Skip to content

Commit 0d0d158

Browse files
committed
Add unit tests for GetMCRegistryConf and IsDisconnectedOCP
Add comprehensive unit tests for the disconnected environment detection and registry configuration retrieval functions in the util package. Tests cover: - IsNoMatchError: Detects both 'no matches for kind' (real API server) and 'no kind is registered' (fake client) errors - IsDisconnectedOCP: Tests with ICSP, IDMS, both, empty lists, and missing CRDs (graceful degradation) - GetMCRegistryConf: Tests successful retrieval, missing MachineConfig, missing CRD, invalid ignition format, missing base64 prefix, and invalid base64 content - Full scenario tests for disconnected environments and non-OpenShift cluster graceful degradation The IsNoMatchError function is updated to also detect 'no kind is registered' errors which occur in functional tests where the fake client behaves differently than a real Kubernetes API server. The MachineConfigNotFound test verifies that IsNotFound errors are NOT treated as IsNoMatchError - when the CRD exists but the resource doesn't, this should be an error (not a warning), indicating misconfiguration.
1 parent 7c45eb0 commit 0d0d158

File tree

2 files changed

+505
-2
lines changed

2 files changed

+505
-2
lines changed

internal/dataplane/util/image_registry.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,13 @@ func IsDisconnectedOCP(ctx context.Context, helper *helper.Helper) (bool, error)
8181

8282
// IsNoMatchError checks if the error indicates that a CRD/resource type doesn't exist
8383
func IsNoMatchError(err error) bool {
84-
// Check for "no matches for kind" type errors which indicate the CRD doesn't exist
85-
return strings.Contains(err.Error(), "no matches for kind")
84+
errStr := err.Error()
85+
// Check for "no matches for kind" type errors which indicate the CRD doesn't exist.
86+
// Also check for "no kind is registered" which occurs when the type isn't in the scheme.
87+
// This is specifically needed for functional tests where the fake client returns a different
88+
// error type than a real Kubernetes API server when CRDs are not installed.
89+
return strings.Contains(errStr, "no matches for kind") ||
90+
strings.Contains(errStr, "no kind is registered")
8691
}
8792

8893
// GetMCRegistryConf - will unmarshal the MachineConfig ignition file the machineConfigIgnition object.

0 commit comments

Comments
 (0)