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

test: add cluster command end to end test #127

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
dca07a8
Save
JeffreyDallas Mar 4, 2024
b2f32ed
save
JeffreyDallas Mar 4, 2024
4bc9e3c
add save
JeffreyDallas Mar 5, 2024
9633cf6
Merge branch 'main' into add_e2e_test
JeffreyDallas Mar 5, 2024
ae3fa7b
save
JeffreyDallas Mar 5, 2024
a963171
save
JeffreyDallas Mar 5, 2024
6f828f1
save
JeffreyDallas Mar 5, 2024
2b0e7b7
typo
JeffreyDallas Mar 5, 2024
45eccf8
save
JeffreyDallas Mar 5, 2024
46ce96e
save
JeffreyDallas Mar 5, 2024
605d34f
save
JeffreyDallas Mar 5, 2024
f38777c
save
JeffreyDallas Mar 5, 2024
ea4fd28
save
JeffreyDallas Mar 5, 2024
18b55b6
save
JeffreyDallas Mar 6, 2024
eb36f50
test deleted
JeffreyDallas Mar 6, 2024
2bc1641
add
JeffreyDallas Mar 6, 2024
4cc48a7
fix clusternamesetup
JeffreyDallas Mar 6, 2024
61a683b
Merge commit 'e4bd1efb12454f3fa027914ace5dc70f61e5cbeb' into add_e2e_…
JeffreyDallas Mar 6, 2024
65fec88
Merge commit 'd7c3b479adf55117afd24614f68217f513894bfe' into add_e2e_…
JeffreyDallas Mar 8, 2024
d0cd007
save
JeffreyDallas Mar 8, 2024
fbbca43
save
JeffreyDallas Mar 8, 2024
454aae7
save
JeffreyDallas Mar 8, 2024
3f6945d
save
JeffreyDallas Mar 8, 2024
5610e19
save
JeffreyDallas Mar 8, 2024
ced3330
save
JeffreyDallas Mar 8, 2024
9718c6d
test
JeffreyDallas Mar 8, 2024
56fe943
save
JeffreyDallas Mar 13, 2024
932b72d
Merge commit 'b1d1e2d9ffcdc8de379e47e78b0e063cb820a1a7' into add_e2e_…
JeffreyDallas Mar 19, 2024
07fdbad
use bootstrap patten
JeffreyDallas Mar 19, 2024
d2a22bc
Merge branch 'main' into add_e2e_test
JeffreyDallas Mar 19, 2024
4d0cbce
change with bootstrap network
JeffreyDallas Mar 20, 2024
dbe4638
code check
JeffreyDallas Mar 20, 2024
38ecb10
more code check
JeffreyDallas Mar 20, 2024
daeba97
test: refactor bootstrap network method for code reusability
leninmehedy Mar 21, 2024
e26ff97
test: fix cluster command e2e test
leninmehedy Mar 21, 2024
98c2aa7
Merge branch 'main' into add_e2e_test
leninmehedy Mar 21, 2024
5a70af9
doc: fix comment for clarity
leninmehedy Mar 21, 2024
3b84ae4
improve test coverage
JeffreyDallas Mar 21, 2024
fcfb1f2
test: check for different chart as cluster command deletes the cluste…
leninmehedy Mar 22, 2024
ffdac9c
Merge commit 'a27d1d2277d3807388579e8f3a14f11715e155cf' into add_e2e_…
JeffreyDallas Mar 22, 2024
c1d5d05
Add assertion
JeffreyDallas Mar 22, 2024
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
3 changes: 3 additions & 0 deletions src/commands/cluster.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export class ClusterCommand extends BaseCommand {
}

ctx.isChartInstalled = await this.chartManager.isChartInstalled(ctx.config.clusterSetupNamespace, constants.FULLSTACK_CLUSTER_SETUP_CHART)
if (!ctx.isChartInstalled) {
throw new FullstackTestingError('No chart found for the cluster')
}
}
},
{
Expand Down
163 changes: 163 additions & 0 deletions test/e2e/commands/cluster.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/**
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the ""License"");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an ""AS IS"" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {
afterAll,
afterEach,
beforeEach,
describe,
expect,
it
} from '@jest/globals'
import {
bootstrapTestVariables,
getDefaultArgv,
TEST_CLUSTER
} from '../../test_util.js'
import {
constants
} from '../../../src/core/index.mjs'
import { flags } from '../../../src/commands/index.mjs'
import { sleep } from '../../../src/core/helpers.mjs'
import * as version from '../../../version.mjs'

describe('ClusterCommand', () => {
const testName = 'cluster-cmd-e2e'
const namespace = testName
const argv = getDefaultArgv()
argv[flags.namespace.name] = namespace
argv[flags.releaseTag.name] = 'v0.47.0-alpha.0'
argv[flags.keyFormat.name] = constants.KEY_FORMAT_PEM
argv[flags.nodeIDs.name] = 'node0,node1,node2'
argv[flags.generateGossipKeys.name] = true
argv[flags.generateTlsKeys.name] = true
argv[flags.clusterName.name] = TEST_CLUSTER
argv[flags.fstChartVersion.name] = version.FST_CHART_VERSION
argv[flags.force.name] = true

const bootstrapResp = bootstrapTestVariables(testName, argv)
const k8 = bootstrapResp.opts.k8
const accountManager = bootstrapResp.opts.accountManager
const configManager = bootstrapResp.opts.configManager
const chartManager = bootstrapResp.opts.chartManager

const clusterCmd = bootstrapResp.cmd.clusterCmd

afterAll(async () => {
await k8.deleteNamespace(namespace)
await accountManager.close()
})

beforeEach(() => {
configManager.reset()
})

afterEach(async () => {
await sleep(5) // give a few ticks so that connections can close
})

it('should cleanup existing deployment', async () => {
jeromy-cannon marked this conversation as resolved.
Show resolved Hide resolved
if (await chartManager.isChartInstalled(constants.FULLSTACK_SETUP_NAMESPACE, constants.FULLSTACK_CLUSTER_SETUP_CHART)) {
expect.assertions(1)
try {
await expect(clusterCmd.reset(argv)).resolves.toBeTruthy()
} catch (e) {
clusterCmd.logger.showUserError(e)
expect(e).toBeNull()
}
}
}, 60000)

it('solo cluster setup should fail with invalid cluster name', async () => {
argv[flags.clusterSetupNamespace.name] = 'INVALID'
configManager.update(argv, true)

expect.assertions(1)
try {
await expect(clusterCmd.setup(argv)).rejects.toThrowError('Error on cluster setup')
} catch (e) {
clusterCmd.logger.showUserError(e)
expect(e).toBeNull()
}
}, 60000)

it('solo cluster setup should work with valid args', async () => {
argv[flags.clusterSetupNamespace.name] = namespace
configManager.update(argv, true)

expect.assertions(1)
try {
await expect(clusterCmd.setup(argv)).resolves.toBeTruthy()
} catch (e) {
clusterCmd.logger.showUserError(e)
expect(e).toBeNull()
}
}, 60000)

it('function getClusterInfo should return true', async () => {
try {
await expect(clusterCmd.getClusterInfo()).resolves.toBeTruthy()
} catch (e) {
clusterCmd.logger.showUserError(e)
expect(e).toBeNull()
}
}, 60000)

it('function showClusterList should return right true', async () => {
try {
await expect(clusterCmd.showClusterList()).resolves.toBeTruthy()
} catch (e) {
clusterCmd.logger.showUserError(e)
expect(e).toBeNull()
}
}, 60000)

it('function showInstalledChartList should return right true', async () => {
try {
await expect(clusterCmd.showInstalledChartList()).resolves.toBeUndefined()
} catch (e) {
clusterCmd.logger.showUserError(e)
expect(e).toBeNull()
}
}, 60000)

// helm list would return an empty list if given invalid namespace
it('solo cluster reset should fail with invalid cluster name', async () => {
argv[flags.clusterSetupNamespace.name] = 'INVALID'
configManager.update(argv, true)

expect.assertions(1)
try {
await expect(clusterCmd.reset(argv)).rejects.toThrowError('Error on cluster reset')
} catch (e) {
clusterCmd.logger.showUserError(e)
expect(e).toBeNull()
}
}, 60000)

it('solo cluster reset should work with valid args', async () => {
argv[flags.clusterSetupNamespace.name] = namespace
configManager.update(argv, true)

expect.assertions(1)
try {
await expect(clusterCmd.reset(argv)).resolves.toBeTruthy()
} catch (e) {
clusterCmd.logger.showUserError(e)
expect(e).toBeNull()
}
}, 60000)
})
File renamed without changes.
4 changes: 2 additions & 2 deletions test/e2e/core/chart_manager.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ describe('ChartManager', () => {
})

it('should be able to check if a chart is installed', async () => {
const ns = configManager.getFlag(flags.clusterSetupNamespace)
const ns = configManager.getFlag(flags.namespace)
expect(ns).not.toBeNull()
const isInstalled = await chartManager.isChartInstalled(ns, constants.FULLSTACK_CLUSTER_SETUP_CHART)
const isInstalled = await chartManager.isChartInstalled(ns, constants.FULLSTACK_DEPLOYMENT_CHART)
expect(isInstalled).toBeTruthy()
})
})
43 changes: 37 additions & 6 deletions test/test_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import { sleep } from '../src/core/helpers.mjs'
import {
ChartManager,
ConfigManager,
constants, Helm, K8,
constants,
Helm,
K8,
KeyManager,
logging,
PackageDownloader,
Expand Down Expand Up @@ -79,7 +81,7 @@ export function getDefaultArgv () {
}

/**
* Bootstrap network in a given namespace
* Initialize common test variables
*
* @param testName test name
* @param argv argv for commands
Expand All @@ -89,14 +91,14 @@ export function getDefaultArgv () {
* @param networkCmdArg an instance of command/NetworkCommand
* @param nodeCmdArg an instance of command/NodeCommand
*/
export function bootstrapNetwork (testName, argv,
export function bootstrapTestVariables (testName, argv,
k8Arg = null,
initCmdArg = null,
clusterCmdArg = null,
networkCmdArg = null,
nodeCmdArg = null
) {
const namespace = argv[flags.namespace.name] || 'bootstrap'
const namespace = argv[flags.namespace.name] || 'bootstrap-ns'
const cacheDir = argv[flags.cacheDir.name] || getTestCacheDir(testName)
const configManager = getTestConfigManager(`${testName}-solo.config`)
configManager.update(argv, true)
Expand Down Expand Up @@ -132,7 +134,8 @@ export function bootstrapNetwork (testName, argv,
const clusterCmd = clusterCmdArg || new ClusterCommand(opts)
const networkCmd = networkCmdArg || new NetworkCommand(opts)
const nodeCmd = nodeCmdArg || new NodeCommand(opts)
const bootstrapResp = {
return {
namespace,
opts,
cmd: {
initCmd,
Expand All @@ -141,6 +144,34 @@ export function bootstrapNetwork (testName, argv,
nodeCmd
}
}
}

/**
* Bootstrap network in a given namespace
*
* @param testName test name
* @param argv argv for commands
* @param k8Arg an instance of core/K8
* @param initCmdArg an instance of command/InitCommand
* @param clusterCmdArg an instance of command/ClusterCommand
* @param networkCmdArg an instance of command/NetworkCommand
* @param nodeCmdArg an instance of command/NodeCommand
*/
export function bootstrapNetwork (testName, argv,
k8Arg = null,
initCmdArg = null,
clusterCmdArg = null,
networkCmdArg = null,
nodeCmdArg = null
) {
const bootstrapResp = bootstrapTestVariables(testName, argv, k8Arg, initCmdArg, clusterCmdArg, networkCmdArg, nodeCmdArg)
const namespace = bootstrapResp.namespace
const initCmd = bootstrapResp.cmd.initCmd
const k8 = bootstrapResp.opts.k8
const clusterCmd = bootstrapResp.cmd.clusterCmd
const networkCmd = bootstrapResp.cmd.networkCmd
const nodeCmd = bootstrapResp.cmd.nodeCmd
const chartManager = bootstrapResp.opts.chartManager

describe(`Bootstrap network for test [release ${argv[flags.releaseTag.name]}, keyFormat: ${argv[flags.keyFormat.name]}]`, () => {
it('should cleanup previous deployment', async () => {
Expand All @@ -155,7 +186,7 @@ export function bootstrapNetwork (testName, argv,
}
}

if (!await k8.hasNamespace(constants.FULLSTACK_SETUP_NAMESPACE)) {
if (!await chartManager.isChartInstalled(constants.FULLSTACK_SETUP_NAMESPACE, constants.FULLSTACK_CLUSTER_SETUP_CHART)) {
await clusterCmd.setup(argv)
}
}, 60000)
Expand Down