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 () {
|
|
|
|
|
before(dockerProxy.start);
|
|
|
|
|
after(dockerProxy.stop);
|
|
|
|
|
|
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-15 18:01:13 +02:00
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
var containerId = stdout.slice(0, -1); // removes the trailing \n
|
|
|
|
|
|
|
|
|
|
exec(`${DOCKER} logs ${containerId}`, function (error, stdout, stderr) {
|
2018-08-16 12:07:15 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
exec(`${DOCKER} rm -f ${containerId}`, function (error, stdout, stderr) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(stderr).to.be.empty();
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-08-16 14:34:55 +02:00
|
|
|
|
|
|
|
|
it('can use PUT to upload archive into a container', function (done) {
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
var containerId = stdout.slice(0, -1); // removes the trailing \n
|
|
|
|
|
|
|
|
|
|
exec(`${DOCKER} cp -a ${__dirname}/proxytestarchive.tar ${containerId}:/tmp/`, function (error, stdout, stderr) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(stderr).to.be.empty();
|
|
|
|
|
expect(stdout).to.be.empty();
|
|
|
|
|
|
|
|
|
|
exec(`${DOCKER} rm -f ${containerId}`, function (error, stdout, stderr) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(stderr).to.be.empty();
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-08-13 22:14:56 +02:00
|
|
|
});
|