Add env and debug mode tests
This commit is contained in:
+2
-3
@@ -940,7 +940,6 @@ function setMemoryLimit(appId, memoryLimit, auditSource, callback) {
|
|||||||
function setEnvironment(appId, env, auditSource, callback) {
|
function setEnvironment(appId, env, auditSource, callback) {
|
||||||
assert.strictEqual(typeof appId, 'string');
|
assert.strictEqual(typeof appId, 'string');
|
||||||
assert.strictEqual(typeof env, 'object');
|
assert.strictEqual(typeof env, 'object');
|
||||||
assert.strictEqual(typeof memoryLimit, 'number');
|
|
||||||
assert.strictEqual(typeof auditSource, 'object');
|
assert.strictEqual(typeof auditSource, 'object');
|
||||||
assert.strictEqual(typeof callback, 'function');
|
assert.strictEqual(typeof callback, 'function');
|
||||||
|
|
||||||
@@ -950,7 +949,7 @@ function setEnvironment(appId, env, auditSource, callback) {
|
|||||||
error = validateEnv(env);
|
error = validateEnv(env);
|
||||||
if (error) return callback(error);
|
if (error) return callback(error);
|
||||||
|
|
||||||
scheduleTask(appId, {}, { installationState: exports.ISTATE_PENDING_CREATE, env: env }, function (error, result) {
|
scheduleTask(appId, {}, { installationState: exports.ISTATE_PENDING_CREATE_CONTAINER, env: env }, function (error, result) {
|
||||||
if (error) return callback(error);
|
if (error) return callback(error);
|
||||||
|
|
||||||
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId: appId, app: app, env: env, taskId: result.taskId });
|
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId: appId, app: app, env: env, taskId: result.taskId });
|
||||||
@@ -972,7 +971,7 @@ function setDebugMode(appId, debugMode, auditSource, callback) {
|
|||||||
error = validateDebugMode(debugMode);
|
error = validateDebugMode(debugMode);
|
||||||
if (error) return callback(error);
|
if (error) return callback(error);
|
||||||
|
|
||||||
scheduleTask(appId, {}, { installationState: exports.ISTATE_PENDING_CREATE, debugMode: debugMode }, function (error, result) {
|
scheduleTask(appId, {}, { installationState: exports.ISTATE_PENDING_CREATE_CONTAINER, debugMode: debugMode }, function (error, result) {
|
||||||
if (error) return callback(error);
|
if (error) return callback(error);
|
||||||
|
|
||||||
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId: appId, app: app, debugMode: debugMode, taskId: result.taskId });
|
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId: appId, app: app, debugMode: debugMode, taskId: result.taskId });
|
||||||
|
|||||||
+1
-1
@@ -287,7 +287,7 @@ function setEnvironment(req, res, next) {
|
|||||||
assert.strictEqual(typeof req.params.id, 'string');
|
assert.strictEqual(typeof req.params.id, 'string');
|
||||||
|
|
||||||
if (!req.body.env || typeof req.body.env !== 'object') return next(new HttpError(400, 'env must be an object'));
|
if (!req.body.env || typeof req.body.env !== 'object') return next(new HttpError(400, 'env must be an object'));
|
||||||
if (Object.keys(req.body.env).some(function (key) { return typeof req.body.env[key] !== 'string'; })) return next(new HttpError(400, 'env must contain values as strings'));
|
if (Object.keys(req.body.env).some((key) => typeof req.body.env[key] !== 'string')) return next(new HttpError(400, 'env must contain values as strings'));
|
||||||
|
|
||||||
apps.setEnvironment(req.params.id, req.body.env, auditSource.fromRequest(req), function (error, result) {
|
apps.setEnvironment(req.params.id, req.body.env, auditSource.fromRequest(req), function (error, result) {
|
||||||
if (error) return next(toHttpError(error));
|
if (error) return next(toHttpError(error));
|
||||||
|
|||||||
@@ -1122,6 +1122,159 @@ describe('App API', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('configure debug mode', function () {
|
||||||
|
it('fails with missing mode', function (done) {
|
||||||
|
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/debug_mode')
|
||||||
|
.query({ access_token: token })
|
||||||
|
.end(function (err, res) {
|
||||||
|
expect(res.statusCode).to.equal(400);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails with bad debug mode', function (done) {
|
||||||
|
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/debug_mode')
|
||||||
|
.query({ access_token: token })
|
||||||
|
.send({ debugMode: 'sleep' })
|
||||||
|
.end(function (err, res) {
|
||||||
|
expect(res.statusCode).to.equal(400);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can set debug mode', function (done) {
|
||||||
|
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/debug_mode')
|
||||||
|
.query({ access_token: token })
|
||||||
|
.send({ debugMode: { readonlyRootfs: false } })
|
||||||
|
.end(function (err, res) {
|
||||||
|
expect(res.statusCode).to.equal(202);
|
||||||
|
taskId = res.body.taskId;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wait for task', function (done) {
|
||||||
|
waitForTask(taskId, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('did change readonly rootfs', function (done) {
|
||||||
|
apps.get(APP_ID, function (error, app) {
|
||||||
|
if (error) return done(error);
|
||||||
|
|
||||||
|
docker.getContainer(app.containerId).inspect(function (error, data) {
|
||||||
|
expect(error).to.not.be.ok();
|
||||||
|
|
||||||
|
expect(data.HostConfig.ReadonlyRootfs).to.be(false);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can reset debug mode', function (done) {
|
||||||
|
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/debug_mode')
|
||||||
|
.query({ access_token: token })
|
||||||
|
.send({ debugMode: null })
|
||||||
|
.end(function (err, res) {
|
||||||
|
expect(res.statusCode).to.equal(202);
|
||||||
|
taskId = res.body.taskId;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wait for task', function (done) {
|
||||||
|
waitForTask(taskId, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('did change readonly rootfs', function (done) {
|
||||||
|
apps.get(APP_ID, function (error, app) {
|
||||||
|
if (error) return done(error);
|
||||||
|
|
||||||
|
docker.getContainer(app.containerId).inspect(function (error, data) {
|
||||||
|
expect(error).to.not.be.ok();
|
||||||
|
|
||||||
|
expect(data.HostConfig.ReadonlyRootfs).to.be(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('configure env', function () {
|
||||||
|
it('fails with missing env', function (done) {
|
||||||
|
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/env')
|
||||||
|
.query({ access_token: token })
|
||||||
|
.end(function (err, res) {
|
||||||
|
expect(res.statusCode).to.equal(400);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails with bad env mode', function (done) {
|
||||||
|
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/env')
|
||||||
|
.query({ access_token: token })
|
||||||
|
.send({ env: 'ok' })
|
||||||
|
.end(function (err, res) {
|
||||||
|
expect(res.statusCode).to.equal(400);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can set env', function (done) {
|
||||||
|
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/env')
|
||||||
|
.query({ access_token: token })
|
||||||
|
.send({ env: { 'OPM': 'SAITAMA' } })
|
||||||
|
.end(function (err, res) {
|
||||||
|
expect(res.statusCode).to.equal(202);
|
||||||
|
taskId = res.body.taskId;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wait for task', function (done) {
|
||||||
|
waitForTask(taskId, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('did set env', function (done) {
|
||||||
|
apps.get(APP_ID, function (error, app) {
|
||||||
|
if (error) return done(error);
|
||||||
|
|
||||||
|
docker.getContainer(app.containerId).inspect(function (error, data) {
|
||||||
|
expect(error).to.not.be.ok();
|
||||||
|
|
||||||
|
expect(data.Config.Env).to.contain('OPM=SAITAMA');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can reset env', function (done) {
|
||||||
|
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure/env')
|
||||||
|
.query({ access_token: token })
|
||||||
|
.send({ env: {} })
|
||||||
|
.end(function (err, res) {
|
||||||
|
expect(res.statusCode).to.equal(202);
|
||||||
|
taskId = res.body.taskId;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wait for task', function (done) {
|
||||||
|
waitForTask(taskId, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('did reset env', function (done) {
|
||||||
|
apps.get(APP_ID, function (error, app) {
|
||||||
|
if (error) return done(error);
|
||||||
|
|
||||||
|
docker.getContainer(app.containerId).inspect(function (error, data) {
|
||||||
|
expect(error).to.not.be.ok();
|
||||||
|
expect(data.Config.Env).to.not.contain('OPM=SAITAMA');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('start/stop', function () {
|
describe('start/stop', function () {
|
||||||
it('non admin cannot stop app', function (done) {
|
it('non admin cannot stop app', function (done) {
|
||||||
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/stop')
|
superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/stop')
|
||||||
|
|||||||
Reference in New Issue
Block a user