Skip to content

Commit

Permalink
refactor, using eql for more understandable error message
Browse files Browse the repository at this point in the history
  • Loading branch information
animehart committed Jun 28, 2023
1 parent 96e6e22 commit f87edb9
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(500);

expect(body.message).to.be(
'Please provide either benchmarkId or packagePolicyId, but not both'
expect(body.message).to.eql(
'Please provide either benchmarkId or packagePolicyId, but not both',
`expected 'Please provide either benchmarkId or packagePolicyId, but not both' but got ${body.message} instead`
);
});

Expand All @@ -80,8 +81,9 @@ export default function ({ getService }: FtrProviderContext) {
})
.expect(500);

expect(body.message).to.be(
'Please provide either benchmarkId or packagePolicyId, but not both'
expect(body.message).to.eql(
'Please provide either benchmarkId or packagePolicyId, but not both',
`expected 'Please provide either benchmarkId or packagePolicyId, but not both' but got ${body.message} instead`
);
});

Expand All @@ -95,8 +97,8 @@ export default function ({ getService }: FtrProviderContext) {
})
.expect(404);

expect(body.statusCode).to.be(404);
expect(body.error).to.be('Not Found');
expect(body.statusCode).to.eql(404, `expected 404 but got ${body.statusCode} instead`);
expect(body.error).to.eql('Not Found', `expected 'Not Found' but got ${body.error} instead`);
});

it(`Should return 200 status code and filter rules by benchmarkId`, async () => {
Expand Down Expand Up @@ -124,7 +126,10 @@ export default function ({ getService }: FtrProviderContext) {
(rule: CspRuleTemplate) => rule.metadata.benchmark.id === 'cis_k8s'
);

expect(allRulesHaveCorrectBenchmarkId).to.be(true);
expect(allRulesHaveCorrectBenchmarkId).to.eql(
true,
`expected true but got ${allRulesHaveCorrectBenchmarkId} instead`
);
});

it(`Should return 200 status code, and only requested fields in the response`, async () => {
Expand Down Expand Up @@ -157,7 +162,7 @@ export default function ({ getService }: FtrProviderContext) {
);
});

expect(fieldsMatched).to.be(true);
expect(fieldsMatched).to.eql(true, `expected true but got ${fieldsMatched} instead`);
});

it(`Should return 200 status code, items sorted by metadata.section field`, async () => {
Expand Down Expand Up @@ -188,7 +193,8 @@ export default function ({ getService }: FtrProviderContext) {
const isSorted = sections.every(
(section, index) => index === 0 || section >= sections[index - 1]
);
expect(isSorted).to.be(true);

expect(isSorted).to.eql(true, `expected true but got ${isSorted} instead`);
});

it(`Should return 200 status code and paginate rules with a limit of PerPage`, async () => {
Expand All @@ -213,7 +219,10 @@ export default function ({ getService }: FtrProviderContext) {
})
.expect(200);

expect(body.items.length).to.be(perPage);
expect(body.items.length).to.eql(
perPage,
`expected ${perPage} but got ${body.items.length} instead`
);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.kspm.status).to.be('index-timeout');
expect(res.kspm.status).to.eql(
'index-timeout',
`expected index-timeout but got ${res.kspm.status} instead`
);
});

it(`Should return index-timeout when installed cspm, has findings only on logs-cloud_security_posture.findings-default* and it has been more than 10 minutes since the installation`, async () => {
Expand All @@ -134,7 +137,10 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.cspm.status).to.be('index-timeout');
expect(res.cspm.status).to.eql(
'index-timeout',
`expected index-timeout but got ${res.cspm.status} instead`
);
});

it(`Should return index-timeout when installed cnvm, has findings only on logs-cloud_security_posture.vulnerabilities-default* and it has been more than 4 hours minutes since the installation`, async () => {
Expand All @@ -160,7 +166,10 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.vuln_mgmt.status).to.be('index-timeout');
expect(res.vuln_mgmt.status).to.eql(
'index-timeout',
`expected index-timeout but got ${res.vuln_mgmt.status} instead`
);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.kspm.status).to.be('indexed');
expect(res.kspm.status).to.eql(
'indexed',
`expected indexed but got ${res.kspm.status} instead`
);
});

it(`Return cspm status indexed when logs-cloud_security_posture.findings_latest-default contains new cspm documents`, async () => {
Expand All @@ -92,7 +95,10 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.cspm.status).to.be('indexed');
expect(res.cspm.status).to.eql(
'indexed',
`expected indexed but got ${res.cspm.status} instead`
);
});

it(`Return vuln status indexed when logs-cloud_security_posture.vulnerabilities_latest-default contains new documents`, async () => {
Expand All @@ -110,7 +116,10 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.vuln_mgmt.status).to.be('indexed');
expect(res.vuln_mgmt.status).to.eql(
'indexed',
`expected indexed but got ${res.vuln_mgmt.status} instead`
);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.kspm.status).to.be('indexing');
expect(res.kspm.status).to.eql(
'indexing',
`expected indexing but got ${res.kspm.status} instead`
);
});

it(`Return cspm status indexing when logs-cloud_security_posture.findings_latest-default doesn't contain new cspm documents, but has newly connected agents `, async () => {
Expand All @@ -91,7 +94,10 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.cspm.status).to.be('indexing');
expect(res.cspm.status).to.eql(
'indexing',
`expected indexing but got ${res.cspm.status} instead`
);
});

it(`Return vuln status indexing when logs-cloud_security_posture.vulnerabilities_latest-default doesn't contain vuln new documents, but has newly connected agents`, async () => {
Expand All @@ -109,7 +115,10 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.vuln_mgmt.status).to.be('indexing');
expect(res.vuln_mgmt.status).to.eql(
'indexing',
`expected indexing but got ${res.vuln_mgmt.status} instead`
);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,26 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.kspm.status).to.be('not-deployed');
expect(res.cspm.status).to.be('not-installed');
expect(res.vuln_mgmt.status).to.be('not-installed');
expect(res.kspm.healthyAgents).to.be(0);
expect(res.kspm.installedPackagePolicies).to.be(1);
expect(res.kspm.status).to.eql(
'not-deployed',
`expected not-deployed but got ${res.kspm.status} instead`
);
expect(res.cspm.status).to.eql(
'not-installed',
`expected not-installed but got ${res.cspm.status} instead`
);
expect(res.vuln_mgmt.status).to.eql(
'not-installed',
`expected not-installed but got ${res.vuln_mgmt.status} instead`
);
expect(res.kspm.healthyAgents).to.eql(
0,
`expected 0 but got ${res.kspm.healthyAgents} instead`
);
expect(res.kspm.installedPackagePolicies).to.eql(
1,
`expected 1 but got ${res.kspm.installedPackagePolicies} instead`
);
});

it(`Should return not-deployed when installed cspm, no findings on either indices and no healthy agents`, async () => {
Expand All @@ -75,11 +90,26 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.cspm.status).to.be('not-deployed');
expect(res.kspm.status).to.be('not-installed');
expect(res.vuln_mgmt.status).to.be('not-installed');
expect(res.cspm.healthyAgents).to.be(0);
expect(res.cspm.installedPackagePolicies).to.be(1);
expect(res.cspm.status).to.eql(
'not-deployed',
`expected not-deployed but got ${res.cspm.status} instead`
);
expect(res.kspm.status).to.eql(
'not-installed',
`expected not-installed but got ${res.kspm.status} instead`
);
expect(res.vuln_mgmt.status).to.eql(
'not-installed',
`expected not-installed but got ${res.vuln_mgmt.status} instead`
);
expect(res.cspm.healthyAgents).to.eql(
0,
`expected 0 but got ${res.cspm.healthyAgents} instead`
);
expect(res.cspm.installedPackagePolicies).to.eql(
1,
`expected 1 but got ${res.cspm.installedPackagePolicies} instead`
);
});

it(`Should return not-deployed when installed cnvm, no findings on either indices and no healthy agents`, async () => {
Expand All @@ -97,11 +127,26 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.expect(200);

expect(res.cspm.status).to.be('not-installed');
expect(res.kspm.status).to.be('not-installed');
expect(res.vuln_mgmt.status).to.be('not-deployed');
expect(res.vuln_mgmt.healthyAgents).to.be(0);
expect(res.vuln_mgmt.installedPackagePolicies).to.be(1);
expect(res.cspm.status).to.eql(
'not-installed',
`expected not-installed but got ${res.cspm.status} instead`
);
expect(res.kspm.status).to.eql(
'not-installed',
`expected not-installed but got ${res.kspm.status} instead`
);
expect(res.vuln_mgmt.status).to.eql(
'not-deployed',
`expected not-deployed but got ${res.vuln_mgmt.status} instead`
);
expect(res.vuln_mgmt.healthyAgents).to.eql(
0,
`expected 0 but got ${res.vuln_mgmt.healthyAgents} instead`
);
expect(res.vuln_mgmt.installedPackagePolicies).to.eql(
1,
`expected 1 but got ${res.vuln_mgmt.installedPackagePolicies} instead`
);
});
});
});
Expand Down
Loading

0 comments on commit f87edb9

Please sign in to comment.