#!/usr/bin/env nu
# Tests for OCI Client Module

# Selective imports (ADR-025 Phase 3 Layer 2).
# utils/logger.nu does not exist — dangling import removed.
use lib_provisioning/oci/client.nu [
    build-artifact-ref get-oci-config is-oci-available test-oci-connection
]

# Test OCI configuration loading
export def test_oci_config [] {
    print "Testing OCI config loading..."

    let config = (get-oci-config)

    assert ($config.registry | is-not-empty) "Registry should be set"
    assert ($config.namespace | is-not-empty) "Namespace should be set"

    print "✅ OCI config test passed"
}

# Test artifact reference building
export def test_artifact_ref [] {
    print "Testing artifact reference building..."

    let ref = (build-artifact-ref "localhost:5000" "provisioning" "kubernetes" "1.28.0")

    assert ($ref == "localhost:5000/provisioning/kubernetes:1.28.0") "Artifact ref should match"

    print "✅ Artifact ref test passed"
}

# Test OCI availability check
export def test_oci_availability [] {
    print "Testing OCI availability..."

    let available = (is-oci-available)

    print $"   OCI available: ($available)"
    print "✅ OCI availability test passed"
}

# Test OCI connection
export def test_oci_connection [] {
    print "Testing OCI connection..."

    let result = (test-oci-connection)

    print $"   Registry reachable: ($result.registry_reachable)"
    print $"   Auth valid: ($result.authentication_valid)"
    print $"   Catalog accessible: ($result.catalog_accessible)"

    if ($result.errors | is-not-empty) {
        print "   Errors:"
        for error in $result.errors {
            print $"     • ($error)"
        }
    }

    print "✅ OCI connection test passed"
}

# Run all OCI client tests
export def main [] {
    print "🧪 Running OCI Client Tests"
    print ""

    test_oci_config
    test_artifact_ref
    test_oci_availability
    test_oci_connection

    print ""
    print "✅ All OCI client tests passed"
}
