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 all 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
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 @test-si-init
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 |
103 changes: 103 additions & 0 deletions bdd/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,106 @@ export async function removeProfile(profileName: string) {
logger.debug(res);
}
}

export function createDirectory(workingDirectory: string) {
if (!fs.existsSync(workingDirectory)) {
fs.mkdirSync(workingDirectory);
if (isLogActive) {
logger.debug(`Directory "${workingDirectory}" successfully created`);
}
} else {
logger.error(`Directory "${workingDirectory}" already exist`);
}
}

export function deleteDirectory(workingDirectory: string) {
try {
fs.rmdirSync(workingDirectory, { recursive: true });
if (isLogActive) {
logger.debug(`Directory "${workingDirectory}" was successfully deleted`);
}
} catch (error: any) {
logger.error(`Error while deleting direcory "${workingDirectory}": ${error.message}`);
}
}

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);
}
});
});
}
22 changes: 21 additions & 1 deletion bdd/step-definitions/e2e/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
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,
spawnSiInit,
isTemplateCreated
} from "../../lib/utils";
import { expectedResponses } from "./expectedResponses";
import { CustomWorld } from "../world";
import { spawn } from "child_process";
Expand Down Expand Up @@ -359,3 +367,15 @@ 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 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);
});
13 changes: 11 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,11 @@ import {
defer,
waitUntilStreamEquals,
waitUntilStreamContains,
removeProfile,
createProfile,
setProfile,
removeProfile
createDirectory,
deleteDirectory
} from "../../lib/utils";
import fs, { createReadStream, existsSync, ReadStream } from "fs";
import { HostClient, InstanceOutputStream } from "@scramjet/api-client";
Expand Down Expand Up @@ -179,6 +181,13 @@ Before(() => {

After({ tags: "@runner-cleanup" }, killRunner);

Before({ tags: "@test-si-init" }, function() {
createDirectory("data/template_seq");
});
After({ tags: "@test-si-init" }, function() {
deleteDirectory("data/template_seq");
});

const startHost = async () => {
let apiUrl = process.env.SCRAMJET_HOST_BASE_URL;

Expand Down Expand Up @@ -683,7 +692,7 @@ When("confirm that sequence and volumes are removed", async function(this: Custo

if (!sequenceId) assert.fail();

const sequences = await hostClient.listSequences() || [];
const sequences = (await hostClient.listSequences()) || [];
const sequenceExist = !!sequences.find((sequenceInfo) => sequenceId === sequenceInfo.id);

assert.equal(sequenceExist, false);
Expand Down