it("should report an event loop delay and cpu stats", (done) => { const delay = { current: 100, max: 150 }; const pusageResults = { cpu: 50 }; sandbox.stub(pusage, "stat").yields(null, pusageResults); agent._delayed(delay.max); agent._delayed(delay.current); const checkMetrics = function (metrics) { expect(metrics.eventLoop.delay).to.equal(delay.current); expect(metrics.eventLoop.high).to.equal(delay.max); expect(metrics.cpu.utilization).to.equal(pusageResults.cpu); }; agent._getStats((err, metrics) => { tryCatch(done, () => { expect(err).to.be.null; checkMetrics(metrics); }); }); });
describe('variable.getValue', () => { const variable = new Variable(); it('should return an existing variable value', async () => { const result = await variable.getValue('SECURE_VARIABLE', 'a810b8db-6d04-4697-bed3-c4b72c996279'); expect(result).to.equal('VALUE'); }); it('should return an existing user variable value', async () => { const result = await variable.getValue( 'USER_SECURE_VARIABLE', 'a810b8db-6d04-4697-bed3-c4b72c996279', '0cd30aef-9c4e-4a23-88e3-3547971296e5', ); expect(result).to.equal('USER_VALUE'); }); it('should return null', async () => { const result = await variable.getValue('UNKNOWN', 'a810b8db-6d04-4697-bed3-c4b72c996279'); expect(result).to.be.null; // eslint-disable-line }); it('should return null', async () => { const result = await variable.getValue('SECURE_VARIABLE'); expect(result).to.be.null; // eslint-disable-line }); });
describe('service', () => { const stateManager = new StateManager(); const service = new Service(services, stateManager); it('should start a service', async () => { await service.load(gladys); await service.start('example'); }); it('should return the example service', async () => { expect(service.getService('example')).to.be.instanceOf(Object).and.to.be.not.null; // eslint-disable-line }); it('should return null a service', async () => { expect(service.getService('DONOTEXIST')).to.be.null; // eslint-disable-line }); it('should return service with message capabilities', async () => { const messageServices = await service.getMessageServices(); expect(messageServices).to.be.instanceOf(Array); }); it('should return service by name', async () => { const testService = await service.getByName('test-service'); expect(testService).to.have.property('name', 'test-service'); }); it('should throw service not found', async () => { const promise = service.getByName('not-found'); return assert.isRejected(promise, 'SERVICE_NOT_FOUND'); }); });
describe('#which', () => { const savePath = process.env.PATH; beforeEach(() => { process.env.PATH = os.tmpdir(); const bin = {}; const content = 'Gorillaz on buildings throwing explosive bananas at each other with mathematical precision'; bin[path.join(os.tmpdir(), 'GORILLA.BAS')] = content; filesystem(bin); }); it('should return the same as shelljs.which', () => { const shell = new Shell(); const which1 = shell.which('GORILLA.BAS'); const which2 = _shell.which('GORILLA.BAS'); _.toString(which1).should.equal(_.toString(which2)); }); it('should return null if command is not found', () => { const shell = new Shell(); const wolfenstein = shell.which('WOLFENSTEIN2D.exe'); expect(wolfenstein).to.be.null; }); afterEach(() => { filesystem.restore(); process.env.PATH = savePath; }); });
it('Standard event', async function() { let _event = require('./sample-event-alb1.json') let _context = require('./sample-context-alb1.json') let result = await new Promise(r => api.run(_event,_context,(e,res) => { r(res) })) let body = JSON.parse(result.body) // console.log(JSON.stringify(result,null,2)); expect(result.headers).to.deep.equal({ 'content-type': 'application/json', 'set-cookie': 'test2=value2; Path=/' }) expect(body).to.have.property('request') expect(result.statusDescription).to.equal('200 OK') expect(body.request.id).is.not.null expect(body.request.interface).to.equal('alb') expect(body.request.userAgent).to.equal('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48') expect(body.request).to.have.property('requestContext') expect(body.request.ip).to.equal('192.168.100.1') expect(body.request.isBase64Encoded).to.equal(true) expect(body.request.clientType).to.equal('unknown') expect(body.request.clientCountry).to.equal('unknown') expect(body.request.route).to.equal('/test/hello') expect(body.request.query.qs1).to.equal('foo') expect(body.request.multiValueQuery.qs1).to.deep.equal(['foo']) })
describe('API Gateway Console Test', function() { // See: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-test-method.html it('Standard event w/o multiValueHeaders', async function() { let _event = require('./sample-event-consoletest1.json') let _context = require('./sample-context-apigateway1.json') let result = await new Promise(r => api.run(_event,_context,(e,res) => { r(res) })) let body = JSON.parse(result.body) // console.log(body); // console.log(body.request.multiValueHeaders); expect(body).to.have.property('request') expect(body.request.id).is.not.null expect(body.request.interface).to.equal('apigateway') expect(body.request).to.have.property('requestContext') expect(body.request.ip).to.equal('test-invoke-source-ip') expect(body.request.pathParameters).to.deep.equal({ "proxy": "test/hello" }) expect(body.request.stageVariables).to.deep.equal({}) expect(body.request.isBase64Encoded).to.equal(false) expect(body.request.clientType).to.equal('unknown') expect(body.request.clientCountry).to.equal('unknown') expect(body.request.route).to.equal('/test/hello') expect(body.request.query).to.deep.equal({}) expect(body.request.multiValueQuery).to.deep.equal({}) expect(body.request.headers).to.deep.equal({}) // NOTE: body.request.multiValueHeaders is null in this case }) })
isBase64Encoded: false }) expect(typeof result.multiValueHeaders['last-modified']).to.not.be.null expect(typeof result.multiValueHeaders['last-modified']).to.not.be.empty isBase64Encoded: false }) expect(typeof result.multiValueHeaders['last-modified']).to.not.be.null expect(typeof result.multiValueHeaders['last-modified']).to.not.be.empty
it('using ids == \'1\',\'2\',\'3\' should be ok and return null common block', function (done) { node.get('/peer/blocks/common?ids=\'1\',\'2\',\'3\'') .end(function (err, res) { node.debug('> Response:'.grey, JSON.stringify(res.body)); node.expect(res.body).to.have.property('success').to.be.ok; node.expect(res.body).to.have.property('common').to.be.null; done(); }); });
it('returns url prompt with correct defaults', function () { const config = new Config('config.json'); const prompts = getPrompts(config, {db: 'sqlite3', auto: true}, 'development'); expect(prompts).to.have.length(1); expect(prompts[0].name).to.equal('url'); expect(prompts[0].default).to.be.null; expect(prompts[0].validate).to.equal(validateUrl); expect(prompts[0].filter).to.equal(ensureProtocol); });
it('dbpath', function () { expect(options.dbpath).to.exist; expect(options.dbpath.defaultValue({get: () => 'mysql'})).to.be.null; expect(options.dbpath.defaultValue({get: () => 'sqlite3'}, 'development')).to.equal(path.resolve('./content/data/ghost-dev.db')); expect(options.dbpath.defaultValue({get: () => 'sqlite3'}, 'production')).to.equal(path.resolve('./content/data/ghost.db')); });