describe("constructor", () => { it("should create a popup screen", () => { const gotoTimeView = new GotoTimeView(options); expect(gotoTimeView).to.be.an.instanceof(GotoTimeView); expect(gotoTimeView).to.have.property("metricsProvider").which.is.an.instanceOf(MetricsProvider); expect(gotoTimeView).to.have.property("screen").which.is.an("object"); expect(gotoTimeView).to.have.property("parent").which.is.an.instanceOf(blessed.box); expect(gotoTimeView).to.have.property("node").which.is.an.instanceOf(blessed.node); expect(gotoTimeView).to.have.property("form").which.is.an.instanceOf(blessed.form); expect(gotoTimeView).to.have.property("timeRangeLabel").which.is.an.instanceOf(blessed.text); expect(gotoTimeView).to.have.property("textBox").which.is.an.instanceOf(blessed.textbox); expect(gotoTimeView).to.have.property("errorText").which.is.an.instanceOf(blessed.text); expect(gotoTimeView).to.have.property("acceptButton").which.is.an.instanceOf(blessed.button); expect(gotoTimeView).to.have.property("cancelButton").which.is.an.instanceOf(blessed.button); }); });
it("should create fullscreen view", () => { const layouts = createPanel([{ views: [ { type: "memory" } ] }]); expect(layouts.views[0]).to.have.property("getPosition").that.is.a("function"); expect(layouts.views[0].getPosition(parent)).to.be.deep.equal({ left: 0, top: 0, width: parent.width, height: parent.height }); });
describe('mqttHandler.init', () => { it('should init', async () => { const gladys = { variable: { getValue: fake.resolves('value'), }, system: { isDocker: fake.resolves(false), }, }; const mqttHandler = new MqttHandler(gladys, MockedMqttClient, 'faea9c35-759a-44d5-bcc9-2af1de37b8b4'); await mqttHandler.init(); assert.callCount(gladys.variable.getValue, 3); expect(Object.keys(mqttHandler.topicBinds)).is.deep.eq(DEFAULT.TOPICS); }); });
describe("constructor", () => { it("should create a box with two gauges and listen for metrics event", () => { const append = sandbox.spy(blessed.node.prototype, "append"); const memory = new MemoryGaugeView(options); expect(memory).to.have.property("node").that.is.an.instanceof(blessed.box); expect(memory.node).to.have.nested.property("options.label", " memory "); expect(append.thirdCall).to.have.been.calledOn(testContainer) .and.calledWithExactly(memory.node); expect(testContainer.screen.on).to.have.been.calledWithExactly("metrics", sinon.match.func); expect(memory).to.have.property("heapGauge").that.is.an.instanceof(contrib.gauge); expect(memory.heapGauge).to.have.nested.property("options.label", "heap"); expect(append.firstCall).to.have.been.calledOn(memory.node) .and.calledWithExactly(memory.heapGauge); expect(memory).to.have.property("rssGauge").that.is.an.instanceof(contrib.gauge); expect(memory.rssGauge).to.have.nested.property("options.label", "resident"); expect(append.secondCall).to.have.been.calledOn(memory.node) .and.calledWithExactly(memory.rssGauge); }); });
describe("_createGraph", () => { it("should create a blessed-contrib line graph", () => { sandbox.spy(testContainer, "append"); options.layoutConfig.view.limit = 8; sandbox.stub(BaseLineGraph.prototype, "_createGraph"); const baseGraph = new BaseLineGraph(options); BaseLineGraph.prototype._createGraph.restore(); expect(baseGraph).to.not.have.property("node"); baseGraph._createGraph(options); expect(baseGraph).to.have.property("node").that.is.an.instanceof(contrib.line); expect(baseGraph.node).to.have.nested.property("options.label", " graph A "); expect(baseGraph.node).to.have.nested.property("options.maxY", undefined); expect(baseGraph.node).to.have.property("position") .that.deep.equals(options.layoutConfig.getPosition(options.parent)); expect(testContainer.append).to.have.been.calledOnce.and.calledWithExactly(baseGraph.node); }); });
describe("constructor", () => { it("should require logProvider", () => { options.logProvider = undefined; expect(() => { new StreamView(options); // eslint-disable-line no-new }).to.throw("StreamView requires logProvider"); }); it("should create a log node and listen for given events", () => { const streamView = new StreamView(options); expect(streamView).to.have.property("node").that.is.an.instanceof(blessed.log); expect(streamView.node).to.have.nested.property("options.label", " stdout / stderr "); expect(testContainer.screen.on).to.have.been .calledWithExactly("stdout", sinon.match.func) .and.calledWithExactly("stderr", sinon.match.func); }); });
describe("onEvent", () => { it("should call update for each gauge", () => { const memory = new MemoryGaugeView(options); expect(memory).to.have.property("heapGauge").that.is.an.instanceof(contrib.gauge); expect(memory).to.have.property("rssGauge").that.is.an.instanceof(contrib.gauge); sandbox.stub(memory, "update"); const mem = { heapUsed: 23, heapTotal: 39, rss: 290, systemTotal: 80010 }; memory.onEvent({ mem }); expect(memory.update).to.have.been.calledTwice .and.to.have.been.calledWithExactly(memory.heapGauge, mem.heapUsed, mem.heapTotal) .and.to.have.been.calledWithExactly(memory.rssGauge, mem.rss, mem.systemTotal); }); });
describe("HelpView", () => { let sandbox; let testContainer; before(() => { sandbox = sinon.createSandbox(); }); beforeEach(() => { utils.stubWidgets(sandbox); testContainer = utils.getTestContainer(sandbox); }); afterEach(() => { sandbox.restore(); }); it("should create a box with text describing keybindings", () => { const help = new HelpView({ parent: testContainer }); expect(help).to.have.property("node").that.is.an.instanceof(blessed.box); expect(help.node).to.have.nested.property("options.content").that.contains("keybindings"); expect(help.node).to.have.property("hidden", true); }); });
.to.be.an("object") .with.property("_metrics") .which.is.an("array") .that.has.lengthOf(mockMetrics.length);
describe("resetGraphs", () => { it("resets zoom level and scroll offsets", () => { sandbox.stub(metricsProvider, "setZoomLevel").callsFake((zoom) => { expect(zoom) .to.be.a("number") .that.equals(0); }); _.each(AGGREGATE_TIME_LEVELS, (level) => { expect(metricsProvider) .to.be.an("object") .with.property("_aggregation") .which.is.an("object") .with.property(level) .which.is.an("object") .with.property("scrollOffset") .which.is.a("number") .that.equals(0); }); metricsProvider.resetGraphs(); }); });
.with.property("metricA") .with.property("valueA") .which.is.a("number") .that.equals(Number(averageA.valueA.toFixed(1))); .with.property("metricB") .with.property("valueA") .which.is.a("number") .that.equals(Number(averageB.valueA.toFixed(1))); .with.property("metricB") .with.property("valueB") .which.is.a("number") .that.equals(Number(averageB.valueB.toFixed(1))); });
it('creates a dynamically generated client synchronously based on version', () => { const backend = new Request({ kubeconfig }) const client = new Client({ backend, version: '1.13' }) expect(client.api.get).is.a('function') })
it('aliases resources', () => { const spec = { paths: { '/foo/deployments': { get: { operationId: 'fooDeploymentsGet' } } } } const client = new Client({ spec, backend: {} }) expect(client.foo.deployments).is.an('object') expect(client.foo.deployment).is.an('object') expect(client.foo.deploy).is.an('object') })
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']) })
it('supports deprecated "version" field for Namespaced CustomResourceDefinitions', () => { const client = new Client({ spec: { paths: {} }, backend: {} }) const crd = { spec: { scope: 'Namespaced', group: 'stable.example.com', version: 'v1', names: { plural: 'foos' } } } client.addCustomResourceDefinition(crd) expect(client.apis['stable.example.com'].v1.foos.get).is.a('function') expect(client.apis['stable.example.com'].v1.namespaces('default').foos.get).is.a('function') expect(client.apis['stable.example.com'].v1.namespaces('default').foos.post).is.a('function') expect(client.apis['stable.example.com'].v1.namespaces('default').foos('blah').get).is.a('function') expect(client.apis['stable.example.com'].v1.namespaces('default').foos('blah').delete).is.a('function') expect(client.apis['stable.example.com'].v1.namespaces('default').foos('blah').get).is.a('function') expect(client.apis['stable.example.com'].v1.namespaces('default').foos('blah').patch).is.a('function') expect(client.apis['stable.example.com'].v1.namespaces('default').foos('blah').put).is.a('function') expect(client.apis['stable.example.com'].v1.watch.foos.getStream).is.a('function') expect(client.apis['stable.example.com'].v1.watch.namespaces('default').foos.getStream).is.a('function') expect(client.apis['stable.example.com'].v1.watch.namespaces('default').foos('blah').getStream).is.a('function') })