// SPDX-License-Identifier: Apache-2.0
import { BaseCommandTest } from './base-command-test.js';
import { main } from '../../../../src/index.js';
import { InjectTokens } from '../../../../src/core/dependency-injection/inject-tokens.js';
import { Templates } from '../../../../src/core/templates.js';
import { Duration } from '../../../../src/core/time/duration.js';
import { container } from 'tsyringe-neo';
import { expect } from 'chai';
import { Flags } from '../../../../src/commands/flags.js';
export class NetworkTest extends BaseCommandTest {
    static soloNetworkDeployArgv(testName, deployment, enableLocalBuildPathTesting, localBuildReleaseTag, loadBalancerEnabled) {
        const { newArgv, argvPushGlobalFlags, optionFromFlag } = NetworkTest;
        const argv = newArgv();
        argv.push('network', 'deploy', optionFromFlag(Flags.deployment), deployment);
        // have to enable load balancer to resolve cross cluster in multi-cluster
        if (loadBalancerEnabled) {
            argv.push(optionFromFlag(Flags.loadBalancerEnabled));
        }
        if (enableLocalBuildPathTesting) {
            argv.push(optionFromFlag(Flags.releaseTag), localBuildReleaseTag);
        }
        argvPushGlobalFlags(argv, testName, true, true);
        return argv;
    }
    static deploy(options) {
        const { testName, deployment, namespace, contexts, enableLocalBuildPathTesting, localBuildReleaseTag, loadBalancerEnabled, } = options;
        const { soloNetworkDeployArgv } = NetworkTest;
        it(`${testName}: network deploy`, async () => {
            await main(soloNetworkDeployArgv(testName, deployment, enableLocalBuildPathTesting, localBuildReleaseTag, loadBalancerEnabled));
            const k8Factory = container.resolve(InjectTokens.K8Factory);
            for (const [index, context_] of contexts.entries()) {
                const k8 = k8Factory.getK8(context_);
                expect(await k8.namespaces().has(namespace), `namespace ${namespace} should exist in ${context}`).to.be.true;
                const pods = await k8.pods().list(namespace, ['solo.hedera.com/type=network-node']);
                expect(pods).to.have.lengthOf(1);
                const nodeAlias = Templates.renderNodeAliasFromNumber(index + 1);
                expect(pods[0].labels['solo.hedera.com/node-name']).to.equal(nodeAlias);
            }
        }).timeout(Duration.ofMinutes(5).toMillis());
    }
    static soloNetworkDestroyArgv(testName, deployment) {
        const { newArgv, argvPushGlobalFlags, optionFromFlag } = NetworkTest;
        const argv = newArgv();
        argv.push('network', 'destroy', optionFromFlag(Flags.deployment), deployment);
        argvPushGlobalFlags(argv, testName, false, true);
        return argv;
    }
    static destroy(options) {
        const { testName, deployment } = options;
        const { soloNetworkDestroyArgv } = NetworkTest;
        it(`${testName}: network destroy`, async () => {
            await main(soloNetworkDestroyArgv(testName, deployment));
        });
    }
}
//# sourceMappingURL=network-test.js.map