Skip to content

Commit

Permalink
Add opts that dev-utils expects,
Browse files Browse the repository at this point in the history
and add unit tests.
  • Loading branch information
wayneseymour committed Jul 20, 2020
1 parent 54c3644 commit 05cb7a3
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .ci/Jenkinsfile_coverage
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ kibanaPipeline(timeoutMinutes: 240) {
]) {
workers.base(name: 'coverage-worker', size: 'l', ramDisk: false, bootstrapped: false) {
catchError {
kibanaCoverage.runTests()
// kibanaCoverage.runTests()
kibanaTeamAssign.load('team_assignment', "### Upload Team Assignment JSON")
handleIngestion(TIME_STAMP)
// handleIngestion(TIME_STAMP)
}
handleFail()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"abc": "123"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import expect from '@kbn/expect';
import { fetch } from '../team_assignment/get_data';
import { noop } from '../utils';

describe(`Team Assignment`, () => {
const mockPath = 'src/dev/code_coverage/ingest_coverage/__tests__/mocks/team_assign_mock.json';
describe(`fetch fn`, () => {
it(`should be a fn`, () => {
expect(typeof fetch).to.be('function');
});
describe(`applied to a path that exists`, () => {
it(`should return the contents of the path`, () => {
const sut = fetch(mockPath);
expect(sut.chain(JSON.parse)).to.have.property('abc');
});
});
describe(`applied to an non-existing path`, () => {
it(`should return a Left with the error message within`, () => {
const expectLeft = (err) =>
expect(err.message).to.contain('ENOENT: no such file or directory');

fetch('fake_path.json').fold(expectLeft, noop);
});
});
});
});
2 changes: 1 addition & 1 deletion src/dev/code_coverage/ingest_coverage/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ export const TEAM_ASSIGNMENT_PIPELINE_NAME = process.env.PIPELINE_NAME || 'team_
export const CODE_COVERAGE_CI_JOB_NAME = 'elastic+kibana+code-coverage';
export const RESEARCH_CI_JOB_NAME = 'elastic+kibana+qa-research';
export const CI_JOB_NAME = process.env.COVERAGE_JOB_NAME || RESEARCH_CI_JOB_NAME;
export const RESEARCH_CLUSTER_ES_HOST = process.env.ES_HOST || 'http://localhost:9200';
export const ES_HOST = process.env.ES_HOST || 'http://localhost:9200';
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

import { readFileSync } from 'fs';
import { resolve } from 'path';
import { fromNullable } from '../either';
import { tryCatch as tc } from '../either';

const ROOT = resolve(__dirname, '../../../../..');

const resolveFromRoot = resolve.bind(null, ROOT);
const path = `
src/dev/code_coverage/ingest_coverage/team_assignment/ingestion_pipeline_painless.json`;
const resolved = resolveFromRoot(path.trimStart());
const getContents = (scriptPath) => readFileSync(scriptPath, 'utf8');

export const fetch = () => fromNullable(resolved).map(getContents);
const resolved = (path) => () => resolveFromRoot(path);

const getContents = (path) => tc(() => readFileSync(path, 'utf8'));

// fetch :: String -> Left | Right
export const fetch = (path) => tc(resolved(path)).chain(getContents);
32 changes: 21 additions & 11 deletions src/dev/code_coverage/ingest_coverage/team_assignment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,39 @@
import { run } from '@kbn/dev-utils';
import { TEAM_ASSIGNMENT_PIPELINE_NAME } from '../constants';
import { fetch } from './get_data';
import { noop } from '../utils';
import { update } from './update_ingest_pipeline';

export const uploadTeamAssignmentJson = () => run(execute, { description });

const updatePipeline = update(TEAM_ASSIGNMENT_PIPELINE_NAME);

function execute({ flags, log }) {
const execute = ({ flags, log }) => {
if (flags.verbose) log.verbose(`### Verbose logging enabled`);

fetch().fold(noop, updatePipeline(log));
const logLeft = handleErr(log);
const updateAndLog = updatePipeline(log);

const { path } = flags;

fetch(path).fold(logLeft, updateAndLog);
};

function handleErr(log) {
return (msg) => log.error(msg);
}

function description() {
return `
const description = `
Upload the latest team assignment pipeline def from src,
to the cluster.
`;

Examples:
const flags = {
string: ['path', 'verbose'],
help: `
--path Required, path to painless definition for team assignment.
`,
};

node scripts/load_team_assignment.js --verbose
const usage = 'node scripts/load_team_assignment.js --verbose --path PATH_TO_PAINLESS_SCRIPT.json';

`;
}
export const uploadTeamAssignmentJson = () => run(execute, { description, flags, usage });
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/

import { createFailError } from '@kbn/dev-utils';
import { RESEARCH_CLUSTER_ES_HOST } from '../constants';
import { ES_HOST } from '../constants';
import { pretty, green } from '../utils';

const { Client } = require('@elastic/elasticsearch');

const node = RESEARCH_CLUSTER_ES_HOST;
const node = ES_HOST;
const client = new Client({ node });

export const update = (id) => (log) => async (body) => {
Expand Down
2 changes: 1 addition & 1 deletion src/dev/code_coverage/shell_scripts/assign_teams.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export PIPELINE_NAME
ES_HOST="https://${USER_FROM_VAULT}:${PASS_FROM_VAULT}@${HOST_FROM_VAULT}"
export ES_HOST

node scripts/load_team_assignment.js --verbose
node scripts/load_team_assignment.js --verbose --path src/dev/code_coverage/ingest_coverage/team_assignment/ingestion_pipeline_painless.json

echo "### Code Coverage Team Assignment - Complete"
echo ""

0 comments on commit 05cb7a3

Please sign in to comment.