diff --git a/cnf-certification-test/operator/suite.go b/cnf-certification-test/operator/suite.go index a4a47f561..09cd5b4c5 100644 --- a/cnf-certification-test/operator/suite.go +++ b/cnf-certification-test/operator/suite.go @@ -19,44 +19,64 @@ package operator import ( "strings" - "github.com/onsi/ginkgo/v2" "github.com/sirupsen/logrus" "github.com/test-network-function/cnf-certification-test/cnf-certification-test/common" "github.com/test-network-function/cnf-certification-test/cnf-certification-test/identifiers" "github.com/test-network-function/cnf-certification-test/cnf-certification-test/operator/phasecheck" + "github.com/test-network-function/cnf-certification-test/pkg/checksdb" "github.com/test-network-function/cnf-certification-test/pkg/provider" "github.com/test-network-function/cnf-certification-test/pkg/testhelper" "github.com/test-network-function/cnf-certification-test/pkg/tnf" ) -// All actual test code belongs below here. Utilities belong above. -var _ = ginkgo.Describe(common.OperatorTestKey, func() { - logrus.Debugf("Entering %s suite", common.OperatorTestKey) - var env provider.TestEnvironment - ginkgo.BeforeEach(func() { +var ( + env provider.TestEnvironment + + beforeEachFn = func(check *checksdb.Check) error { + logrus.Infof("Check %s: getting test environment.", check.ID) env = provider.GetTestEnvironment() - }) + return nil + } +) + +func LoadChecks() { + logrus.Debugf("Entering %s suite", common.OperatorTestKey) + + checksGroup := checksdb.NewChecksGroup(common.OperatorTestKey). + WithBeforeEachFn(beforeEachFn) testID, tags := identifiers.GetGinkgoTestIDAndLabels(identifiers.TestOperatorInstallStatusSucceededIdentifier) - ginkgo.It(testID, ginkgo.Label(tags...), func() { - testhelper.SkipIfEmptyAny(ginkgo.Skip, testhelper.NewSkipObject(env.Operators, "env.Operators")) - testOperatorInstallationPhaseSucceeded(&env) - }) + check := checksdb.NewCheck(testID, tags). + WithSkipCheckFn(testhelper.GetNoOperatorsSkipFn(&env)). + WithCheckFn(func(c *checksdb.Check) error { + testOperatorInstallationPhaseSucceeded(c, &env) + return nil + }) + + checksGroup.Add(check) testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestOperatorNoPrivileges) - ginkgo.It(testID, ginkgo.Label(tags...), func() { - testhelper.SkipIfEmptyAny(ginkgo.Skip, testhelper.NewSkipObject(env.Operators, "env.Operators")) - testOperatorInstallationWithoutPrivileges(&env) - }) + check = checksdb.NewCheck(testID, tags). + WithSkipCheckFn(testhelper.GetNoOperatorsSkipFn(&env)). + WithCheckFn(func(c *checksdb.Check) error { + testOperatorInstallationWithoutPrivileges(c, &env) + return nil + }) + + checksGroup.Add(check) testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestOperatorIsInstalledViaOLMIdentifier) - ginkgo.It(testID, ginkgo.Label(tags...), func() { - testhelper.SkipIfEmptyAny(ginkgo.Skip, testhelper.NewSkipObject(env.Operators, "env.Operators")) - testOperatorOlmSubscription(&env) - }) -}) + check = checksdb.NewCheck(testID, tags). + WithSkipCheckFn(testhelper.GetNoOperatorsSkipFn(&env)). + WithCheckFn(func(c *checksdb.Check) error { + testOperatorOlmSubscription(c, &env) + return nil + }) + + checksGroup.Add(check) +} -func testOperatorInstallationPhaseSucceeded(env *provider.TestEnvironment) { +func testOperatorInstallationPhaseSucceeded(check *checksdb.Check, env *provider.TestEnvironment) { var compliantObjects []*testhelper.ReportObject var nonCompliantObjects []*testhelper.ReportObject for i := range env.Operators { @@ -70,10 +90,10 @@ func testOperatorInstallationPhaseSucceeded(env *provider.TestEnvironment) { } } - testhelper.AddTestResultReason(compliantObjects, nonCompliantObjects, tnf.ClaimFilePrintf, ginkgo.Fail) + check.SetResult(compliantObjects, nonCompliantObjects) } -func testOperatorInstallationWithoutPrivileges(env *provider.TestEnvironment) { +func testOperatorInstallationWithoutPrivileges(check *checksdb.Check, env *provider.TestEnvironment) { var compliantObjects []*testhelper.ReportObject var nonCompliantObjects []*testhelper.ReportObject for i := range env.Operators { @@ -111,10 +131,10 @@ func testOperatorInstallationWithoutPrivileges(env *provider.TestEnvironment) { } } - testhelper.AddTestResultReason(compliantObjects, nonCompliantObjects, tnf.ClaimFilePrintf, ginkgo.Fail) + check.SetResult(compliantObjects, nonCompliantObjects) } -func testOperatorOlmSubscription(env *provider.TestEnvironment) { +func testOperatorOlmSubscription(check *checksdb.Check, env *provider.TestEnvironment) { var compliantObjects []*testhelper.ReportObject var nonCompliantObjects []*testhelper.ReportObject @@ -130,5 +150,5 @@ func testOperatorOlmSubscription(env *provider.TestEnvironment) { } } - testhelper.AddTestResultReason(compliantObjects, nonCompliantObjects, tnf.ClaimFilePrintf, ginkgo.Fail) + check.SetResult(compliantObjects, nonCompliantObjects) } diff --git a/pkg/certsuite/certsuite.go b/pkg/certsuite/certsuite.go index d31000fc8..3e2849ff7 100644 --- a/pkg/certsuite/certsuite.go +++ b/pkg/certsuite/certsuite.go @@ -12,6 +12,7 @@ import ( "github.com/test-network-function/cnf-certification-test/cnf-certification-test/manageability" "github.com/test-network-function/cnf-certification-test/cnf-certification-test/networking" "github.com/test-network-function/cnf-certification-test/cnf-certification-test/observability" + "github.com/test-network-function/cnf-certification-test/cnf-certification-test/operator" "github.com/test-network-function/cnf-certification-test/cnf-certification-test/performance" "github.com/test-network-function/cnf-certification-test/cnf-certification-test/platform" "github.com/test-network-function/cnf-certification-test/cnf-certification-test/results" @@ -31,6 +32,7 @@ func LoadChecksDB() { observability.LoadChecks() performance.LoadChecks() platform.LoadChecks() + operator.LoadChecks() } func Run(labelsFilter, outputFolder string, timeout time.Duration) { diff --git a/pkg/testhelper/testhelper.go b/pkg/testhelper/testhelper.go index a09ba1e1a..b7df30361 100644 --- a/pkg/testhelper/testhelper.go +++ b/pkg/testhelper/testhelper.go @@ -573,6 +573,15 @@ func GetNoHugepagesPodsSkipFn(env *provider.TestEnvironment) func() (bool, strin } } +func GetNoOperatorsSkipFn(env *provider.TestEnvironment) func() (bool, string) { + return func() (bool, string) { + if len(env.Operators) == 0 { + return true, "no operators found" + } + return false, "" + } +} + func SkipIfEmptyAny(skip func(string, ...int), object ...[2]interface{}) { for _, o := range object { s := reflect.ValueOf(o[0])