describe('#Cli', () => { it('should return a Cli instance with correct default options', () => { const cli = new Cli(); cli.should.be.instanceof(Cli); cli.should.have.property('prefix', 'LANDO'); cli.should.have.property('logLevel', 'warn'); cli.should.have.property('userConfRoot').and.not.be.empty; }); it('should return a Cli instance with custom options', () => { const prefix = '16309'; const logLevel = 'allthelogz'; const userConfRoot = '/tmp'; const cli = new Cli(prefix, logLevel, userConfRoot); cli.should.be.instanceof(Cli); cli.should.have.property('prefix', prefix); cli.should.have.property('logLevel', logLevel); cli.should.have.property('userConfRoot', userConfRoot); }); });
describe('#loadFiles', () => { it('should return an empty object if no files are specified', () => { const fileConfig = config.loadFiles(); expect(fileConfig).to.be.empty; }); it('should return data only from files that exist', () => { filesystem({'/tmp/config1.yml': 'obiwan: kenobi'}); const fileConfig = config.loadFiles(['/tmp/config1.yml', '/tmp/doesnotexist.yml']); expect(hasher(fileConfig)).to.equal(hasher({obiwan: 'kenobi'})); filesystem.restore(); }); it('should give priority to the last file loaded', () => { filesystem({ '/tmp/config1.yml': 'scoundrel: lando', '/tmp/config2.yml': 'scoundrel: solo', }); const fileConfig = config.loadFiles(['/tmp/config1.yml', '/tmp/config2.yml']); expect(hasher(fileConfig)).to.equal(hasher({scoundrel: 'solo'})); filesystem.restore(); }); });
describe("generate-layouts", () => { it("should validate default layout", () => { expect(generateLayouts("lib/default-layout-config.js")).to.be.an("array"); }); it("should fail on bad layouts", () => { expect(() => { generateLayouts("fake/layout-not-found"); }).to.throw(/Cannot find module/); expect(() => { mock("fake/invalid-config-layout", { invalid: "config" }); generateLayouts("fake/invalid-config-layout"); }).to.throw(/instance is not of a type\(s\) array/); }); it("should generate empty layout", () => { mock("fake/empty-layout", []); expect(generateLayouts("fake/empty-layout")).to.be.empty; }); it("should include a getPosition method", () => { const layout = generateLayouts("lib/default-layout-config.js"); const fake = { fake: "result" }; expect(layout[0]).to.respondTo("getPosition"); expect(layout[0].getPosition(fake)).to.eql(fake); }); });
describe('#Metrics', () => { it('should return a Metrics instance with correct default options', () => { const metrics = new Metrics(); metrics.should.be.instanceof(Metrics); metrics.should.have.property('id', 'unknown'); metrics.endpoints.should.be.instanceof(Array); metrics.endpoints.should.be.empty; metrics.data.should.be.instanceof(Object); metrics.data.should.be.empty; metrics.log.should.be.instanceof(EventEmitter); }); it('should return a Metrics instance with user options', () => { const metrics = new Metrics({id: '24601', endpoints: [1, 2], data: {prisoner: 'valjean'}}); metrics.should.be.instanceof(Metrics); metrics.should.have.property('id', '24601'); metrics.data.prisoner.should.equal('valjean'); metrics.endpoints.should.have.length(2); metrics.endpoints.should.be.not.empty; metrics.data.should.be.not.empty; metrics.log.should.be.instanceof(EventEmitter); }); });
const username = user.getUsername(); expect(username).to.be.a('string'); expect(username).to.not.be.empty; }); });
events.should.be.an('object').with.property('log'); events.should.have.property('_maxListeners', 64); events._listeners.should.be.an('array').and.be.empty; events.should.have.property('_eventsCount', 0); }); events.on('battle-of-tanaab', data => { data.maneuver.should.equal('little'); data.should.not.be.empty; }); events.emit('battle-of-tanaab', data);
it('does not append sbin to path if platform is not linux', function () { const execaStub = sinon.stub(execa, 'shell').resolves(); const ctx = {system: {platform: {linux: false}}}; return mysqlCheck.task(ctx).then(() => { expect(execaStub.calledOnce).to.be.true; expect(execaStub.args[0][1]).to.be.empty; }); });
it('should start and finish a local span', () => { recorder.record(record(rootId, 1, new Annotation.LocalOperationStart('foo'))); recorder.record(record(rootId, 3, new Annotation.LocalOperationStop())); expect(popSpan()).to.deep.equal({ traceId: rootId.traceId, id: rootId.spanId, name: 'foo', timestamp: 1, duration: 2 }); expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions });
it('should not log span that is not in partial spans list', () => { const span = { delegate: { timestamp: 1, setLocalEndpoint: () => {} } }; recorder._writeSpan(rootId, span); expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions });
expect(() => { expect(null, "blah").to.be.empty; }).to.throw( AssertionError, "blah: .empty was passed non-string primitive null" );
it('should start and finish a client span', () => { recorder.record(record(rootId, 1, new Annotation.ClientSend())); recorder.record(record(rootId, 3, new Annotation.ClientRecv())); expect(popSpan()).to.deep.equal({ traceId: rootId.traceId, id: rootId.spanId, kind: 'CLIENT', timestamp: 1, duration: 2 }); expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions });
it('should start and finish a consumer span', () => { recorder.record(record(rootId, 1, new Annotation.ConsumerStart())); recorder.record(record(rootId, 3, new Annotation.ConsumerStop())); expect(popSpan()).to.deep.equal({ traceId: rootId.traceId, id: rootId.spanId, kind: 'CONSUMER', timestamp: 1, duration: 2 }); expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions });
it('should not log span that is not in partial spans list', () => { const span = { delegate: { timestamp: 1, setLocalEndpoint: () => {} } }; recorder._writeSpan(rootId, span); expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions });