Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions tests/gather_aro.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bats
# Tests for collection-scripts/gather_aro
#
# NOTE: gather_aro does NOT source common.sh -- it is fully standalone.
# Detection uses: oc get clusters.aro.openshift.io --ignore-not-found=true

load test_helper

# =============================================================================
# Early-exit path (not ARO)
# =============================================================================

@test "gather_aro exits early when ARO CR is not found" {
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_ARO_OUTPUT=''
cd \"$SCRIPT_DIR\"
/bin/bash gather_aro 2>&1
"

assert_success
refute_output --partial "Collecting ARO Cluster Data"
refute_output --partial "MOCK sync called"
}

# =============================================================================
# Happy path (ARO detected)
# =============================================================================

@test "gather_aro collects data when ARO CR is found" {
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_ARO_OUTPUT='cluster'
cd \"$SCRIPT_DIR\"
/bin/bash gather_aro 2>&1
"

assert_success
assert_output --partial "INFO: Collecting ARO Cluster Data"
}

@test "gather_aro inspects all expected targets" {
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_ARO_OUTPUT='cluster'
export MOCK_OC_LOG_FILE=\"$TEST_TMPDIR/oc_calls.log\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_aro 2>&1
echo '---OC CALLS LOG---'
cat \"$TEST_TMPDIR/oc_calls.log\"
"

assert_success
# Verify all three inspect targets from the script
assert_output --partial "clusters.aro.openshift.io"
assert_output --partial "ns/openshift-azure-operator"
assert_output --partial "ns/openshift-azure-logging"
}

@test "gather_aro calls sync at end" {
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_ARO_OUTPUT='cluster'
cd \"$SCRIPT_DIR\"
/bin/bash gather_aro 2>&1
"

assert_success
assert_output --partial "MOCK sync called"
}

@test "gather_aro handles oc adm inspect failure gracefully" {
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_ARO_OUTPUT='cluster'
export MOCK_OC_INSPECT_EXIT_CODE=1
cd \"$SCRIPT_DIR\"
/bin/bash gather_aro 2>&1
"

assert_output --partial "Collecting ARO Cluster Data"
assert_output --partial "clusters.aro.openshift.io"
assert_output --partial "ns/openshift-azure-operator"
}
124 changes: 124 additions & 0 deletions tests/gather_ingress_node_firewall.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/usr/bin/env bats
# Tests for collection-scripts/gather_ingress_node_firewall

load test_helper

# =============================================================================
# CRD inspection tests
# =============================================================================

@test "gather_ingress_node_firewall inspects all CRDs" {
local ns_fixture
ns_fixture=$(create_fixture "subs.txt" "openshift-ingress-node-firewall")
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$ns_fixture\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_ingress_node_firewall 2>&1
"

assert_success
# Namespaced CRDs
assert_output --partial "ingressnodefirewallconfigs"
assert_output --partial "ingressnodefirewallnodestates"
# Cluster-scoped CRDs
assert_output --partial "ingressnodefirewalls"
}

@test "namespaced CRDs are inspected with namespace flag" {
local ns_fixture
ns_fixture=$(create_fixture "subs.txt" "openshift-ingress-node-firewall")
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$ns_fixture\"
export MOCK_OC_LOG_FILE=\"$TEST_TMPDIR/oc_calls.log\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_ingress_node_firewall 2>&1
echo '---OC CALLS LOG---'
cat \"$TEST_TMPDIR/oc_calls.log\"
"

assert_success
# Namespaced CRDs should be inspected with -n <namespace>
assert_output --partial "-n openshift-ingress-node-firewall"
assert_output --partial "ingressnodefirewallconfigs"
}

# =============================================================================
# Main script behavior tests
# =============================================================================

@test "gather_ingress_node_firewall exits early when operator not found" {
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$FIXTURES_DIR/oc_outputs/subs_empty.txt\"
export BASE_COLLECTION_PATH=\"$TEST_TMPDIR/must-gather\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_ingress_node_firewall
"

assert_success
assert_output --partial "INFO"
assert_output --partial "not detected"
}

@test "gather_ingress_node_firewall completes successfully when operator is found" {
local ns_fixture
ns_fixture=$(create_fixture "subs.txt" "openshift-ingress-node-firewall")
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$ns_fixture\"
export BASE_COLLECTION_PATH=\"$TEST_TMPDIR/must-gather\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_ingress_node_firewall 2>&1
"

assert_success
refute_output --partial "not detected"
}

@test "gather_ingress_node_firewall inspects operator namespace" {
local ns_fixture
ns_fixture=$(create_fixture "subs.txt" "openshift-ingress-node-firewall")
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$ns_fixture\"
export MOCK_OC_LOG_FILE=\"$TEST_TMPDIR/oc_calls.log\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_ingress_node_firewall 2>&1
echo '---OC CALLS LOG---'
cat \"$TEST_TMPDIR/oc_calls.log\"
"

assert_success
assert_output --partial "ns/openshift-ingress-node-firewall"
}

@test "gather_ingress_node_firewall calls sync at end" {
local ns_fixture
ns_fixture=$(create_fixture "subs.txt" "openshift-ingress-node-firewall")
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$ns_fixture\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_ingress_node_firewall 2>&1
"

assert_success
assert_output --partial "MOCK sync called"
}

@test "gather_ingress_node_firewall handles oc adm inspect failure gracefully" {
local ns_fixture
ns_fixture=$(create_fixture "subs.txt" "openshift-ingress-node-firewall")
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$ns_fixture\"
export MOCK_OC_INSPECT_EXIT_CODE=1
cd \"$SCRIPT_DIR\"
/bin/bash gather_ingress_node_firewall 2>&1
"

assert_output --partial "ingressnodefirewallconfigs"
assert_output --partial "ingressnodefirewalls"
}
105 changes: 105 additions & 0 deletions tests/gather_nmstate.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env bats
# Tests for collection-scripts/gather_nmstate

load test_helper

# =============================================================================
# get_nmstate_crs() tests
# =============================================================================

@test "get_nmstate_crs inspects all NMState CRDs" {
local ns_fixture
ns_fixture=$(create_fixture "subs.txt" "openshift-nmstate")
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$ns_fixture\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_nmstate 2>&1
"

assert_success
assert_output --partial "nmstates"
assert_output --partial "nodenetworkconfigurationenactments"
assert_output --partial "nodenetworkconfigurationpolicies"
assert_output --partial "nodenetworkstates"
}

# =============================================================================
# Main script behavior tests
# =============================================================================

@test "gather_nmstate exits early when operator not found" {
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$FIXTURES_DIR/oc_outputs/subs_empty.txt\"
export BASE_COLLECTION_PATH=\"$TEST_TMPDIR/must-gather\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_nmstate
"

assert_success
assert_output --partial "INFO"
assert_output --partial "not detected"
}

@test "gather_nmstate completes successfully when operator is found" {
local ns_fixture
ns_fixture=$(create_fixture "subs.txt" "openshift-nmstate")
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$ns_fixture\"
export BASE_COLLECTION_PATH=\"$TEST_TMPDIR/must-gather\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_nmstate 2>&1
"

assert_success
refute_output --partial "not detected"
}

@test "gather_nmstate uses correct namespace from subscription" {
local ns_fixture
ns_fixture=$(create_fixture "subs.txt" "openshift-nmstate")
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$ns_fixture\"
export MOCK_OC_LOG_FILE=\"$TEST_TMPDIR/oc_calls.log\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_nmstate 2>&1
echo '---OC CALLS LOG---'
cat \"$TEST_TMPDIR/oc_calls.log\"
"

assert_success
assert_output --partial "adm inspect"
assert_output --partial "ns/openshift-nmstate"
}

@test "gather_nmstate calls sync at end" {
local ns_fixture
ns_fixture=$(create_fixture "subs.txt" "openshift-nmstate")
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$ns_fixture\"
cd \"$SCRIPT_DIR\"
/bin/bash gather_nmstate 2>&1
"

assert_success
assert_output --partial "MOCK sync called"
}

@test "gather_nmstate handles oc adm inspect failure gracefully" {
local ns_fixture
ns_fixture=$(create_fixture "subs.txt" "openshift-nmstate")
run bash -c "
export PATH=\"$BATS_TEST_DIRNAME/mocks:\$PATH\"
export MOCK_OC_OUTPUT=\"$ns_fixture\"
export MOCK_OC_INSPECT_EXIT_CODE=1
cd \"$SCRIPT_DIR\"
/bin/bash gather_nmstate 2>&1
"

assert_output --partial "nmstates"
assert_output --partial "nodenetworkstates"
}
Loading