fix dockerproxy test

This commit is contained in:
Girish Ramakrishnan
2023-12-04 00:11:11 +01:00
parent 470417fcbe
commit d45c433bc7
2 changed files with 14 additions and 7 deletions
+4 -3
View File
@@ -73,7 +73,9 @@ async function containersCreate(req, res, next) {
debug('containersCreate: original bind mounts:', req.body.HostConfig.Binds);
const result = await volumes.list();
const [error, result] = await safe(volumes.list());
if (error) return next(new HttpError(500, `Error listing volumes: ${error.message}`));
const volumesByName = {};
result.forEach(r => volumesByName[r.name] = r);
@@ -146,8 +148,6 @@ async function start() {
// Overwrite the default 2min request timeout. This is required for large builds for example
gHttpServer.setTimeout(60 * 60 * 1000);
debug(`startDockerProxy: started proxy on port ${constants.DOCKER_PROXY_PORT}`);
// eslint-disable-next-line no-unused-vars
gHttpServer.on('upgrade', function (req, client, head) {
// Create a new tcp connection to the TCP server
@@ -176,6 +176,7 @@ async function start() {
});
});
debug(`start: listening on 172.18.0.1:${constants.DOCKER_PROXY_PORT}`);
await util.promisify(gHttpServer.listen.bind(gHttpServer))(constants.DOCKER_PROXY_PORT, '172.18.0.1');
}
+10 -4
View File
@@ -7,10 +7,13 @@
'use strict';
const child_process = require('child_process'),
common = require('./common.js'),
constants = require('../constants.js'),
dockerProxy = require('../dockerproxy.js'),
expect = require('expect.js');
expect = require('expect.js'),
infra = require('../infra_version.js');
const DOCKER = `docker -H tcp://172.18.0.1:${constants.DOCKER_PROXY_PORT} `;
@@ -26,18 +29,21 @@ async function exec(cmd) {
describe('Dockerproxy', function () {
let containerId;
const { setup, cleanup } = common;
// create a container to test against
before(async function () {
await setup();
await dockerProxy.start();
const stdout = await exec(`${DOCKER} run -d cloudron/base:3.0.0 "bin/bash" "-c" "while true; do echo 'perpetual walrus'; sleep 1; done"`);
const stdout = await exec(`${DOCKER} run -d ${infra.images.base} "bin/bash" "-c" "while true; do echo 'perpetual walrus'; sleep 1; done"`);
containerId = stdout.slice(0, -1); // removes the trailing \n
});
after(async function () {
await exec(`${DOCKER} rm -f ${containerId}`);
await dockerProxy.stop();
await cleanup();
});
// uncomment this to run the proxy for manual testing
@@ -50,13 +56,13 @@ describe('Dockerproxy', function () {
});
it('can create container', async function () {
const cmd = `${DOCKER} run cloudron/base:3.0.0 "/bin/bash" "-c" "echo 'hello'"`;
const cmd = `${DOCKER} run ${infra.images.base} "/bin/bash" "-c" "echo 'hello'"`;
const stdout = await exec(cmd);
expect(stdout).to.contain('hello');
});
it('proxy overwrites the container network option', async function () {
const cmd = `${DOCKER} run --network ifnotrewritethiswouldfail cloudron/base:3.0.0 "/bin/bash" "-c" "echo 'hello'"`;
const cmd = `${DOCKER} run --network ifnotrewritethiswouldfail ${infra.images.base} "/bin/bash" "-c" "echo 'hello'"`;
const stdout = await exec(cmd);
expect(stdout).to.contain('hello');
});