Skip to content

Commit

Permalink
Fixup tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneseymour committed May 18, 2020
1 parent 7364f7f commit 8312c9e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 26,945 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import expect from '@kbn/expect';
import { ciRunUrl } from '../transforms';
import { ciRunUrl, coveredFilePath, itemizeVcs } from '../transforms';

describe(`Transform fn`, () => {
describe(`ciRunUrl`, () => {
Expand All @@ -31,4 +31,32 @@ describe(`Transform fn`, () => {
expect(ciRunUrl({ a: 'a' })).not.to.have.property('ciRunUrl');
});
});
describe(`coveredFilePath`, () => {
it(`should remove the jenkins workspace path`, () => {
const obj = {
staticSiteUrl:
'/var/lib/jenkins/workspace/elastic+kibana+code-coverage/kibana/x-pack/legacy/plugins/reporting/server/browsers/extract/unzip.js',
COVERAGE_INGESTION_KIBANA_ROOT:
'/var/lib/jenkins/workspace/elastic+kibana+code-coverage/kibana',
};
expect(coveredFilePath(obj)).to.have.property(
'coveredFilePath',
'x-pack/legacy/plugins/reporting/server/browsers/extract/unzip.js'
);
});
});
describe(`itemizeVcs`, () => {
it(`should return a sha url`, () => {
const vcsInfo = [
'origin/ingest-code-coverage',
'f07b34f6206',
`Tre' Seymour`,
`Lorem :) ipsum Tre' λ dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`,
];
expect(itemizeVcs(vcsInfo)({}).vcs).to.have.property(
'vcsUrl',
`https://github.com/elastic/kibana/commit/${vcsInfo[1]}`
);
});
});
});
1 change: 0 additions & 1 deletion src/dev/code_coverage/ingest_coverage/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
* under the License.
*/

export const STATIC_SITE_URL_PROP_NAME = 'staticSiteUrl';
export const COVERAGE_INDEX = process.env.COVERAGE_INDEX || 'kibana_code_coverage';
export const TOTALS_INDEX = process.env.TOTALS_INDEX || `kibana_total_code_coverage`;
5 changes: 1 addition & 4 deletions src/dev/code_coverage/ingest_coverage/ingest.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
const { Client } = require('@elastic/elasticsearch');
import { createFailError } from '@kbn/dev-utils';
import chalk from 'chalk';
import { green, always } from './utils';
import { green, always, pretty } from './utils';
import { fromNullable } from './either';
import { COVERAGE_INDEX, TOTALS_INDEX } from './constants';

Expand Down Expand Up @@ -98,6 +98,3 @@ function color(whichColor) {
return chalk[whichColor].bgWhiteBright(x);
};
}
function pretty(x) {
return JSON.stringify(x, null, 2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
* under the License.
*/

import expect from '@kbn/expect';
import { spawn } from 'child_process';
import { resolve } from 'path';
import { green, always } from '../utils';

import { STATIC_SITE_URL_PROP_NAME, COVERAGE_INDEX } from '../constants';

const ROOT_DIR = resolve(__dirname, '../../../../..');
const MOCKS_DIR = resolve(__dirname, './mocks');
const staticSiteUrlRegexes = {
Expand All @@ -40,110 +37,43 @@ const env = {
NODE_ENV: 'integration_test',
COVERAGE_INGESTION_KIBANA_ROOT: '/var/lib/jenkins/workspace/elastic+kibana+code-coverage/kibana',
};
const includesSiteUrlPredicate = x => x.includes(STATIC_SITE_URL_PROP_NAME);
const includesSiteUrlPredicate = x => x.includes('staticSiteUrl');
const siteUrlLines = specificLinesOnly(includesSiteUrlPredicate);
const splitByNewLine = x => x.split('\n');
const siteUrlsSplitByNewLine = siteUrlLines(splitByNewLine);
const siteUrlsSplitByNewLineWithoutBlanks = siteUrlsSplitByNewLine(notBlankLines);

describe('Ingesting Coverage to Cluster', () => {
const verboseArgs = [
'scripts/ingest_coverage.js',
'--verbose',
'--vcsInfoPath',
'src/dev/code_coverage/ingest_coverage/integration_tests/mocks/VCS_INFO.txt',
'--path',
];

const noTotalsPath = 'jest-combined/coverage-summary-NO-total.json';
const verboseArgs = [
'scripts/ingest_coverage.js',
'--verbose',
'--vcsInfoPath',
'src/dev/code_coverage/ingest_coverage/integration_tests/mocks/VCS_INFO.txt',
'--path',
];

describe('Ingesting coverage', () => {
const bothIndexesPath = 'jest-combined/coverage-summary-manual-mix.json';

describe('with NODE_ENV set to "integration_test"', () => {
describe(`and debug || verbose turned on`, () => {
describe(`to the [${COVERAGE_INDEX}] index`, () => {
const mutableCoverageIndexChunks = [];

beforeAll(done => {
const ingestAndMutateAsync = ingestAndMutate(done);
const ingestAndMutateAsyncWithPath = ingestAndMutateAsync(noTotalsPath);
const verboseIngestAndMutateAsyncWithPath = ingestAndMutateAsyncWithPath(verboseArgs);
verboseIngestAndMutateAsyncWithPath(mutableCoverageIndexChunks);
});

it(
'should result in every posted item having a site url that meets all regex assertions',
always(
siteUrlsSplitByNewLineWithoutBlanks(mutableCoverageIndexChunks).forEach(
expectAllRegexesToPass({
...staticSiteUrlRegexes,
endsInDotJsDotHtml: /.js.html$/,
})
)
)
);
});
describe(`to both indexes in the same push`, () => {
const mutableBothIndexesChunks = [];

beforeAll(done => {
const ingestAndMutateAsync = ingestAndMutate(done);
const ingestAndMutateAsyncWithPath = ingestAndMutateAsync(bothIndexesPath);
const verboseIngestAndMutateAsyncWithPath = ingestAndMutateAsyncWithPath(verboseArgs);
verboseIngestAndMutateAsyncWithPath(mutableBothIndexesChunks);
});
describe(`to the coverage index`, () => {
const mutableCoverageIndexChunks = [];

it(
'should result in every posted item having a site url that meets all regex assertions',
always(
siteUrlsSplitByNewLineWithoutBlanks(mutableBothIndexesChunks).forEach(
expectAllRegexesToPass(staticSiteUrlRegexes)
)
)
);

it('should result in the "just logging" message being present in the log', () => {
expect(mutableBothIndexesChunks.some(x => x.includes('Just Logging'))).to.be(true);
});
it('should result in the "actually sending" message NOT being present in the log', () => {
expect(mutableBothIndexesChunks.every(x => !x.includes('Actually sending...'))).to.be(
true
);
});
describe(`with provided vcs info file`, () => {
const filterZero = xs => included => xs.filter(x => x.includes(included))[0];
const filteredWith = filterZero(mutableBothIndexesChunks);
it('should have a vcs block', () => {
const vcs = 'vcs';
const portion = filteredWith(vcs);
expect(portion).to.contain(vcs);
});
it(`should have a branch`, () => {
const branch = `"branch":`;
const portion = filteredWith(branch);
expect(portion).to.contain(branch);
expect(portion).to.contain(`"origin/ingest-code-coverage"`);
});
it(`should have a sha`, () => {
const sha = `"sha":`;
const portion = filteredWith(sha);
expect(portion).to.contain(sha);
expect(portion).to.contain(`"f07b34f6206"`);
});
it(`should have an author`, () => {
const author = `"author":`;
const portion = filteredWith(author);
expect(portion).to.contain(author);
expect(portion).to.contain(`"Tre' Seymour"`);
});
it(`should have a commit msg, truncated`, () => {
const commitMsg = `"commitMsg":`;
const portion = filteredWith(commitMsg);
expect(portion).to.contain(commitMsg);
expect(portion).to.contain(`"Lorem :) ipsum Tre' λ dolor sit amet, consectetur ..."`);
});
});
});
beforeAll(done => {
const ingestAndMutateAsync = ingestAndMutate(done);
const ingestAndMutateAsyncWithPath = ingestAndMutateAsync(bothIndexesPath);
const verboseIngestAndMutateAsyncWithPath = ingestAndMutateAsyncWithPath(verboseArgs);
verboseIngestAndMutateAsyncWithPath(mutableCoverageIndexChunks);
});

it(
'should result in every posted item having a site url that meets all regex assertions',
always(
siteUrlsSplitByNewLineWithoutBlanks(mutableCoverageIndexChunks).forEach(
expectAllRegexesToPass({
...staticSiteUrlRegexes,
endsInDotJsDotHtml: /.js.html$/,
})
)
)
);
});
});

Expand Down
Loading

0 comments on commit 8312c9e

Please sign in to comment.