update
This commit is contained in:
123
test/test.ts
123
test/test.ts
@@ -1,14 +1,14 @@
|
||||
import { assertEquals } from '@std/assert';
|
||||
import { assertEquals, assertExists } 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');
|
||||
// Set up test environment with the NEW SZCI environment variables
|
||||
Deno.env.set('SZCI_TEST', 'true');
|
||||
Deno.env.set('SZCI_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|##');
|
||||
Deno.env.set('SZCI_LOGIN_DOCKER', 'docker.io|someuser|somepass');
|
||||
Deno.env.set('SZCI_SSHKEY_1', 'hostString|somePrivKey|##');
|
||||
|
||||
// Get the test assets directory
|
||||
const testAssetsDir = path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), 'assets/');
|
||||
@@ -51,44 +51,81 @@ Deno.test('should read a directory of Dockerfiles', async () => {
|
||||
szciInstance.dockerManager
|
||||
);
|
||||
sortableArray = readDockerfilesArray;
|
||||
assertEquals(readDockerfilesArray[1].version, 'sometag1');
|
||||
|
||||
// The test assets directory should have multiple Dockerfiles
|
||||
assertExists(readDockerfilesArray, 'readDockerfilesArray should exist');
|
||||
assertEquals(readDockerfilesArray.length > 0, true, 'Should find at least one Dockerfile');
|
||||
|
||||
// Find the sometag1 dockerfile
|
||||
const sometag1Dockerfile = readDockerfilesArray.find(df => df.version === 'sometag1');
|
||||
assertExists(sometag1Dockerfile, 'Should find Dockerfile_sometag1');
|
||||
assertEquals(sometag1Dockerfile?.version, 'sometag1');
|
||||
});
|
||||
|
||||
Deno.test('should sort an array of Dockerfiles', async () => {
|
||||
// Use the sortableArray from previous test, or create a new one if empty
|
||||
if (!sortableArray || sortableArray.length === 0) {
|
||||
const szciInstance = new Szci();
|
||||
await szciInstance.start();
|
||||
sortableArray = await DockerfileModule.Dockerfile.readDockerfiles(szciInstance.dockerManager);
|
||||
}
|
||||
|
||||
const sortedArray = await DockerfileModule.Dockerfile.sortDockerfiles(sortableArray);
|
||||
console.log(sortedArray);
|
||||
assertExists(sortedArray, 'sortedArray should exist');
|
||||
console.log('Sorted dockerfiles:', sortedArray.map(df => df.cleanTag));
|
||||
});
|
||||
|
||||
Deno.test('should build all Dockerfiles', async () => {
|
||||
const szciInstance = new Szci();
|
||||
await szciInstance.start();
|
||||
await szciInstance.dockerManager.handleCli({
|
||||
_: ['docker', 'build'],
|
||||
});
|
||||
Deno.test({
|
||||
name: 'should build all Dockerfiles',
|
||||
// Allow resource leaks since smartshell creates background processes
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
fn: 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({
|
||||
name: 'should test all Dockerfiles',
|
||||
// Allow resource leaks since smartshell creates background processes
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
fn: 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'],
|
||||
});
|
||||
Deno.test({
|
||||
name: 'should login docker daemon',
|
||||
// Allow resource leaks since smartshell creates background processes
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
fn: 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({
|
||||
// Ensure test mode is set so we don't actually write to disk
|
||||
Deno.env.set('SZCI_TEST', 'true');
|
||||
|
||||
const szciModSsh = await import('../ts/mod_ssh/index.ts');
|
||||
await szciModSsh.handleCli({
|
||||
_: ['ssh', 'prepare'],
|
||||
});
|
||||
});
|
||||
@@ -96,18 +133,24 @@ Deno.test('should prepare SSH keys', async () => {
|
||||
// ====
|
||||
// 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'],
|
||||
});
|
||||
Deno.test({
|
||||
name: 'should install a certain version of node',
|
||||
// Allow resource leaks for this test since nvm creates background processes
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
fn: 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
|
||||
|
||||
Reference in New Issue
Block a user