Skip to content

Commit

Permalink
fix: e2e tests and CI pipelline
Browse files Browse the repository at this point in the history
Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com>
  • Loading branch information
leninmehedy committed Jan 22, 2024
1 parent 90b0f4d commit 1a5981b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/zxc-fsnetman-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ jobs:
run: |
npm i
npm link
fsnetman init -d ../charts # use the charts directory for all subsequent commands
fsnetman cluster create
kind create cluster -n fst
kubectl create ns fst-e2e
fsnetman init -d ../charts --namespace fst-e2e
fsnetman cluster setup --cert-manager --cert-manager-crds
fsnetman chart install --enable-tls --self-signed --enable-hedera-explorer-tls
fsnetman chart install --enable-tls --self-signed --enable-hedera-explorer-tls --acme-cluster-issuer
npm run test-e2e
- name: Output logs
Expand Down
4 changes: 2 additions & 2 deletions fullstack-network-manager/src/commands/flags.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const namespace = {
name: 'namespace',
definition: {
describe: 'Namespace',
default: constants.DEFAULT_NAMESPACE,
default: '',
alias: 'n',
type: 'string'
}
Expand Down Expand Up @@ -165,7 +165,7 @@ export const nodeIDs = {
name: 'node-ids',
definition: {
describe: 'Comma separated node IDs (empty means all nodes)',
default: '',
default: 'node0,node1,node2',
alias: 'i',
type: 'string'
}
Expand Down
5 changes: 4 additions & 1 deletion fullstack-network-manager/src/commands/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export class InitCommand extends BaseCommand {
return {
command: 'init',
desc: 'Perform dependency checks and initialize local environment',
builder: y => flags.setCommandFlags(y, flags.chartDirectory),
builder: y => {
flags.setCommandFlags(y, flags.chartDirectory)
flags.setCommandFlags(y, flags.namespace)
},
handler: (argv) => {
initCmd.init(argv).then(r => {
if (!r) process.exit(1)
Expand Down
4 changes: 2 additions & 2 deletions fullstack-network-manager/src/core/config_manager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ export class ConfigManager {
* Return the value of the given flag
*
* @param flag flag object
* @return {*|string} value of the flag or empty string if flag value is not available
* @return {*|string} value of the flag or undefined if flag value is not available
*/
getFlag (flag) {
if (this.config.flags[flag.name] !== undefined) {
return this.config.flags[flag.name]
}

return ''
return undefined
}

/**
Expand Down
4 changes: 3 additions & 1 deletion fullstack-network-manager/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export function main (argv) {
const context = kubeConfig.getContextObject(kubeConfig.getCurrentContext())
const cluster = kubeConfig.getCurrentCluster()
configManager.setFlag(flags.clusterName, cluster.name)
configManager.setFlag(flags.namespace, context.namespace)
if (context.namespace) {
configManager.setFlag(flags.namespace, context.namespace)
}
configManager.persist()

logger.showUser(chalk.green('\n-------------------------------------------------------------------------------'))
Expand Down
17 changes: 13 additions & 4 deletions fullstack-network-manager/test/e2e/core/kubectl_e2e.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('Kubectl', () => {
const testLogger = logging.NewLogger('debug')
const configManager = new ConfigManager(testLogger)
const kubectl = new Kubectl2(configManager, testLogger)
// configManager.load({namespace: constants.NAMESPACE_NAME})

it('should be able to list clusters', async () => {
const clusters = await kubectl.getClusters()
Expand All @@ -23,7 +22,7 @@ describe('Kubectl', () => {
it('should be able to list namespaces', async () => {
const namespaces = await kubectl.getNamespaces()
expect(namespaces).not.toHaveLength(0)
expect(namespaces).toContain(constants.NAMESPACE_NAME)
expect(namespaces).toContain(constants.DEFAULT_NAMESPACE)
})

it('should be able to list contexts', async () => {
Expand Down Expand Up @@ -112,8 +111,18 @@ describe('Kubectl', () => {

it('should be able to cat a log file inside the container', async () => {
const podName = Templates.renderNetworkPodName('node0')
const logfilePath = `${constants.HEDERA_HAPI_PATH}/logs/hgcaa.log`
const output = await kubectl.execContainer(podName, constants.ROOT_CONTAINER, ['tail', '-10', logfilePath])
const containerName = constants.ROOT_CONTAINER
const testFileName = 'test.txt'
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kubectl-'))
const tmpFile = path.join(tmpDir, testFileName)
const destDir = constants.HEDERA_USER_HOME_DIR
const destPath = `${destDir}/${testFileName}`
fs.writeFileSync(tmpFile, 'TEST\nNow current platform status = ACTIVE')

await expect(kubectl.copyTo(podName, containerName, tmpFile, destDir)).resolves.toBeTruthy()
const output = await kubectl.execContainer(podName, containerName, ['tail', '-10', destPath])
expect(output.indexOf('Now current platform status = ACTIVE')).toBeGreaterThan(0)

fs.rmdirSync(tmpDir, { recursive: true })
})
})

0 comments on commit 1a5981b

Please sign in to comment.