@@ -2404,6 +2404,27 @@ func IsCapabilityEnabled(oc *CLI, cap configv1.ClusterVersionCapability) (bool,
2404
2404
return false , nil
2405
2405
}
2406
2406
2407
+ // AllCapabilitiesEnabled returns true if all of the given capabilities are enabled on the cluster.
2408
+ func AllCapabilitiesEnabled (oc * CLI , caps ... configv1.ClusterVersionCapability ) (bool , error ) {
2409
+ cv , err := oc .AdminConfigClient ().ConfigV1 ().ClusterVersions ().Get (context .Background (), "version" , metav1.GetOptions {})
2410
+ if err != nil {
2411
+ return false , err
2412
+ }
2413
+
2414
+ enabledCaps := make (map [configv1.ClusterVersionCapability ]struct {}, len (cv .Status .Capabilities .EnabledCapabilities ))
2415
+ for _ , c := range cv .Status .Capabilities .EnabledCapabilities {
2416
+ enabledCaps [c ] = struct {}{}
2417
+ }
2418
+
2419
+ for _ , c := range caps {
2420
+ if _ , found := enabledCaps [c ]; ! found {
2421
+ return false , nil
2422
+ }
2423
+ }
2424
+
2425
+ return true , nil
2426
+ }
2427
+
2407
2428
// SkipIfNotPlatform skip the test if supported platforms are not matched
2408
2429
func SkipIfNotPlatform (oc * CLI , platforms ... configv1.PlatformType ) {
2409
2430
var match bool
@@ -2420,6 +2441,15 @@ func SkipIfNotPlatform(oc *CLI, platforms ...configv1.PlatformType) {
2420
2441
}
2421
2442
}
2422
2443
2444
+ // SkipIfMissingCapabilities skips the test if any of the given cluster capabilities is not enabled.
2445
+ func SkipIfMissingCapabilities (oc * CLI , caps ... configv1.ClusterVersionCapability ) {
2446
+ enabled , err := AllCapabilitiesEnabled (oc , caps ... )
2447
+ o .Expect (err ).NotTo (o .HaveOccurred ())
2448
+ if ! enabled {
2449
+ g .Skip (fmt .Sprintf ("Skip this test scenario because not all of the following capabilities are enabled: %v" , caps ))
2450
+ }
2451
+ }
2452
+
2423
2453
// GetClusterRegion get the cluster's region
2424
2454
func GetClusterRegion (oc * CLI ) string {
2425
2455
region , err := oc .AsAdmin ().WithoutNamespace ().Run ("get" ).Args ("node" , `-ojsonpath={.items[].metadata.labels.topology\.kubernetes\.io/region}` ).Output ()
0 commit comments