"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const utils_1 = require("./utils");
(0, vitest_1.describe)('isDualStack', () => {
    const createMachineNetwork = (cidr) => ({ cidr, clusterId: 'test' });
    const createClusterNetwork = (cidr, hostPrefix) => ({
        cidr,
        hostPrefix,
        clusterId: 'test',
    });
    const createServiceNetwork = (cidr) => ({ cidr, clusterId: 'test' });
    (0, vitest_1.describe)('OCP < 4.12 (legacy behavior)', () => {
        (0, vitest_1.test)('returns true for valid dual stack with IPv4 primary', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [
                    createMachineNetwork('192.168.1.0/24'),
                    createMachineNetwork('2001:db8::/64'),
                ],
                clusterNetworks: [
                    createClusterNetwork('10.128.0.0/14', 23),
                    createClusterNetwork('fd01::/48', 64),
                ],
                serviceNetworks: [
                    createServiceNetwork('172.30.0.0/16'),
                    createServiceNetwork('fd02::/112'),
                ],
                openshiftVersion: '4.11',
            });
            (0, vitest_1.expect)(result).toBe(true);
        });
        (0, vitest_1.test)('returns false for IPv6 primary in OCP < 4.12', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [
                    createMachineNetwork('2001:db8::/64'),
                    createMachineNetwork('192.168.1.0/24'),
                ],
                clusterNetworks: [
                    createClusterNetwork('fd01::/48', 64),
                    createClusterNetwork('10.128.0.0/14', 23),
                ],
                serviceNetworks: [
                    createServiceNetwork('fd02::/112'),
                    createServiceNetwork('172.30.0.0/16'),
                ],
                openshiftVersion: '4.11',
            });
            (0, vitest_1.expect)(result).toBe(false);
        });
        (0, vitest_1.test)('returns false for single stack', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [createMachineNetwork('192.168.1.0/24')],
                clusterNetworks: [createClusterNetwork('10.128.0.0/14', 23)],
                serviceNetworks: [createServiceNetwork('172.30.0.0/16')],
                openshiftVersion: '4.11',
            });
            (0, vitest_1.expect)(result).toBe(false);
        });
        (0, vitest_1.test)('returns false for empty networks', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [],
                clusterNetworks: [],
                serviceNetworks: [],
                openshiftVersion: '4.11',
            });
            (0, vitest_1.expect)(result).toBe(false);
        });
    });
    (0, vitest_1.describe)('OCP >= 4.12 (new behavior)', () => {
        (0, vitest_1.test)('returns true for IPv4 primary and IPv6 secondary', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [
                    createMachineNetwork('192.168.1.0/24'),
                    createMachineNetwork('2001:db8::/64'),
                ],
                clusterNetworks: [
                    createClusterNetwork('10.128.0.0/14', 23),
                    createClusterNetwork('fd01::/48', 64),
                ],
                serviceNetworks: [
                    createServiceNetwork('172.30.0.0/16'),
                    createServiceNetwork('fd02::/112'),
                ],
                openshiftVersion: '4.12',
            });
            (0, vitest_1.expect)(result).toBe(true);
        });
        (0, vitest_1.test)('returns true for IPv6 primary and IPv4 secondary', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [
                    createMachineNetwork('2001:db8::/64'),
                    createMachineNetwork('192.168.1.0/24'),
                ],
                clusterNetworks: [
                    createClusterNetwork('fd01::/48', 64),
                    createClusterNetwork('10.128.0.0/14', 23),
                ],
                serviceNetworks: [
                    createServiceNetwork('fd02::/112'),
                    createServiceNetwork('172.30.0.0/16'),
                ],
                openshiftVersion: '4.12',
            });
            (0, vitest_1.expect)(result).toBe(true);
        });
        (0, vitest_1.test)('returns false for IPv6 primary and IPv6 secondary (not dual-stack)', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [
                    createMachineNetwork('2001:db8::/64'),
                    createMachineNetwork('2001:db9::/64'),
                ],
                clusterNetworks: [
                    createClusterNetwork('fd01::/48', 64),
                    createClusterNetwork('fd02::/48', 64),
                ],
                serviceNetworks: [createServiceNetwork('fd03::/112'), createServiceNetwork('fd04::/112')],
                openshiftVersion: '4.12',
            });
            (0, vitest_1.expect)(result).toBe(false);
        });
        (0, vitest_1.test)('returns false for IPv4 primary and IPv4 secondary (not dual-stack)', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [
                    createMachineNetwork('192.168.1.0/24'),
                    createMachineNetwork('10.0.0.0/24'),
                ],
                clusterNetworks: [
                    createClusterNetwork('10.128.0.0/14', 23),
                    createClusterNetwork('172.16.0.0/14', 23),
                ],
                serviceNetworks: [
                    createServiceNetwork('172.30.0.0/16'),
                    createServiceNetwork('172.31.0.0/16'),
                ],
                openshiftVersion: '4.12',
            });
            (0, vitest_1.expect)(result).toBe(false);
        });
        (0, vitest_1.test)('returns false for single stack', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [createMachineNetwork('192.168.1.0/24')],
                clusterNetworks: [createClusterNetwork('10.128.0.0/14', 23)],
                serviceNetworks: [createServiceNetwork('172.30.0.0/16')],
                openshiftVersion: '4.12',
            });
            (0, vitest_1.expect)(result).toBe(false);
        });
        (0, vitest_1.test)('returns false if any network type is not dual stack', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [
                    createMachineNetwork('192.168.1.0/24'),
                    createMachineNetwork('2001:db8::/64'),
                ],
                clusterNetworks: [createClusterNetwork('10.128.0.0/14', 23)], // Single stack
                serviceNetworks: [
                    createServiceNetwork('172.30.0.0/16'),
                    createServiceNetwork('fd02::/112'),
                ],
                openshiftVersion: '4.12',
            });
            (0, vitest_1.expect)(result).toBe(false);
        });
    });
    (0, vitest_1.describe)('no version specified (defaults to legacy behavior)', () => {
        (0, vitest_1.test)('returns true for IPv4 primary and IPv6 secondary', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [
                    createMachineNetwork('192.168.1.0/24'),
                    createMachineNetwork('2001:db8::/64'),
                ],
                clusterNetworks: [
                    createClusterNetwork('10.128.0.0/14', 23),
                    createClusterNetwork('fd01::/48', 64),
                ],
                serviceNetworks: [
                    createServiceNetwork('172.30.0.0/16'),
                    createServiceNetwork('fd02::/112'),
                ],
            });
            (0, vitest_1.expect)(result).toBe(true);
        });
        (0, vitest_1.test)('returns false for IPv6 primary when no version specified', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [
                    createMachineNetwork('2001:db8::/64'),
                    createMachineNetwork('192.168.1.0/24'),
                ],
                clusterNetworks: [
                    createClusterNetwork('fd01::/48', 64),
                    createClusterNetwork('10.128.0.0/14', 23),
                ],
                serviceNetworks: [
                    createServiceNetwork('fd02::/112'),
                    createServiceNetwork('172.30.0.0/16'),
                ],
            });
            (0, vitest_1.expect)(result).toBe(false);
        });
    });
    (0, vitest_1.describe)('edge cases', () => {
        (0, vitest_1.test)('handles undefined networks', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: undefined,
                clusterNetworks: undefined,
                serviceNetworks: undefined,
                openshiftVersion: '4.12',
            });
            (0, vitest_1.expect)(result).toBe(false);
        });
        (0, vitest_1.test)('handles networks with empty CIDRs', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [
                    { cidr: '', clusterId: 'test' },
                    { cidr: '', clusterId: 'test' },
                ],
                clusterNetworks: [
                    { cidr: '', hostPrefix: 23, clusterId: 'test' },
                    { cidr: '', hostPrefix: 64, clusterId: 'test' },
                ],
                serviceNetworks: [
                    { cidr: '', clusterId: 'test' },
                    { cidr: '', clusterId: 'test' },
                ],
                openshiftVersion: '4.12',
            });
            (0, vitest_1.expect)(result).toBe(false);
        });
        (0, vitest_1.test)('handles invalid CIDRs', () => {
            const result = (0, utils_1.isDualStack)({
                machineNetworks: [createMachineNetwork('invalid'), createMachineNetwork('also-invalid')],
                clusterNetworks: [
                    createClusterNetwork('invalid', 23),
                    createClusterNetwork('also-invalid', 64),
                ],
                serviceNetworks: [createServiceNetwork('invalid'), createServiceNetwork('also-invalid')],
                openshiftVersion: '4.12',
            });
            (0, vitest_1.expect)(result).toBe(false);
        });
    });
});
//# sourceMappingURL=utils.test.js.map