Skip to content

Commit

Permalink
Adding the operator suite to the ginkgoless branch (#1672)
Browse files Browse the repository at this point in the history
  • Loading branch information
edcdavid authored Nov 30, 2023
1 parent a3a6492 commit 8ff3fd6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 26 deletions.
72 changes: 46 additions & 26 deletions cnf-certification-test/operator/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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

Expand All @@ -130,5 +150,5 @@ func testOperatorOlmSubscription(env *provider.TestEnvironment) {
}
}

testhelper.AddTestResultReason(compliantObjects, nonCompliantObjects, tnf.ClaimFilePrintf, ginkgo.Fail)
check.SetResult(compliantObjects, nonCompliantObjects)
}
2 changes: 2 additions & 0 deletions pkg/certsuite/certsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,6 +32,7 @@ func LoadChecksDB() {
observability.LoadChecks()
performance.LoadChecks()
platform.LoadChecks()
operator.LoadChecks()
}

func Run(labelsFilter, outputFolder string, timeout time.Duration) {
Expand Down
9 changes: 9 additions & 0 deletions pkg/testhelper/testhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 8ff3fd6

Please sign in to comment.