117 lines
3.4 KiB
TypeScript
117 lines
3.4 KiB
TypeScript
import { assertEquals } from '@std/assert';
|
|
import * as path from '@std/path';
|
|
import * as smartpath from '@push.rocks/smartpath';
|
|
|
|
// Set up test environment
|
|
Deno.env.set('NPMTS_TEST', 'true');
|
|
Deno.env.set('NPMCI_URL_CLOUDLY', 'localhost');
|
|
Deno.env.set('CI_REPOSITORY_URL', 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git');
|
|
Deno.env.set('CI_BUILD_TOKEN', 'kjlkjfiudofiufs');
|
|
Deno.env.set('NPMCI_LOGIN_DOCKER', 'docker.io|someuser|somepass');
|
|
Deno.env.set('NPMCI_SSHKEY_1', 'hostString|somePrivKey|##');
|
|
|
|
// Get the test assets directory
|
|
const testAssetsDir = path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), 'assets/');
|
|
|
|
// Save original cwd and change to test assets
|
|
const originalCwd = Deno.cwd();
|
|
Deno.chdir(testAssetsDir);
|
|
|
|
import type { Dockerfile } from '../ts/manager.docker/mod.classes.dockerfile.ts';
|
|
import { Szci } from '../ts/szci.classes.szci.ts';
|
|
import * as DockerfileModule from '../ts/manager.docker/mod.classes.dockerfile.ts';
|
|
|
|
// ======
|
|
// Docker
|
|
// ======
|
|
|
|
let dockerfile1: Dockerfile;
|
|
let dockerfile2: Dockerfile;
|
|
let sortableArray: Dockerfile[];
|
|
|
|
Deno.test('should return valid Dockerfiles', async () => {
|
|
const szciInstance = new Szci();
|
|
await szciInstance.start();
|
|
dockerfile1 = new DockerfileModule.Dockerfile(szciInstance.dockerManager, {
|
|
filePath: './Dockerfile',
|
|
read: true,
|
|
});
|
|
dockerfile2 = new DockerfileModule.Dockerfile(szciInstance.dockerManager, {
|
|
filePath: './Dockerfile_sometag1',
|
|
read: true,
|
|
});
|
|
assertEquals(dockerfile1.version, 'latest');
|
|
assertEquals(dockerfile2.version, 'sometag1');
|
|
});
|
|
|
|
Deno.test('should read a directory of Dockerfiles', async () => {
|
|
const szciInstance = new Szci();
|
|
await szciInstance.start();
|
|
const readDockerfilesArray = await DockerfileModule.Dockerfile.readDockerfiles(
|
|
szciInstance.dockerManager
|
|
);
|
|
sortableArray = readDockerfilesArray;
|
|
assertEquals(readDockerfilesArray[1].version, 'sometag1');
|
|
});
|
|
|
|
Deno.test('should sort an array of Dockerfiles', async () => {
|
|
const sortedArray = await DockerfileModule.Dockerfile.sortDockerfiles(sortableArray);
|
|
console.log(sortedArray);
|
|
});
|
|
|
|
Deno.test('should build all Dockerfiles', async () => {
|
|
const szciInstance = new Szci();
|
|
await szciInstance.start();
|
|
await szciInstance.dockerManager.handleCli({
|
|
_: ['docker', 'build'],
|
|
});
|
|
});
|
|
|
|
Deno.test('should test all Dockerfiles', async () => {
|
|
const szciInstance = new Szci();
|
|
await szciInstance.start();
|
|
await szciInstance.dockerManager.handleCli({
|
|
_: ['docker', 'test'],
|
|
});
|
|
});
|
|
|
|
Deno.test('should login docker daemon', async () => {
|
|
const szciInstance = new Szci();
|
|
await szciInstance.start();
|
|
await szciInstance.dockerManager.handleCli({
|
|
_: ['docker', 'login'],
|
|
});
|
|
});
|
|
|
|
// ===
|
|
// SSH
|
|
// ===
|
|
Deno.test('should prepare SSH keys', async () => {
|
|
const npmciModSsh = await import('../ts/mod_ssh/index.ts');
|
|
await npmciModSsh.handleCli({
|
|
_: ['ssh', 'prepare'],
|
|
});
|
|
});
|
|
|
|
// ====
|
|
// node
|
|
// ====
|
|
Deno.test('should install a certain version of node', async () => {
|
|
const szciInstance = new Szci();
|
|
await szciInstance.start();
|
|
await szciInstance.nodejsManager.handleCli({
|
|
_: ['node', 'install', 'stable'],
|
|
});
|
|
await szciInstance.nodejsManager.handleCli({
|
|
_: ['node', 'install', 'lts'],
|
|
});
|
|
await szciInstance.nodejsManager.handleCli({
|
|
_: ['node', 'install', 'legacy'],
|
|
});
|
|
});
|
|
|
|
// Restore original working directory after all tests
|
|
Deno.test('reset paths', () => {
|
|
Deno.chdir(originalCwd);
|
|
});
|