Files
cloudron-box/src/test/dockerproxy-test.js
Girish Ramakrishnan 7cfc455cd3 make tests pass again
also disable column statistics on ubuntu 20
2020-07-10 09:33:35 -07:00

106 lines
3.6 KiB
JavaScript

/* jslint node:true */
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
var constants = require('../constants.js'),
dockerProxy = require('../dockerproxy.js'),
exec = require('child_process').exec,
expect = require('expect.js');
const DOCKER = `docker -H tcp://172.18.0.1:${constants.DOCKER_PROXY_PORT} `;
describe('Dockerproxy', function () {
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 cloudron/base:2.0.0 "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);
});
});
// uncomment this to run the proxy for manual testing
// it('wait', function (done) {} );
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(); // on some machines, i get 'No swap limit support'
done();
});
});
it('can create container', function (done) {
var cmd = `${DOCKER} run cloudron/base:2.0.0 "/bin/bash" "-c" "echo 'hello'"`;
exec(cmd, function (error, stdout, stderr) {
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) {
var cmd = `${DOCKER} run --network ifnotrewritethiswouldfail cloudron/base:2.0.0 "/bin/bash" "-c" "echo 'hello'"`;
exec(cmd, function (error, stdout, stderr) {
expect(error).to.be(null);
expect(stdout).to.contain('hello');
expect(stderr).to.be.empty();
done();
});
});
it('cannot see logs through docker logs, since syslog is configured', function (done) {
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();
done();
});
});
it('can use PUT to upload archive into a container', function (done) {
exec(`${DOCKER} cp ${__dirname}/proxytestarchive.tar ${containerId}:/tmp/`, function (error, stdout, stderr) {
expect(error).to.be(null);
expect(stderr).to.be.empty();
expect(stdout).to.be.empty();
done();
});
});
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();
expect(stdout).to.equal('bin\nboot\ndev\netc\nhome\nlib\nlib64\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsrv\nsys\ntmp\nusr\nvar\n');
done();
});
});
});