2018-08-13 22:14:56 +02:00
|
|
|
/* jslint node:true */
|
|
|
|
|
/* global it:false */
|
2021-09-07 09:57:49 -07:00
|
|
|
/* global xit:false */
|
2018-08-13 22:14:56 +02:00
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2023-12-04 00:11:11 +01:00
|
|
|
|
2021-09-07 09:57:49 -07:00
|
|
|
const child_process = require('child_process'),
|
2023-12-04 00:11:11 +01:00
|
|
|
common = require('./common.js'),
|
2021-09-07 09:57:49 -07:00
|
|
|
constants = require('../constants.js'),
|
2019-07-25 15:33:34 -07:00
|
|
|
dockerProxy = require('../dockerproxy.js'),
|
2023-12-04 00:11:11 +01:00
|
|
|
expect = require('expect.js'),
|
|
|
|
|
infra = require('../infra_version.js');
|
2018-08-13 22:14:56 +02:00
|
|
|
|
2020-03-29 18:55:44 -07:00
|
|
|
const DOCKER = `docker -H tcp://172.18.0.1:${constants.DOCKER_PROXY_PORT} `;
|
2018-08-13 22:14:56 +02:00
|
|
|
|
2021-09-07 09:57:49 -07:00
|
|
|
async function exec(cmd) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
child_process.exec(cmd, { encoding: 'utf8' }, function (error, stdout) {
|
|
|
|
|
if (error) return reject(error);
|
|
|
|
|
|
|
|
|
|
resolve(stdout);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-17 13:38:43 -07:00
|
|
|
describe('Dockerproxy', function () {
|
2022-04-14 20:30:00 -05:00
|
|
|
let containerId;
|
2023-12-04 00:11:11 +01:00
|
|
|
const { setup, cleanup } = common;
|
2018-08-17 13:44:12 +02:00
|
|
|
|
|
|
|
|
// create a container to test against
|
2021-09-07 09:57:49 -07:00
|
|
|
before(async function () {
|
2023-12-04 00:11:11 +01:00
|
|
|
await setup();
|
2021-09-07 09:57:49 -07:00
|
|
|
await dockerProxy.start();
|
2018-08-17 13:44:12 +02:00
|
|
|
|
2023-12-04 00:11:11 +01:00
|
|
|
const stdout = await exec(`${DOCKER} run -d ${infra.images.base} "bin/bash" "-c" "while true; do echo 'perpetual walrus'; sleep 1; done"`);
|
2021-09-07 09:57:49 -07:00
|
|
|
containerId = stdout.slice(0, -1); // removes the trailing \n
|
2018-08-17 13:44:12 +02:00
|
|
|
});
|
|
|
|
|
|
2021-09-07 09:57:49 -07:00
|
|
|
after(async function () {
|
|
|
|
|
await exec(`${DOCKER} rm -f ${containerId}`);
|
|
|
|
|
await dockerProxy.stop();
|
2023-12-04 00:11:11 +01:00
|
|
|
await cleanup();
|
2018-08-17 13:44:12 +02:00
|
|
|
});
|
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) {} );
|
|
|
|
|
|
2021-09-07 09:57:49 -07:00
|
|
|
it('can get info', async function () {
|
|
|
|
|
const stdout = await exec(DOCKER + ' info');
|
|
|
|
|
expect(stdout).to.contain('Containers:');
|
|
|
|
|
// expect(stderr).to.be.empty(); // on some machines, i get 'No swap limit support'
|
2018-08-13 22:14:56 +02:00
|
|
|
});
|
|
|
|
|
|
2021-09-07 09:57:49 -07:00
|
|
|
it('can create container', async function () {
|
2023-12-04 00:11:11 +01:00
|
|
|
const cmd = `${DOCKER} run ${infra.images.base} "/bin/bash" "-c" "echo 'hello'"`;
|
2021-09-07 09:57:49 -07:00
|
|
|
const stdout = await exec(cmd);
|
|
|
|
|
expect(stdout).to.contain('hello');
|
2018-08-14 22:52:00 +02:00
|
|
|
});
|
|
|
|
|
|
2021-09-07 09:57:49 -07:00
|
|
|
it('proxy overwrites the container network option', async function () {
|
2023-12-04 00:11:11 +01:00
|
|
|
const cmd = `${DOCKER} run --network ifnotrewritethiswouldfail ${infra.images.base} "/bin/bash" "-c" "echo 'hello'"`;
|
2021-09-07 09:57:49 -07:00
|
|
|
const stdout = await exec(cmd);
|
|
|
|
|
expect(stdout).to.contain('hello');
|
2018-08-13 22:14:56 +02:00
|
|
|
});
|
2018-08-15 18:01:13 +02:00
|
|
|
|
2021-06-29 09:44:16 -07:00
|
|
|
xit('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
|
|
|
|
2021-09-07 09:57:49 -07:00
|
|
|
it('can use PUT to upload archive into a container', async function () {
|
|
|
|
|
const stdout = await exec(`${DOCKER} cp ${__dirname}/proxytestarchive.tar ${containerId}:/tmp/`);
|
|
|
|
|
expect(stdout).to.be.empty();
|
2018-08-17 13:44:12 +02:00
|
|
|
});
|
2018-08-16 14:34:55 +02:00
|
|
|
|
2021-09-07 09:57:49 -07:00
|
|
|
it('can exec into a container', async function () {
|
|
|
|
|
const stdout = await exec(`${DOCKER} exec ${containerId} ls`);
|
|
|
|
|
expect(stdout).to.equal('bin\nboot\ndev\netc\nhome\nlib\nlib32\nlib64\nlibx32\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsrv\nsys\ntmp\nusr\nvar\n');
|
2018-08-16 14:34:55 +02:00
|
|
|
});
|
2018-08-13 22:14:56 +02:00
|
|
|
});
|