Skip to content

Commit

Permalink
Transition manageability suite to ginkgoless (#1614)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 authored Nov 14, 2023
1 parent ae0b030 commit 50caa00
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
60 changes: 40 additions & 20 deletions cnf-certification-test/manageability/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,57 @@ package manageability
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/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.ManageabilityTestKey, func() {
logrus.Debugf("Entering %s suite", common.ManageabilityTestKey)
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
}

skipIfNoContainersFn = func() (bool, string) {
if len(env.Containers) == 0 {
logrus.Warnf("No containers to check...")
return true, "There are no containers to check. Please check under test labels."
}
return false, ""
}
)

func init() {
logrus.Debugf("Entering %s suite", common.ManageabilityTestKey)

checksGroup := checksdb.NewChecksGroup(common.ManageabilityTestKey).
WithBeforeEachFn(beforeEachFn)

testID, tags := identifiers.GetGinkgoTestIDAndLabels(identifiers.TestContainersImageTag)
ginkgo.It(testID, ginkgo.Label(tags...), func() {
testhelper.SkipIfEmptyAll(ginkgo.Skip, testhelper.NewSkipObject(env.Containers, "env.Containers"))
testContainersImageTag(&env)
})
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoContainersFn).
WithCheckFn(func(c *checksdb.Check) error {
testContainersImageTag(c, &env)
return nil
}))

testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestContainerPortNameFormat)
ginkgo.It(testID, ginkgo.Label(tags...), func() {
testhelper.SkipIfEmptyAll(ginkgo.Skip, testhelper.NewSkipObject(env.Containers, "env.Containers"))
testContainerPortNameFormat(&env)
})
})
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoContainersFn).
WithCheckFn(func(c *checksdb.Check) error {
testContainerPortNameFormat(c, &env)
return nil
}))
}

func testContainersImageTag(env *provider.TestEnvironment) {
func testContainersImageTag(check *checksdb.Check, env *provider.TestEnvironment) {
var compliantObjects []*testhelper.ReportObject
var nonCompliantObjects []*testhelper.ReportObject
for _, cut := range env.Containers {
Expand All @@ -61,7 +81,7 @@ func testContainersImageTag(env *provider.TestEnvironment) {
compliantObjects = append(compliantObjects, testhelper.NewContainerReportObject(cut.Namespace, cut.Podname, cut.Name, "Container is tagged", true))
}
}
testhelper.AddTestResultReason(compliantObjects, nonCompliantObjects, tnf.ClaimFilePrintf, ginkgo.Fail)
check.SetResult(compliantObjects, nonCompliantObjects)
}

// The name field in the ContainerPort section must be of the form <protocol>[-<suffix>] where <protocol> is one of the following,
Expand All @@ -73,7 +93,7 @@ func containerPortNameFormatCheck(portName string) bool {
return allowedProtocolNames[res[0]]
}

func testContainerPortNameFormat(env *provider.TestEnvironment) {
func testContainerPortNameFormat(check *checksdb.Check, env *provider.TestEnvironment) {
for _, newProtocol := range env.ValidProtocolNames {
allowedProtocolNames[newProtocol] = true
}
Expand All @@ -91,5 +111,5 @@ func testContainerPortNameFormat(env *provider.TestEnvironment) {
}
}
}
testhelper.AddTestResultReason(compliantObjects, nonCompliantObjects, tnf.ClaimFilePrintf, ginkgo.Fail)
check.SetResult(compliantObjects, nonCompliantObjects)
}
10 changes: 10 additions & 0 deletions generated_policy.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"grades": {
"requiredPassingTests": [
{
"id": "manageability-container-port-name-format",
"suite": "manageability",
"tags": "extended"
},
{
"id": "manageability-containers-image-tag",
"suite": "manageability",
"tags": "extended"
},
{
"id": "observability-container-logging",
"suite": "observability",
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/test-network-function/cnf-certification-test/pkg/loghelper"
"github.com/test-network-function/cnf-certification-test/pkg/versions"

_ "github.com/test-network-function/cnf-certification-test/cnf-certification-test/manageability"
_ "github.com/test-network-function/cnf-certification-test/cnf-certification-test/observability"
"github.com/test-network-function/cnf-certification-test/cnf-certification-test/webserver"

Expand Down

0 comments on commit 50caa00

Please sign in to comment.