2023-09-11 19:49:45 +03:00
|
|
|
import { rmSync } from "fs";
|
|
|
|
import * as fs from "fs";
|
|
|
|
|
|
|
|
import {
|
|
|
|
IssueType,
|
|
|
|
StackGenerateType,
|
2023-10-31 09:03:39 +00:00
|
|
|
} from "../../src/core/model/process_model";
|
|
|
|
import { EXEC_TYPE } from "../../src/core/model/exec_error_model";
|
|
|
|
import { StackService } from "../../src/core/services/stack_service";
|
|
|
|
import { delay } from "../../src/core/helper/delay";
|
|
|
|
import { assert, dirname__ } from "../test";
|
|
|
|
import { TriggerType } from "../../src/features/triggers/trigger_model";
|
2023-09-11 19:49:45 +03:00
|
|
|
|
|
|
|
abstract class IStackServiceTest {
|
|
|
|
abstract test(): Promise<boolean>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function readDirRecursive(path: string, filesToDir: string[] = []) {
|
|
|
|
const files = fs.readdirSync(path);
|
|
|
|
files.forEach((file) => {
|
|
|
|
let filePath = "";
|
|
|
|
if (path[path.length - 1] !== "/") {
|
|
|
|
filePath = `${path}/${file}`;
|
|
|
|
} else {
|
|
|
|
filePath = `${path}${file}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const stats = fs.statSync(filePath);
|
|
|
|
if (stats.isDirectory()) {
|
|
|
|
readDirRecursive(filePath, filesToDir);
|
|
|
|
} else {
|
|
|
|
filesToDir.push(file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return filesToDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
class SimpleTestStackServiceTest
|
|
|
|
extends StackService
|
|
|
|
implements IStackServiceTest
|
|
|
|
{
|
|
|
|
constructor() {
|
|
|
|
super(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
process: {
|
|
|
|
type: EXEC_TYPE.EXEC,
|
|
|
|
command: `nix run gitlab:robossembler/nix-robossembler-overlay#test-script '{
|
|
|
|
"filesMeta":[
|
|
|
|
{"type":"folder","name":"example", "path": null,"rewrite":true}
|
|
|
|
],
|
|
|
|
"path":"$PATH"
|
|
|
|
}'`,
|
|
|
|
isGenerating: true,
|
|
|
|
isLocaleCode: false,
|
|
|
|
issueType: IssueType.WARNING,
|
|
|
|
},
|
|
|
|
trigger: {
|
|
|
|
type: TriggerType.FILE,
|
|
|
|
value: ["context"],
|
|
|
|
},
|
|
|
|
env: null,
|
|
|
|
stackGenerateType: StackGenerateType.SINGLETON,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
process: {
|
|
|
|
type: EXEC_TYPE.EXEC,
|
|
|
|
command: `nix run gitlab:robossembler/nix-robossembler-overlay#test-script '{
|
|
|
|
"filesMeta":[
|
|
|
|
{"type":"file","name":"1.txt", "path":"example","rewrite":true}
|
|
|
|
],
|
|
|
|
"path":"$PATH"
|
|
|
|
}'`,
|
|
|
|
isGenerating: true,
|
|
|
|
isLocaleCode: false,
|
|
|
|
issueType: IssueType.WARNING,
|
|
|
|
},
|
|
|
|
trigger: {
|
|
|
|
type: TriggerType.FILE,
|
|
|
|
value: ["1.txt"],
|
|
|
|
},
|
|
|
|
env: null,
|
|
|
|
stackGenerateType: StackGenerateType.SINGLETON,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
dirname__ + "/context/"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
async test(): Promise<boolean> {
|
|
|
|
await this.call();
|
|
|
|
const testResult = readDirRecursive(this.path).equals(
|
|
|
|
["1.txt", "test.txt"],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
await delay(100);
|
|
|
|
rmSync(this.path + "example/", { recursive: true });
|
|
|
|
return testResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class StackServiceTest {
|
|
|
|
dirName: string;
|
|
|
|
|
|
|
|
constructor(dirName: string) {
|
|
|
|
this.dirName = dirName;
|
|
|
|
}
|
|
|
|
public async test() {
|
|
|
|
const tests = [new SimpleTestStackServiceTest()];
|
|
|
|
for await (const el of tests) {
|
|
|
|
assert((await el.test()) === true, el.constructor.name);
|
|
|
|
await delay(3000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|