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';
|
|
|
|
|
|
|
|
|
|
var dockerProxy = require('../dockerproxy.js'),
|
|
|
|
|
config = require('../config.js'),
|
|
|
|
|
exec = require('child_process').exec,
|
|
|
|
|
expect = require('expect.js');
|
|
|
|
|
|
|
|
|
|
const DOCKER = `docker -H tcp://localhost:${config.get('dockerProxyPort')} `;
|
|
|
|
|
|
|
|
|
|
describe('Cloudron', 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();
|
|
|
|
|
|
|
|
|
|
exec(`${DOCKER} run -d ubuntu "bin/bash" "-c" "while true; do echo 'perpetual walrus'; sleep 1; done"`, function (error, stdout, stderr) {
|
|
|
|
|
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
|
|
|
|
|
// this.timeout(1000000);
|
|
|
|
|
// 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:');
|
|
|
|
|
expect(stderr).to.be.empty();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can create container', function (done) {
|
|
|
|
|
var cmd = DOCKER + ` run ubuntu "/bin/bash" "-c" "echo 'hello'"`;
|
|
|
|
|
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-08-15 18:01:13 +02:00
|
|
|
var cmd = `${DOCKER} run --network ifnotrewritethiswouldfail ubuntu "/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-08-17 13:44:12 +02:00
|
|
|
exec(`${DOCKER} cp -a ${__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
|
|
|
});
|