|
| 1 | +/** |
| 2 | + * Copyright (C) 2024 Hedera Hashgraph, LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the ""License""); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an ""AS IS"" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
| 17 | +import { |
| 18 | + afterAll, |
| 19 | + afterEach, |
| 20 | + beforeEach, |
| 21 | + describe, |
| 22 | + expect, |
| 23 | + it |
| 24 | +} from '@jest/globals' |
| 25 | +import { |
| 26 | + bootstrapTestVariables, |
| 27 | + getDefaultArgv, |
| 28 | + TEST_CLUSTER |
| 29 | +} from '../../test_util.js' |
| 30 | +import { |
| 31 | + constants |
| 32 | +} from '../../../src/core/index.mjs' |
| 33 | +import { flags } from '../../../src/commands/index.mjs' |
| 34 | +import { sleep } from '../../../src/core/helpers.mjs' |
| 35 | +import * as version from '../../../version.mjs' |
| 36 | + |
| 37 | +describe('ClusterCommand', () => { |
| 38 | + const testName = 'cluster-cmd-e2e' |
| 39 | + const namespace = testName |
| 40 | + const argv = getDefaultArgv() |
| 41 | + argv[flags.namespace.name] = namespace |
| 42 | + argv[flags.releaseTag.name] = 'v0.47.0-alpha.0' |
| 43 | + argv[flags.keyFormat.name] = constants.KEY_FORMAT_PEM |
| 44 | + argv[flags.nodeIDs.name] = 'node0,node1,node2' |
| 45 | + argv[flags.generateGossipKeys.name] = true |
| 46 | + argv[flags.generateTlsKeys.name] = true |
| 47 | + argv[flags.clusterName.name] = TEST_CLUSTER |
| 48 | + argv[flags.fstChartVersion.name] = version.FST_CHART_VERSION |
| 49 | + argv[flags.force.name] = true |
| 50 | + |
| 51 | + const bootstrapResp = bootstrapTestVariables(testName, argv) |
| 52 | + const k8 = bootstrapResp.opts.k8 |
| 53 | + const accountManager = bootstrapResp.opts.accountManager |
| 54 | + const configManager = bootstrapResp.opts.configManager |
| 55 | + const chartManager = bootstrapResp.opts.chartManager |
| 56 | + |
| 57 | + const clusterCmd = bootstrapResp.cmd.clusterCmd |
| 58 | + |
| 59 | + afterAll(async () => { |
| 60 | + await k8.deleteNamespace(namespace) |
| 61 | + await accountManager.close() |
| 62 | + }) |
| 63 | + |
| 64 | + beforeEach(() => { |
| 65 | + configManager.reset() |
| 66 | + }) |
| 67 | + |
| 68 | + afterEach(async () => { |
| 69 | + await sleep(5) // give a few ticks so that connections can close |
| 70 | + }) |
| 71 | + |
| 72 | + it('should cleanup existing deployment', async () => { |
| 73 | + if (await chartManager.isChartInstalled(constants.FULLSTACK_SETUP_NAMESPACE, constants.FULLSTACK_CLUSTER_SETUP_CHART)) { |
| 74 | + expect.assertions(1) |
| 75 | + try { |
| 76 | + await expect(clusterCmd.reset(argv)).resolves.toBeTruthy() |
| 77 | + } catch (e) { |
| 78 | + clusterCmd.logger.showUserError(e) |
| 79 | + expect(e).toBeNull() |
| 80 | + } |
| 81 | + } |
| 82 | + }, 60000) |
| 83 | + |
| 84 | + it('solo cluster setup should fail with invalid cluster name', async () => { |
| 85 | + argv[flags.clusterSetupNamespace.name] = 'INVALID' |
| 86 | + configManager.update(argv, true) |
| 87 | + |
| 88 | + expect.assertions(1) |
| 89 | + try { |
| 90 | + await expect(clusterCmd.setup(argv)).rejects.toThrowError('Error on cluster setup') |
| 91 | + } catch (e) { |
| 92 | + clusterCmd.logger.showUserError(e) |
| 93 | + expect(e).toBeNull() |
| 94 | + } |
| 95 | + }, 60000) |
| 96 | + |
| 97 | + it('solo cluster setup should work with valid args', async () => { |
| 98 | + argv[flags.clusterSetupNamespace.name] = namespace |
| 99 | + configManager.update(argv, true) |
| 100 | + |
| 101 | + expect.assertions(1) |
| 102 | + try { |
| 103 | + await expect(clusterCmd.setup(argv)).resolves.toBeTruthy() |
| 104 | + } catch (e) { |
| 105 | + clusterCmd.logger.showUserError(e) |
| 106 | + expect(e).toBeNull() |
| 107 | + } |
| 108 | + }, 60000) |
| 109 | + |
| 110 | + it('function getClusterInfo should return true', async () => { |
| 111 | + try { |
| 112 | + await expect(clusterCmd.getClusterInfo()).resolves.toBeTruthy() |
| 113 | + } catch (e) { |
| 114 | + clusterCmd.logger.showUserError(e) |
| 115 | + expect(e).toBeNull() |
| 116 | + } |
| 117 | + }, 60000) |
| 118 | + |
| 119 | + it('function showClusterList should return right true', async () => { |
| 120 | + try { |
| 121 | + await expect(clusterCmd.showClusterList()).resolves.toBeTruthy() |
| 122 | + } catch (e) { |
| 123 | + clusterCmd.logger.showUserError(e) |
| 124 | + expect(e).toBeNull() |
| 125 | + } |
| 126 | + }, 60000) |
| 127 | + |
| 128 | + it('function showInstalledChartList should return right true', async () => { |
| 129 | + try { |
| 130 | + await expect(clusterCmd.showInstalledChartList()).resolves.toBeUndefined() |
| 131 | + } catch (e) { |
| 132 | + clusterCmd.logger.showUserError(e) |
| 133 | + expect(e).toBeNull() |
| 134 | + } |
| 135 | + }, 60000) |
| 136 | + |
| 137 | + // helm list would return an empty list if given invalid namespace |
| 138 | + it('solo cluster reset should fail with invalid cluster name', async () => { |
| 139 | + argv[flags.clusterSetupNamespace.name] = 'INVALID' |
| 140 | + configManager.update(argv, true) |
| 141 | + |
| 142 | + expect.assertions(1) |
| 143 | + try { |
| 144 | + await expect(clusterCmd.reset(argv)).rejects.toThrowError('Error on cluster reset') |
| 145 | + } catch (e) { |
| 146 | + clusterCmd.logger.showUserError(e) |
| 147 | + expect(e).toBeNull() |
| 148 | + } |
| 149 | + }, 60000) |
| 150 | + |
| 151 | + it('solo cluster reset should work with valid args', async () => { |
| 152 | + argv[flags.clusterSetupNamespace.name] = namespace |
| 153 | + configManager.update(argv, true) |
| 154 | + |
| 155 | + expect.assertions(1) |
| 156 | + try { |
| 157 | + await expect(clusterCmd.reset(argv)).resolves.toBeTruthy() |
| 158 | + } catch (e) { |
| 159 | + clusterCmd.logger.showUserError(e) |
| 160 | + expect(e).toBeNull() |
| 161 | + } |
| 162 | + }, 60000) |
| 163 | +}) |
0 commit comments