// SPDX-License-Identifier: Apache-2.0
import { describe, it } from 'mocha';
import { expect } from 'chai';
import { NodeCommandTasks } from '../../../../src/commands/node/tasks.js';
import { NamespaceName } from '../../../../src/types/namespace/namespace-name.js';
function createNodeCommandTasksWithPvcData(persistentVolumeClaimsByContext) {
    const nodeCommandTasks = Object.create(NodeCommandTasks.prototype);
    nodeCommandTasks.k8Factory = {
        getK8: (context) => ({
            pvcs: () => ({
                list: async () => persistentVolumeClaimsByContext[context] ?? [],
            }),
        }),
    };
    return nodeCommandTasks;
}
function invokeValidateNodePvcsForLocalBuildPath(nodeCommandTasks, contexts) {
    const validatorFunction = nodeCommandTasks.validateNodePvcsForLocalBuildPath;
    return validatorFunction.call(nodeCommandTasks, NamespaceName.of('solo'), contexts);
}
describe('NodeCommandTasks local build path PVC validation', () => {
    it('throws when local build path is used without node PVCs', async () => {
        const nodeCommandTasks = createNodeCommandTasksWithPvcData({
            'kind-solo': [],
        });
        await expect(invokeValidateNodePvcsForLocalBuildPath(nodeCommandTasks, ['kind-solo'])).to.be.rejectedWith('Redeploy the consensus network with --pvcs true');
    });
    it('passes when node PVCs exist for each context', async () => {
        const nodeCommandTasks = createNodeCommandTasksWithPvcData({
            'kind-alpha': ['data-node1'],
            'kind-beta': ['data-node2'],
        });
        await expect(invokeValidateNodePvcsForLocalBuildPath(nodeCommandTasks, ['kind-alpha', 'kind-beta'])).to.eventually
            .be.fulfilled;
    });
});
//# sourceMappingURL=local-build-path-pvc-validation.test.js.map