From 28cd6d1b49b3e17a4d9117715e24fe839be38009 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Wed, 6 Nov 2024 16:53:21 +0100 Subject: [PATCH] fix(tests): Refactored test setup for consistency and isolated config initialization. --- changelog.md | 6 ++++ test/helpers/cloudlyfactory.ts | 63 +++++++++++++++++----------------- test/test.apiclient.ts | 2 +- ts/00_commitinfo_data.ts | 2 +- ts_web/00_commitinfo_data.ts | 2 +- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/changelog.md b/changelog.md index 53ea5a1..9e3aeb1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2024-11-06 - 4.3.7 - fix(tests) +Refactored test setup for consistency and isolated config initialization. + +- test/helpers/cloudlyfactory.ts: Test configuration setup was refactored to ensure consistent initialization of cloudly configuration across tests. +- test/test.apiclient.ts: Updated cloudlyApiClient test setup to use testCloudlyConfig for dynamic port allocation. + ## 2024-11-06 - 4.3.6 - fix(test) Enhance test helpers with dynamic Hetzner token retrieval. diff --git a/test/helpers/cloudlyfactory.ts b/test/helpers/cloudlyfactory.ts index d2b8f88..d70b458 100644 --- a/test/helpers/cloudlyfactory.ts +++ b/test/helpers/cloudlyfactory.ts @@ -5,37 +5,39 @@ import * as cloudly from '../../ts/index.js'; const stopFunctions: Array<() => Promise> = []; +const tapToolsNodeMod = await import('@push.rocks/tapbundle/node'); +const smartmongo = await tapToolsNodeMod.tapNodeTools.createSmartmongo(); +stopFunctions.push(async () => { + await smartmongo.stopAndDumpToDir('./.nogit/mongodump'); +}); +const smarts3 = await tapToolsNodeMod.tapNodeTools.createSmarts3(); +await smarts3.createBucket('cloudly-test'); +stopFunctions.push(async () => { + await smarts3.stop(); +}); + +export const testCloudlyConfig: cloudly.ICloudlyConfig = { + cfToken: await testQenv.getEnvVarOnDemand('CF_TOKEN'), + environment: 'integration', + letsEncryptEmail: 'test@serve.zone', + publicUrl: '127.0.0.1', + publicPort: '8080', + mongoDescriptor: await smartmongo.getMongoDescriptor(), + s3Descriptor: await smarts3.getS3Descriptor(), + sslMode: 'none', + ...(() => { + if (process.env.NPMCI_SECRET01) { + return { + hetznerToken: process.env.NPMCI_SECRET01, + }; + } + })(), +}; + export const createCloudly = async () => { - const tapToolsNodeMod = await import('@push.rocks/tapbundle/node'); - const smartmongo = await tapToolsNodeMod.tapNodeTools.createSmartmongo(); - stopFunctions.push(async () => { - await smartmongo.stopAndDumpToDir('./.nogit/mongodump'); - }); - const smarts3 = await tapToolsNodeMod.tapNodeTools.createSmarts3(); - await smarts3.createBucket('cloudly-test'); - stopFunctions.push(async () => { - await smarts3.stop(); - }); - const cloudlyConfig: cloudly.ICloudlyConfig = { - cfToken: await testQenv.getEnvVarOnDemand('CF_TOKEN'), - environment: 'integration', - letsEncryptEmail: 'test@serve.zone', - publicUrl: 'localhost', - publicPort: '8080', - mongoDescriptor: await smartmongo.getMongoDescriptor(), - s3Descriptor: await smarts3.getS3Descriptor(), - sslMode: 'none', - ...(() => { - if (process.env.NPMCI_SECRET01) { - return { - hetznerToken: process.env.NPMCI_SECRET01 - } - } - })() - }; - const cloudlyInstance = new cloudly.Cloudly(cloudlyConfig); + const cloudlyInstance = new cloudly.Cloudly(testCloudlyConfig); return cloudlyInstance; -} +}; export const stopCloudly = async () => { await Promise.all(stopFunctions.map((stopFunction) => stopFunction())); @@ -43,5 +45,4 @@ export const stopCloudly = async () => { export const getEnvVarOnDemand = async (envVarName: string) => { return testQenv.getEnvVarOnDemand(envVarName); -} - +}; diff --git a/test/test.apiclient.ts b/test/test.apiclient.ts index bc7cace..f8a17ee 100644 --- a/test/test.apiclient.ts +++ b/test/test.apiclient.ts @@ -33,7 +33,7 @@ tap.preTask('should create a new machine user for testing', async () => { tap.test('should create a new cloudlyApiClient', async () => { testClient = new cloudlyApiClient.CloudlyApiClient({ registerAs: 'api', - cloudlyUrl: `http://localhost:${await helpers.getEnvVarOnDemand('SERVEZONE_PORT')}`, + cloudlyUrl: `http://localhost:${helpers.testCloudlyConfig.publicPort}`, }); await testClient.start(); expect(testClient).toBeTruthy(); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 39e155f..f95befd 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/cloudly', - version: '4.3.6', + version: '4.3.7', description: 'A comprehensive tool for managing containerized applications across multiple cloud providers using Docker Swarmkit, featuring web, CLI, and API interfaces.' } diff --git a/ts_web/00_commitinfo_data.ts b/ts_web/00_commitinfo_data.ts index 39e155f..f95befd 100644 --- a/ts_web/00_commitinfo_data.ts +++ b/ts_web/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/cloudly', - version: '4.3.6', + version: '4.3.7', description: 'A comprehensive tool for managing containerized applications across multiple cloud providers using Docker Swarmkit, featuring web, CLI, and API interfaces.' }