Files
szci/test/test.ts

117 lines
3.4 KiB
TypeScript
Raw Normal View History

import { assertEquals } from '@std/assert';
import * as path from '@std/path';
2023-07-12 15:35:38 +02:00
import * as smartpath from '@push.rocks/smartpath';
2016-11-15 00:07:55 +01:00
// 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|##');
2017-08-28 01:35:21 +02:00
// Get the test assets directory
const testAssetsDir = path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), 'assets/');
2017-08-28 01:35:21 +02:00
// Save original cwd and change to test assets
const originalCwd = Deno.cwd();
Deno.chdir(testAssetsDir);
2016-11-15 00:07:55 +01:00
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';
2016-06-05 13:01:45 +02:00
2017-08-27 15:24:17 +02:00
// ======
// Docker
// ======
let dockerfile1: Dockerfile;
let dockerfile2: Dockerfile;
let sortableArray: Dockerfile[];
2016-06-05 13:01:45 +02:00
Deno.test('should return valid Dockerfiles', async () => {
const szciInstance = new Szci();
await szciInstance.start();
dockerfile1 = new DockerfileModule.Dockerfile(szciInstance.dockerManager, {
2019-08-29 20:38:44 +02:00
filePath: './Dockerfile',
2021-05-14 18:11:12 +00:00
read: true,
2019-08-29 20:38:44 +02:00
});
dockerfile2 = new DockerfileModule.Dockerfile(szciInstance.dockerManager, {
2019-08-29 20:38:44 +02:00
filePath: './Dockerfile_sometag1',
2021-05-14 18:11:12 +00:00
read: true,
2019-08-29 20:38:44 +02:00
});
assertEquals(dockerfile1.version, 'latest');
assertEquals(dockerfile2.version, 'sometag1');
2018-04-04 22:25:13 +02:00
});
2016-11-15 00:07:55 +01:00
Deno.test('should read a directory of Dockerfiles', async () => {
const szciInstance = new Szci();
await szciInstance.start();
const readDockerfilesArray = await DockerfileModule.Dockerfile.readDockerfiles(
szciInstance.dockerManager
2019-08-29 20:38:44 +02:00
);
sortableArray = readDockerfilesArray;
assertEquals(readDockerfilesArray[1].version, 'sometag1');
2018-04-04 22:25:13 +02:00
});
2016-11-15 00:07:55 +01:00
Deno.test('should sort an array of Dockerfiles', async () => {
const sortedArray = await DockerfileModule.Dockerfile.sortDockerfiles(sortableArray);
console.log(sortedArray);
2018-04-04 22:25:13 +02:00
});
2016-11-15 00:07:55 +01:00
Deno.test('should build all Dockerfiles', async () => {
const szciInstance = new Szci();
await szciInstance.start();
await szciInstance.dockerManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['docker', 'build'],
2018-04-04 22:25:13 +02:00
});
});
2016-11-15 00:18:32 +01:00
Deno.test('should test all Dockerfiles', async () => {
const szciInstance = new Szci();
await szciInstance.start();
await szciInstance.dockerManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['docker', 'test'],
2018-04-04 22:25:13 +02:00
});
});
2017-08-27 15:24:17 +02:00
Deno.test('should login docker daemon', async () => {
const szciInstance = new Szci();
await szciInstance.start();
await szciInstance.dockerManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['docker', 'login'],
2018-04-04 22:25:13 +02:00
});
});
2017-08-27 15:24:17 +02:00
// ===
// SSH
// ===
Deno.test('should prepare SSH keys', async () => {
const npmciModSsh = await import('../ts/mod_ssh/index.ts');
await npmciModSsh.handleCli({
2021-05-14 18:11:12 +00:00
_: ['ssh', 'prepare'],
2018-04-04 22:25:13 +02:00
});
});
2017-08-27 15:24:17 +02:00
// ====
// node
// ====
Deno.test('should install a certain version of node', async () => {
const szciInstance = new Szci();
await szciInstance.start();
await szciInstance.nodejsManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['node', 'install', 'stable'],
2018-04-04 22:25:13 +02:00
});
await szciInstance.nodejsManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['node', 'install', 'lts'],
2018-04-04 22:25:13 +02:00
});
await szciInstance.nodejsManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['node', 'install', 'legacy'],
2018-04-04 22:25:13 +02:00
});
});
// Restore original working directory after all tests
Deno.test('reset paths', () => {
Deno.chdir(originalCwd);
2018-04-04 22:25:13 +02:00
});