// 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 { Flags } from '../../../../src/commands/flags.js';
import { container } from 'tsyringe-neo';
import { expect } from 'chai';
export class ClusterReferenceTest extends BaseCommandTest {
    static soloClusterReferenceConnectArgv(testName, clusterReference, context) {
        const { newArgv, optionFromFlag, argvPushGlobalFlags } = ClusterReferenceTest;
        const argv = newArgv();
        argv.push('cluster-ref', 'connect', optionFromFlag(Flags.clusterRef), clusterReference, optionFromFlag(Flags.context), context);
        argvPushGlobalFlags(argv, testName);
        return argv;
    }
    static connect(options) {
        const { testName, testLogger, clusterReferences, clusterReferenceNameArray, contexts } = options;
        const { soloClusterReferenceConnectArgv } = ClusterReferenceTest;
        it(`${testName}: solo cluster-ref connect`, async () => {
            testLogger.info(`${testName}: beginning solo cluster-ref connect`);
            for (const [clusterReferenceName, context] of clusterReferences.entries()) {
                await main(soloClusterReferenceConnectArgv(testName, clusterReferenceName, context));
            }
            const localConfig = container.resolve(InjectTokens.LocalConfigRuntimeState);
            const clusterReferencesActual = localConfig.configuration.clusterRefs;
            expect(clusterReferencesActual.get(clusterReferenceNameArray[0])?.toString()).to.equal(contexts[0]);
            expect(clusterReferencesActual.get(clusterReferenceNameArray[1])?.toString()).to.equal(contexts[1]);
            testLogger.info(`${testName}: finished solo cluster-ref connect`);
        });
    }
    static soloClusterReferenceSetup(testName, clusterReference) {
        const { newArgv, optionFromFlag, argvPushGlobalFlags } = ClusterReferenceTest;
        const argv = newArgv();
        argv.push('cluster-ref', 'setup', optionFromFlag(Flags.clusterRef), clusterReference);
        argvPushGlobalFlags(argv, testName, false, true);
        return argv;
    }
    static setup(options) {
        const { testName, testLogger, clusterReferenceNameArray } = options;
        const { soloClusterReferenceSetup } = ClusterReferenceTest;
        it(`${testName}: solo cluster-ref setup`, async () => {
            testLogger.info(`${testName}: beginning solo cluster-ref setup`);
            for (const clusterReferenceName of clusterReferenceNameArray) {
                await main(soloClusterReferenceSetup(testName, clusterReferenceName));
            }
            // TODO add some verification that the setup was successful
            testLogger.info(`${testName}: finishing solo cluster-ref setup`);
        });
    }
}
//# sourceMappingURL=cluster-reference-test.js.map