Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add E2E Mutation tests for Lagu #501

Closed
wants to merge 13 commits into from
2 changes: 1 addition & 1 deletion cli/data/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ input DeleteOpenshiftInput {
}

input DeleteProjectInput {
id: Int!
project: String!
}

input DeleteSshKeyInput {
Expand Down
4 changes: 2 additions & 2 deletions cli/data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3136,14 +3136,14 @@
"fields": null,
"inputFields": [
{
"name": "id",
"name": "project",
"description": "",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"name": "String",
"ofType": null
}
},
Expand Down
3 changes: 2 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"chalk": "^2.4.1",
"exit": "^0.1.2",
"findup-sync": "^2.0.0",
"graphql": "^0.13.2",
"hosted-git-info": "^2.6.0",
Expand All @@ -75,6 +76,6 @@
"tildify": "^1.2.0",
"untildify": "^3.0.2",
"url-regex": "^4.1.1",
"yargs": "^11.0.0"
"yargs": "^12.0.1"
}
}
228 changes: 150 additions & 78 deletions cli/src/__tests__/__snapshots__/e2e.test.js.snap

Large diffs are not rendered by default.

79 changes: 69 additions & 10 deletions cli/src/__tests__/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('lagu', () => {
'--token',
tokenPath,
'--project',
'ci-multiproject1',
'ci-github',
'--api',
'http://localhost:3000',
'--ssh',
Expand Down Expand Up @@ -134,17 +134,48 @@ describe('lagu', () => {
});

it('should list all environments for a project (project read from .lagoon.yml)', async () => {
const results = spawnSync(CLI_PATH, ['environments'], {
reject: false,
const results = spawnSync(CLI_PATH, ['environments'], { cwd });
expect(results.code).toBe(0);
expect(stripCreatedDates(results.stdout)).toMatchSnapshot();
});

it('should show project details (read from .lagoon.yml)', async () => {
const results = spawnSync(CLI_PATH, ['project'], {
cwd,
});
expect(results.code).toBe(0);
expect(stripCreatedDates(results.stdout)).toMatchSnapshot();
});

it('should show project details (using --project option)', async () => {
it('should list all projects', async () => {
const results = spawnSync(CLI_PATH, ['projects'], {
cwd,
});
expect(results.code).toBe(0);
expect(stripCreatedDates(results.stdout)).toMatchSnapshot();
});

it('should create a project', async () => {
const results = spawnSync(
CLI_PATH,
['project', '--project', 'ci-multiproject1'],
[
'project',
'create',
'--customer',
'3',
'--name',
'e2e-test-project',
'--git_url',
'ssh://[email protected]:2222/git/e2e-test-project.git',
'--openshift',
'2',
'--branches',
'true',
'--pullrequests',
'true',
'--production_environment',
'master',
],
{
cwd,
},
Expand All @@ -153,22 +184,50 @@ describe('lagu', () => {
expect(stripCreatedDates(results.stdout)).toMatchSnapshot();
});

it('should show project details (read from .lagoon.yml)', async () => {
const results = spawnSync(CLI_PATH, ['project'], {
cwd,
});
it('should show newly-created project details (using --project option)', async () => {
const results = spawnSync(
CLI_PATH,
['project', '--project', 'e2e-test-project'],
{
cwd,
},
);
expect(results.code).toBe(0);
expect(stripCreatedDates(results.stdout)).toMatchSnapshot();
});

it('should list all projects', async () => {
it('should list the new project among all projects', async () => {
const results = spawnSync(CLI_PATH, ['projects'], {
cwd,
});
expect(results.code).toBe(0);
expect(stripCreatedDates(results.stdout)).toMatchSnapshot();
});

it('should delete the project', async () => {
const results = spawnSync(
CLI_PATH,
['project', 'delete', '--project', 'e2e-test-project'],
{
cwd,
},
);
expect(results.code).toBe(0);
expect(results.stdout).toMatchSnapshot();
});

it('should not show deleted project details (using --project option)', async () => {
const results = spawnSync(
CLI_PATH,
['project', '--project', 'e2e-test-project'],
{
cwd,
},
);
expect(results.code).toBe(0);
expect(stripCreatedDates(results.stdout)).toMatchSnapshot();
});

it('should log out when logged in', async () => {
const results = spawnSync(CLI_PATH, ['logout'], {
cwd,
Expand Down
13 changes: 8 additions & 5 deletions cli/src/cli/answerWithOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { blue } from 'chalk';
import R from 'ramda';

import type Inquirer from 'inquirer';
import type { inquirer$Answers } from 'inquirer';

function notifyOptionUsed(
clog: typeof console.log,
Expand All @@ -23,7 +23,7 @@ export function answerWithOptionIfSet({
clog,
}: {
option: string,
answers: Inquirer.answers,
answers: inquirer$Answers,
notify?: boolean,
clog: typeof console.log,
}) {
Expand All @@ -33,13 +33,16 @@ export function answerWithOptionIfSet({
R.has(option),
R.prop('options'),
): ({ options: Object }) => boolean),
(objectWithOptions: { options: Object }): void => {
(objectWithOptions: { options: Object }): false => {
// Assign option key in the answers object to option value and let the user know
const propVal = R.path(['options', option], objectWithOptions);
if (notify === true) {
notifyOptionUsed(clog, option, propVal);
}

// $FlowFixMe Covariant property cannot be assigned
answers[option] = propVal;
return false;
},
];
}
Expand All @@ -56,8 +59,8 @@ export function answerWithOptionIfSetOrPrompt({
options: Object,
notify?: boolean,
clog: typeof console.log,
}) {
return (answers: Inquirer.answers) =>
}): inquirer$Answers => boolean {
return (answers: inquirer$Answers) =>
R.ifElse(
// If the option exists, use it and let the user know...
...answerWithOptionIfSet({
Expand Down
1 change: 1 addition & 0 deletions cli/src/cli/promptUntilValidKeyPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function promptUntilValidKeyPath(
// TODO: Move the fileExists validation logic to this object under the validate key to fail earlier
},
]);

if (
!(await fileExists(
// Expand tilde characters in paths
Expand Down
3 changes: 2 additions & 1 deletion cli/src/cli/visit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow

import exit from 'exit';
import { printErrors } from '../printErrors';

import typeof Yargs from 'yargs';
Expand Down Expand Up @@ -46,6 +47,6 @@ export function visit(cmd: CommandModule) {
process.exit(exitCode);
})
// Process returned with an exit code of typically 0 (success) or 1 (failure)
.then(code => process.exit(code)),
.then(code => exit(code)),
};
}
5 changes: 1 addition & 4 deletions cli/src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export type BaseHandlerArgs = {|
cerr: typeof console.error,
|};

const notUndefined = R.complement(R.equals(undefined));

export function getOptions({
config,
argv,
Expand All @@ -29,8 +27,7 @@ export function getOptions({
return (R.pick(R.keys(commandOptions))({
// Remove options from the config that should require user input every time
...R.omit(dynamicOptionKeys || [], config || {}),
// Filter out unspecified values (yargs sets them as `undefined`) so that they don't overwrite config values
...R.filter(notUndefined, argv),
...argv,
}): {
[key: $Keys<typeof commandOptions>]: any,
});
Expand Down
17 changes: 8 additions & 9 deletions cli/src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { printErrors } from '../printErrors';
import { getOptions } from '.';

import typeof Yargs from 'yargs';
import type { LagoonConfigInput } from '../config';
import type { BaseHandlerArgs } from '.';

export const command = 'init';
Expand All @@ -33,7 +34,7 @@ export const commandOptions = {
[TOKEN]: TOKEN,
};

type Options = {
type OptionalOptions = {
overwrite?: boolean,
project?: string,
api?: string,
Expand All @@ -48,7 +49,6 @@ export function builder(yargs: Yargs) {
[OVERWRITE]: {
describe: 'Overwrite the configuration file if it exists',
type: 'boolean',
default: undefined,
},
[PROJECT]: {
describe: 'Name of project to configure',
Expand Down Expand Up @@ -111,7 +111,7 @@ export function builder(yargs: Yargs) {

type PromptForOverwriteArgs = {|
filepath: string,
options: Options,
options: OptionalOptions,
clog: typeof console.log,
|};

Expand Down Expand Up @@ -139,7 +139,7 @@ PromptForOverwriteArgs): Promise<{ [key: typeof OVERWRITE]: boolean }> {

type InitArgs = {|
cwd: string,
options: Options,
options: OptionalOptions,
clog: typeof console.log,
cerr: typeof console.error,
|};
Expand Down Expand Up @@ -167,7 +167,8 @@ InitArgs): Promise<number> {
});
}

const configInput = await inquirer.prompt([
// $FlowFixMe inquirer$Answers is inexact, LagoonConfigInput is exact
const configInput: LagoonConfigInput = await inquirer.prompt([
{
type: 'input',
name: PROJECT,
Expand Down Expand Up @@ -215,15 +216,13 @@ InitArgs): Promise<number> {
notify: true,
clog,
}),
filter: untildify,
},
]);

try {
clog(`Creating file '${filepath}'...`);
await createConfig(
filepath,
R.over(R.lensProp(TOKEN), untildify, configInput),
);
await createConfig(filepath, configInput);
clog(green('Configuration file created!'));
return 0;
} catch (e) {
Expand Down
17 changes: 9 additions & 8 deletions cli/src/commands/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { visit } from '../cli/visit';
import { config } from '../config';
import gql from '../gql';
import { runGQLQuery } from '../query';
import {
printGraphQLErrors,
printProjectConfigurationError,
} from '../printErrors';
import { printGraphQLErrors } from '../printErrors';
import { getOptions } from '.';

import typeof Yargs from 'yargs';
Expand All @@ -26,8 +23,12 @@ export const commandOptions = {
[PROJECT]: PROJECT,
};

type OptionalOptions = {
project?: string,
};

type Options = {
project: string,
+project: string,
};

export function builder(yargs: Yargs): Yargs {
Expand All @@ -53,15 +54,15 @@ export function builder(yargs: Yargs): Yargs {
}

type PromptForQueryOptionsArgs = {|
options: Options,
options: OptionalOptions,
clog: typeof console.log,
|};

async function promptForQueryOptions({
options,
clog,
}:
PromptForQueryOptionsArgs): Promise<{ [key: typeof PROJECT]: string }> {
PromptForQueryOptionsArgs): Promise<Options> {
return inquirer.prompt([
{
type: 'input',
Expand All @@ -75,7 +76,7 @@ PromptForQueryOptionsArgs): Promise<{ [key: typeof PROJECT]: string }> {
type ProjectDetailsArgs = {
clog: typeof console.log,
cerr: typeof console.error,
options: Options,
options: OptionalOptions,
};

export async function projectDetails({
Expand Down
Loading