Skip to content

[CLI TEST] VDM-1507 si init #990

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

Merged
merged 5 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ dist
bdd/.work/
bdd/reports/*.html
bdd/*-test-result.txt
bdd/data/template_seq/

!bdd/data/template_seq/.gitkeep

# pre-runner sample-package
packages/pre-runner/sample-package/
Expand Down
Empty file added bdd/data/template_seq/.gitkeep
Empty file.
12 changes: 11 additions & 1 deletion bdd/features/e2e/E2E-010-cli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,14 @@ Feature: CLI tests
Then I confirm instance id is: <instanceId>
Examples:
| instanceId |
| Supervisor-Instance-0000-11111111111 |
| Supervisor-Instance-0000-11111111111 |

@ci-api @cli
Scenario: E2E-010 TC-019 Test Init template sequence
When I execute CLI command si init <templateType>
Then I confirm template <templateType> is created
Examples:
| templateType |
| ts |
| js |
| py |
106 changes: 105 additions & 1 deletion bdd/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function fileContains(filename: any, key: any) {
let line;

// eslint-disable-next-line no-cond-assign
while (line = stdoutFile.next()) {
while ((line = stdoutFile.next())) {
if (line.includes(key)) {
return;
}
Expand Down Expand Up @@ -274,3 +274,107 @@ export async function removeProfile(profileName: string) {
logger.debug(res);
}
}

export async function deleteAllFilesInDirectory(workingDirectory: string) {
try {
const files = await fs.promises.readdir(workingDirectory);

await Promise.all(
files.map(async (file) => {
const filePath = `${workingDirectory}/${file}`;

try {
await fs.promises.unlink(filePath);
if (isLogActive) {
logger.debug(`File ${filePath} was deleted`);
}
} catch (error) {
logger.error(`Deleting error file ${file}: ${error}`);
}
})
);
} catch (err) {
logger.error(`Can not read from directory: ${workingDirectory}`);
}
}

export function spawnSiInit(
command: string,
templateType: string,
workingDirectory: string,
env: NodeJS.ProcessEnv = process.env
) {
return new Promise<void>((resolve, reject) => {
const args = () => {
return [...si, "init", "seq", templateType, "-p", workingDirectory];
};

if (isLogActive) {
logger.debug("Spawning command: /usr/bin/env", ...args());
}

const childProcess = spawn(command, args(), {
env
});

childProcess.stdout.on("data", (data) => {
if (isLogActive) {
logger.debug(data.toString());
}
if (data.includes("Sequence template succesfully created")) {
resolve();
} else {
childProcess.stdin.write("\n");
}
});
childProcess.stderr.on("data", (data) => {
const stderrString = data.toString();

logger.warn(`Stderr: ${stderrString}`);
});
childProcess.on("error", (err) => {
logger.error(err);
reject();
});
childProcess.on("exit", (code) => {
if (isLogActive) {
logger.debug(`Exit code: ${code}`);
}
resolve();
});
});
}

export function isTemplateCreated(templateType: string, workingDirectory: string) {
return new Promise<boolean>((resolve, reject) => {
// eslint-disable-next-line complexity
fs.readdir(workingDirectory, (err, files) => {
if (err) {
logger.error(`Can not read from directory: ${workingDirectory}`);
reject(err);
return;
}
if (
templateType === "ts" &&
files.includes("index.ts") &&
files.includes("package.json") &&
files.includes("tsconfig.json")
) {
resolve(true);
}
if (
templateType === "py" &&
files.includes("main.py") &&
files.includes("package.json") &&
files.includes("requirements.txt")
) {
resolve(true);
}
if (templateType === "js" && files.includes("index.js") && files.includes("package.json")) {
resolve(true);
} else {
resolve(false);
}
});
});
}
24 changes: 23 additions & 1 deletion bdd/step-definitions/e2e/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
import { Given, Then, When } from "@cucumber/cucumber";
import { strict as assert } from "assert";
import fs from "fs";
import { getStreamsFromSpawn, defer, waitUntilStreamContains, killProcessByName, getSiCommand } from "../../lib/utils";
import {
getStreamsFromSpawn,
defer,
waitUntilStreamContains,
killProcessByName,
getSiCommand,
deleteAllFilesInDirectory,
spawnSiInit,
isTemplateCreated
} from "../../lib/utils";
import { expectedResponses } from "./expectedResponses";
import { CustomWorld } from "../world";
import { spawn } from "child_process";
Expand Down Expand Up @@ -359,3 +368,16 @@ Then(/^I confirm instance id is: (.*)$/, async function (this: CustomWorld, expe

assert.equal(instance.id, expectedInstanceId);
});

When(/^I execute CLI command si init (.*)$/, { timeout: 30000 }, async function (templateType: string) {
const workingDirectory = "data/template_seq";

await deleteAllFilesInDirectory(workingDirectory);
await spawnSiInit("/usr/bin/env", templateType, workingDirectory);
});

Then(/^I confirm template (.*) is created$/, async function (templateType: string) {
const workingDirectory = "data/template_seq";

assert.equal(await isTemplateCreated(templateType, workingDirectory), true);
});
4 changes: 2 additions & 2 deletions bdd/step-definitions/e2e/host-steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
defer,
waitUntilStreamEquals,
waitUntilStreamContains,
removeProfile,
createProfile,
setProfile,
removeProfile
setProfile
} from "../../lib/utils";
import fs, { createReadStream, existsSync, ReadStream } from "fs";
import { HostClient, InstanceOutputStream } from "@scramjet/api-client";
Expand Down