it("should tell whether the specified string matches the agent's information", () => { const agent = Agents.Agent.fromJSON(agentData[0]); expect(agent.matches('host-1')).toBe(true); expect(agent.matches("Linux")).toBe(true); expect(agent.matches("10.12.2.201")).toBe(true); expect(agent.matches("linux")).toBe(true); expect(agent.matches("perf")).toBe(true); expect(agent.matches("invalid-search")).toBe(false); });
it("should serialize to JSON", () => { const agent = Agents.Agent.fromJSON(agentData[0]); expect(JSON.parse(JSON.stringify(agent, s.snakeCaser))).toEqual({ hostname: 'host-1', resources: ['linux', 'java'], environments: ['staging', 'perf'], agent_config_state: 'Enabled' // eslint-disable-line camelcase }); });
it("should deserialize from json", () => { const agent = Agents.Agent.fromJSON(agentData[0]); expect(agent.uuid()).toBe('uuid-1'); expect(agent.hostname()).toBe('host-1'); expect(agent.ipAddress()).toBe('10.12.2.201'); expect(agent.sandbox()).toBe('/var/lib/go-agent-2'); expect(agent.operatingSystem()).toBe('Linux'); expect(agent.freeSpace()).toBe(111902543872); expect(agent.agentConfigState()).toBe('Enabled'); expect(agent.agentState()).toBe('Building'); expect(agent.buildState()).toBe('Unknown'); expect(agent.resources()).toEqual(['linux', 'java']); expect(agent.environments().length).toBe(2); expect(agent.environments()[0].name()).toEqual('staging'); expect(agent.environments()[1].name()).toEqual('perf'); expect(agent.environments()[0].associatedFromConfigRepo()).toBe(true); expect(agent.environments()[1].associatedFromConfigRepo()).toBe(false); expect(agent.buildDetails().pipelineUrl()).toEqual("http://localhost:8153/go/tab/pipeline/history/up42"); expect(agent.buildDetails().stageUrl()).toEqual("http://localhost:8153/go/pipelines/up42/2/up42_stage/1"); expect(agent.buildDetails().jobUrl()).toEqual("http://localhost:8153/go/tab/build/detail/up42/2/up42_stage/1/up42_job"); });
it("should be 'Building (Cancelled)' when agentState is 'Building' and buildState is 'Cancelled'", () => { const agent = new Agents.Agent({agentState: 'Building', buildState: 'Cancelled'}); expect(agent.status()).toBe('Building (Cancelled)'); });
it("should be 'Disabled' when agentConfigState is 'Disabled'", () => { const agent = new Agents.Agent({agentConfigState: 'Disabled'}); expect(agent.status()).toBe('Disabled'); });
it("should be 'Disabled (Cancelled)' when agentConfigState is 'Disabled' and buildState is 'Cancelled'", () => { const agent = new Agents.Agent({agentConfigState: 'Disabled', buildState: 'Cancelled'}); expect(agent.status()).toBe('Disabled (Cancelled)'); });
it("should be pending when agentConfigState is Pending", () => { const agent = new Agents.Agent({agentConfigState: 'Pending'}); expect(agent.status()).toBe('Pending'); });
it("should default resource to be empty if no resource provided", () => { const elasticAgentData = agentData[7]; const agent = Agents.Agent.fromJSON(elasticAgentData); expect(agent.resources()).toEqual([]); });
it("should be able to say elastic agent or not", () => { const elasticAgentData = agentData[7]; const agent = Agents.Agent.fromJSON(elasticAgentData); expect(agent.isElasticAgent()).toBeTruthy(); });
it("should have elastic agent id and elastic plugin id", () => { const elasticAgentData = agentData[7]; const agent = Agents.Agent.fromJSON(elasticAgentData); expect(agent.elasticAgentId()).toBe('0039ddc8-38a0-4f7b-be15-522fcb6f8649'); expect(agent.elasticPluginId()).toBe('cd.go.contrib.elastic-agent.docker'); });
it("should tell whether the specified elastic agent id matches the agent's information", () => { const elasticAgentJSON = agentData[7]; const agent = Agents.Agent.fromJSON(elasticAgentJSON); expect(agent.matches(elasticAgentJSON.elastic_agent_id)).toBe(true); });
it("should be 'Building' when agentState is 'Building'", () => { const agent = new Agents.Agent({agentState: 'Building'}); expect(agent.status()).toBe('Building'); });