npmci/test/test.ts

134 lines
3.6 KiB
TypeScript
Raw Permalink Normal View History

2023-07-12 13:35:38 +00:00
import { tap, expect } from '@push.rocks/tapbundle';
2018-04-04 20:25:13 +00:00
import * as path from 'path';
2023-07-12 13:35:38 +00:00
import * as smartpath from '@push.rocks/smartpath';
2016-11-14 23:07:55 +00:00
2018-04-04 20:25:13 +00:00
process.env.NPMTS_TEST = 'true';
2022-10-11 12:26:42 +00:00
process.env.NPMCI_URL_CLOUDLY = 'localhost';
2017-08-27 23:35:21 +00:00
2016-11-14 23:07:55 +00:00
// set up environment
2018-04-04 20:25:13 +00:00
process.env.CI_REPOSITORY_URL = 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git';
process.env.CI_BUILD_TOKEN = 'kjlkjfiudofiufs';
2017-08-27 23:35:21 +00:00
// Docker
2018-04-04 20:25:13 +00:00
process.env.NPMCI_LOGIN_DOCKER = 'docker.io|someuser|somepass';
2017-08-27 23:35:21 +00:00
// SSH env
2018-04-04 20:25:13 +00:00
process.env.NPMCI_SSHKEY_1 = 'hostString|somePrivKey|##';
2017-08-27 23:35:21 +00:00
2016-06-05 11:01:45 +00:00
process.cwd = () => {
return path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), 'assets/');
2018-04-04 20:25:13 +00:00
};
2016-11-14 23:07:55 +00:00
2024-05-23 19:47:06 +00:00
import type * as npmciTypes from '../ts/index.js';
const npmci = await import('../ts/index.js');
2016-06-05 11:01:45 +00:00
2017-08-27 13:24:17 +00:00
// ======
// Docker
// ======
2024-05-23 19:47:06 +00:00
let dockerfile1: npmciTypes.Dockerfile;
let dockerfile2: npmciTypes.Dockerfile;
let sortableArray: npmciTypes.Dockerfile[];
2016-06-05 11:01:45 +00:00
tap.test('should return valid Dockerfiles', async () => {
2019-08-29 18:26:23 +00:00
const npmciInstance = new npmci.Npmci();
2023-08-24 15:25:55 +00:00
await npmciInstance.start();
2019-08-29 18:38:44 +00:00
dockerfile1 = new npmci.Dockerfile(npmciInstance.dockerManager, {
filePath: './Dockerfile',
2021-05-14 18:11:12 +00:00
read: true,
2019-08-29 18:38:44 +00:00
});
dockerfile2 = new npmci.Dockerfile(npmciInstance.dockerManager, {
filePath: './Dockerfile_sometag1',
2021-05-14 18:11:12 +00:00
read: true,
2019-08-29 18:38:44 +00:00
});
expect(dockerfile1.version).toEqual('latest');
return expect(dockerfile2.version).toEqual('sometag1');
2018-04-04 20:25:13 +00:00
});
2016-11-14 23:07:55 +00:00
tap.test('should read a directory of Dockerfiles', async () => {
2019-08-29 18:26:23 +00:00
const npmciInstance = new npmci.Npmci();
2023-08-24 15:25:55 +00:00
await npmciInstance.start();
2019-08-29 18:38:44 +00:00
return npmci.Dockerfile.readDockerfiles(npmciInstance.dockerManager).then(
2024-05-23 19:47:06 +00:00
async (readDockerfilesArrayArg: npmciTypes.Dockerfile[]) => {
2018-04-04 20:25:13 +00:00
sortableArray = readDockerfilesArrayArg;
return expect(readDockerfilesArrayArg[1].version).toEqual('sometag1');
2019-08-29 18:38:44 +00:00
}
);
2018-04-04 20:25:13 +00:00
});
2016-11-14 23:07:55 +00:00
tap.test('should sort an array of Dockerfiles', async () => {
2019-08-29 18:38:44 +00:00
return npmci.Dockerfile.sortDockerfiles(sortableArray).then(
2024-05-23 19:47:06 +00:00
async (sortedArrayArg: npmciTypes.Dockerfile[]) => {
2018-04-04 20:25:13 +00:00
console.log(sortedArrayArg);
2019-08-29 18:38:44 +00:00
}
);
2018-04-04 20:25:13 +00:00
});
2016-11-14 23:07:55 +00:00
2017-08-27 13:24:17 +00:00
tap.test('should build all Dockerfiles', async () => {
2019-08-29 18:26:23 +00:00
const npmciInstance = new npmci.Npmci();
2023-08-24 15:25:55 +00:00
await npmciInstance.start();
2019-08-29 18:26:23 +00:00
return npmciInstance.dockerManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['docker', 'build'],
2018-04-04 20:25:13 +00:00
});
});
2016-11-14 23:18:32 +00:00
2017-08-27 13:24:17 +00:00
tap.test('should test all Dockerfiles', async () => {
2019-08-29 18:26:23 +00:00
const npmciInstance = new npmci.Npmci();
2023-08-24 15:25:55 +00:00
await npmciInstance.start();
2019-08-29 18:26:23 +00:00
return npmciInstance.dockerManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['docker', 'test'],
2018-04-04 20:25:13 +00:00
});
});
2017-08-27 13:24:17 +00:00
tap.test('should test dockerfiles', async () => {
2019-08-29 18:26:23 +00:00
const npmciInstance = new npmci.Npmci();
2023-08-24 15:25:55 +00:00
await npmciInstance.start();
2019-08-29 18:26:23 +00:00
return npmciInstance.dockerManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['docker', 'test'],
2018-04-04 20:25:13 +00:00
});
});
2017-08-27 13:24:17 +00:00
tap.test('should login docker daemon', async () => {
2019-08-29 18:26:23 +00:00
const npmciInstance = new npmci.Npmci();
2023-08-24 15:25:55 +00:00
await npmciInstance.start();
2019-08-29 18:26:23 +00:00
return npmciInstance.dockerManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['docker', 'login'],
2018-04-04 20:25:13 +00:00
});
});
2017-08-27 13:24:17 +00:00
// ===
// SSH
// ===
tap.test('should prepare SSH keys', async () => {
const npmciModSsh = await import('../ts/mod_ssh/index.js');
2017-08-27 13:24:17 +00:00
return await npmciModSsh.handleCli({
2021-05-14 18:11:12 +00:00
_: ['ssh', 'prepare'],
2018-04-04 20:25:13 +00:00
});
});
2017-08-27 13:24:17 +00:00
// ====
// node
// ====
tap.test('should install a certain version of node', async () => {
2019-08-29 18:26:23 +00:00
const npmciInstance = new npmci.Npmci();
2023-08-24 15:25:55 +00:00
await npmciInstance.start();
2019-08-29 18:26:23 +00:00
await npmciInstance.nodejsManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['node', 'install', 'stable'],
2018-04-04 20:25:13 +00:00
});
2019-08-29 18:26:23 +00:00
await npmciInstance.nodejsManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['node', 'install', 'lts'],
2018-04-04 20:25:13 +00:00
});
2019-08-29 18:26:23 +00:00
await npmciInstance.nodejsManager.handleCli({
2021-05-14 18:11:12 +00:00
_: ['node', 'install', 'legacy'],
2018-04-04 20:25:13 +00:00
});
});
2017-08-27 13:24:17 +00:00
// make sure test ends all right
tap.test('reset paths', async () => {
process.cwd = () => {
2018-04-04 20:25:13 +00:00
return path.join(__dirname, '../');
};
});
2017-05-15 12:19:56 +00:00
2018-04-04 20:25:13 +00:00
tap.start();