diff --git a/index.js b/index.js index 53409ea..711dc29 100644 --- a/index.js +++ b/index.js @@ -44,8 +44,8 @@ var run = function(image, opts) { if (opts.entrypoint) copts.Entrypoint = [].concat(opts.entrypoint) if (opts.ports) { - Object.keys(opts.ports).forEach(function(host) { - var container = opts.ports[host] + Object.keys(opts.ports).forEach(function(container) { + var host = opts.ports[container] if (!/\//.test(container)) container += '/tcp' copts.ExposedPorts[container] = {} sopts.PortBindings[container] = [{HostPort:host+''}] @@ -59,9 +59,9 @@ var run = function(image, opts) { } if (opts.volumes) { - Object.keys(opts.volumes).forEach(function(host) { - var container = opts.volumes[host] - copts.Volumes[host] = {} + Object.keys(opts.volumes).forEach(function(container) { + var host = opts.volumes[container] + copts.Volumes[container] = {} if(!endsWith(container, ':rw') || !endsWith(container, ':ro')) container += ':rw' diff --git a/test.js b/test.js index cb80724..fa69794 100644 --- a/test.js +++ b/test.js @@ -2,6 +2,9 @@ var tape = require('tape') var concat = require('concat-stream') var run = require('./') +var fs = require('fs') +var path = require('path') + tape('spawn bash', function(t) { var child = run('mafintosh/dev') @@ -12,6 +15,35 @@ tape('spawn bash', function(t) { })) }) +tape('env', function(t) { + var child = run('mafintosh/dev', { + env:{ + 'ENV_TEST_VAR':'hello world' + } + }) + + child.stdin.end('echo $ENV_TEST_VAR') + child.stdout.pipe(concat(function(data) { + t.same(data.toString(), 'hello world\n', 'echoes $ENV_TEST_VAR') + t.end() + })) +}) + +tape('volume', function(t) { + var child = run('mafintosh/dev', { + volumes:{ + '/test':__dirname + } + }) + + var licenceContent = fs.readFileSync(path.join(__dirname, 'LICENSE'), 'utf8') + child.stdin.end('cat /test/LICENSE') + child.stdout.pipe(concat(function(data) { + t.same(data.toString(), licenceContent, 'echoes license file through volume') + t.end() + })) +}) + tape('destroy', function(t) { var child = run('mafintosh/dev') @@ -20,4 +52,4 @@ tape('destroy', function(t) { t.ok(code !== 0, 'not ok exit') t.end() }) -}) \ No newline at end of file +})