github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/pkg/conditional_spec.go (about) 1 // Copyright (c) 2021, 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 package pkg 4 5 import ( 6 "fmt" 7 8 "github.com/onsi/ginkgo/v2" 9 "github.com/verrazzano/verrazzano/pkg/k8sutil" 10 ) 11 12 // ConditionalCheckFunc Test function for conditional specs 13 type ConditionalCheckFunc func() (bool, error) 14 15 // ConditionalSpec Executes the specified test spec/func when the condition function passes without error 16 func ConditionalSpec(description string, skipMessage string, condition ConditionalCheckFunc, specFunc interface{}) { 17 checkPassed, err := condition() 18 if err != nil { 19 ginkgo.Fail(err.Error()) 20 } 21 // Only run the target test function when the minimum version criteria is met 22 if checkPassed { 23 ginkgo.It(description, specFunc) 24 } else { 25 Log(Info, fmt.Sprintf("Skipping spec '%s', %s", description, skipMessage)) 26 } 27 } 28 29 // MinVersionSpec Executes the specified test spec/func when the Verrazzano version meets the minimum specified version 30 func MinVersionSpec(description string, minVersion string, specFunc interface{}) { 31 ConditionalSpec(description, fmt.Sprintf("Min version not met: %s", minVersion), func() (bool, error) { 32 kubeconfigPath, err := k8sutil.GetKubeConfigLocation() 33 if err != nil { 34 Log(Error, fmt.Sprintf("Failed to get default kubeconfig path: %s", err.Error())) 35 return false, err 36 } 37 return IsVerrazzanoMinVersion(minVersion, kubeconfigPath) 38 }, specFunc) 39 }