Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): start Kind cluster on demand if not having a kube config errors #624

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/test_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import { ROOT_CONTAINER } from '../src/core/constants.mjs'
import crypto from 'crypto'
import { AccountCommand } from '../src/commands/account.mjs'
import { FullstackTestingError } from '../src/core/errors.mjs'
import { execSync } from 'child_process'

export const testLogger = logging.NewLogger('debug', true)
export const TEST_CLUSTER = 'solo-e2e'
Expand Down Expand Up @@ -360,3 +362,27 @@
const keyString = keyBytes.toString()
keyHashMap.set(privateKeyFileName, crypto.createHash('sha256').update(keyString).digest('base64'))
}

/**
* @param {ConfigManager} configManager
* @returns {K8}
*/
export function getK8Instance (configManager) {
try {
return new K8(configManager, testLogger)
jeromy-cannon marked this conversation as resolved.
Show resolved Hide resolved
// TODO: return a mock without running the init within constructor after we convert to Mocha, Jest ESModule mocks are broke.
} catch (e) {
if (!(e instanceof FullstackTestingError)) {
throw e

Check warning on line 376 in test/test_util.js

View check run for this annotation

Codecov / codecov/patch

test/test_util.js#L376

Added line #L376 was not covered by tests
}

// Set envs
process.env.SOLO_CLUSTER_NAME = 'solo-e2e'
process.env.SOLO_NAMESPACE = 'solo-e2e'
process.env.SOLO_CLUSTER_SETUP_NAMESPACE = 'fullstack-setup'

Check warning on line 382 in test/test_util.js

View check run for this annotation

Codecov / codecov/patch

test/test_util.js#L380-L382

Added lines #L380 - L382 were not covered by tests

// Create cluster
execSync(`kind create cluster --name "${process.env.SOLO_CLUSTER_NAME}"`, { stdio: 'inherit' })
return new K8(configManager, testLogger)

Check warning on line 386 in test/test_util.js

View check run for this annotation

Codecov / codecov/patch

test/test_util.js#L385-L386

Added lines #L385 - L386 were not covered by tests
}
}
5 changes: 3 additions & 2 deletions test/unit/commands/base.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
constants
} from '../../../src/core/index.mjs'
import { BaseCommand } from '../../../src/commands/base.mjs'
import { K8 } from '../../../src/core/k8.mjs'
import * as flags from '../../../src/commands/flags.mjs'
import { getK8Instance } from '../../test_util.js'

const testLogger = logging.NewLogger('debug', true)

Expand All @@ -40,7 +40,8 @@ describe('BaseCommand', () => {
const helmDepManager = new HelmDependencyManager(downloader, zippy, testLogger)
const depManagerMap = new Map().set(constants.HELM, helmDepManager)
const depManager = new DependencyManager(testLogger, depManagerMap)
const k8 = new K8(configManager, testLogger)

const k8 = getK8Instance(configManager)

const baseCmd = new BaseCommand({
logger: testLogger,
Expand Down
5 changes: 3 additions & 2 deletions test/unit/commands/init.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
KeyManager,
logging, PackageDownloader, Zippy
} from '../../../src/core/index.mjs'
import { K8 } from '../../../src/core/k8.mjs'
import { getK8Instance } from '../../test_util.js'

const testLogger = logging.NewLogger('debug', true)
describe('InitCommand', () => {
Expand All @@ -47,7 +47,8 @@ describe('InitCommand', () => {
const configManager = new ConfigManager(testLogger)

const keyManager = new KeyManager(testLogger)
const k8 = new K8(configManager, testLogger)

const k8 = getK8Instance(configManager)

const initCmd = new InitCommand({
logger: testLogger,
Expand Down
5 changes: 4 additions & 1 deletion test/unit/core/platform_installer.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ import {
MissingArgumentError
} from '../../../src/core/errors.mjs'
import { AccountManager } from '../../../src/core/account_manager.mjs'
import { getK8Instance } from '../../test_util.js'
describe('PackageInstaller', () => {
const testLogger = core.logging.NewLogger('debug', true)
const configManager = new ConfigManager(testLogger)
const k8 = new core.K8(configManager, testLogger)

const k8 = getK8Instance(configManager)

const accountManager = new AccountManager(testLogger, k8)
const installer = new PlatformInstaller(testLogger, k8, configManager, accountManager)

Expand Down
Loading