2018-08-13 22:14:56 +02:00
|
|
|
/* jslint node:true */
|
|
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2019-07-25 15:33:34 -07:00
|
|
|
var constants = require('../constants.js'),
|
|
|
|
|
dockerProxy = require('../dockerproxy.js'),
|
2018-08-13 22:14:56 +02:00
|
|
|
exec = require('child_process').exec,
|
|
|
|
|
expect = require('expect.js');
|
|
|
|
|
|
2019-07-25 15:33:34 -07:00
|
|
|
const DOCKER = `docker -H tcp://localhost:${constants.DOCKER_PROXY_PORT} `;
|
2018-08-13 22:14:56 +02:00
|
|
|
|
2018-08-17 13:38:43 -07:00
|
|
|
describe('Dockerproxy', function () {
|
2018-08-17 13:44:12 +02:00
|
|
|
var containerId;
|
|
|
|
|
|
|
|
|
|
// create a container to test against
|
|
|
|
|
before(function (done) {
|
|
|
|
|
dockerProxy.start(function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
2018-10-30 13:36:00 -07:00
|
|
|
exec(`${DOCKER} run -d cloudron/base:1.0.0 "bin/bash" "-c" "while true; do echo 'perpetual walrus'; sleep 1; done"`, function (error, stdout, stderr) {
|
2018-08-17 13:44:12 +02:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(stderr).to.be.empty();
|
|
|
|
|
|
|
|
|
|
containerId = stdout.slice(0, -1); // removes the trailing \n
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after(function (done) {
|
|
|
|
|
exec(`${DOCKER} rm -f ${containerId}`, function (error, stdout, stderr) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(stderr).to.be.empty();
|
|
|
|
|
|
|
|
|
|
dockerProxy.stop(done);
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-08-13 22:14:56 +02:00
|
|
|
|
2018-08-16 14:34:55 +02:00
|
|
|
// uncomment this to run the proxy for manual testing
|
|
|
|
|
// it('wait', function (done) {} );
|
|
|
|
|
|
2018-08-13 22:14:56 +02:00
|
|
|
it('can get info', function (done) {
|
|
|
|
|
exec(DOCKER + ' info', function (error, stdout, stderr) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(stdout).to.contain('Containers:');
|
2018-08-20 20:10:14 -07:00
|
|
|
// expect(stderr).to.be.empty(); // on some machines, i get 'No swap limit support'
|
2018-08-13 22:14:56 +02:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can create container', function (done) {
|
2018-10-30 13:36:00 -07:00
|
|
|
var cmd = `${DOCKER} run cloudron/base:1.0.0 "/bin/bash" "-c" "echo 'hello'"`;
|
2018-08-13 22:14:56 +02:00
|
|
|
exec(cmd, function (error, stdout, stderr) {
|
2018-08-14 22:52:00 +02:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(stdout).to.contain('hello');
|
|
|
|
|
expect(stderr).to.be.empty();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('proxy overwrites the container network option', function (done) {
|
2018-10-30 13:36:00 -07:00
|
|
|
var cmd = `${DOCKER} run --network ifnotrewritethiswouldfail cloudron/base:1.0.0 "/bin/bash" "-c" "echo 'hello'"`;
|
2018-08-14 22:52:00 +02:00
|
|
|
exec(cmd, function (error, stdout, stderr) {
|
2018-08-13 22:14:56 +02:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(stdout).to.contain('hello');
|
|
|
|
|
expect(stderr).to.be.empty();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-08-15 18:01:13 +02:00
|
|
|
|
2018-08-16 12:07:15 +02:00
|
|
|
it('cannot see logs through docker logs, since syslog is configured', function (done) {
|
2018-08-17 13:44:12 +02:00
|
|
|
exec(`${DOCKER} logs ${containerId}`, function (error, stdout, stderr) {
|
|
|
|
|
expect(error.message).to.contain('configured logging driver does not support reading');
|
|
|
|
|
expect(stderr).to.contain('configured logging driver does not support reading');
|
|
|
|
|
expect(stdout).to.be.empty();
|
2018-08-15 18:01:13 +02:00
|
|
|
|
2018-08-17 13:44:12 +02:00
|
|
|
done();
|
2018-08-15 18:01:13 +02:00
|
|
|
});
|
|
|
|
|
});
|
2018-08-16 14:34:55 +02:00
|
|
|
|
|
|
|
|
it('can use PUT to upload archive into a container', function (done) {
|
2018-10-30 13:36:00 -07:00
|
|
|
exec(`${DOCKER} cp ${__dirname}/proxytestarchive.tar ${containerId}:/tmp/`, function (error, stdout, stderr) {
|
2018-08-16 14:34:55 +02:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(stderr).to.be.empty();
|
2018-08-17 13:44:12 +02:00
|
|
|
expect(stdout).to.be.empty();
|
2018-08-16 14:34:55 +02:00
|
|
|
|
2018-08-17 13:44:12 +02:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-08-16 14:34:55 +02:00
|
|
|
|
2018-08-17 13:44:12 +02:00
|
|
|
it('can exec into a container', function (done) {
|
|
|
|
|
exec(`${DOCKER} exec ${containerId} ls`, function (error, stdout, stderr) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(stderr).to.be.empty();
|
2018-08-17 15:30:23 +02:00
|
|
|
expect(stdout).to.equal('bin\nboot\ndev\netc\nhome\nlib\nlib64\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsrv\nsys\ntmp\nusr\nvar\n');
|
2018-08-16 14:34:55 +02:00
|
|
|
|
2018-08-17 13:44:12 +02:00
|
|
|
done();
|
2018-08-16 14:34:55 +02:00
|
|
|
});
|
|
|
|
|
});
|
2018-08-13 22:14:56 +02:00
|
|
|
});
|