Skip to content

Commit

Permalink
e2e tests enhancements
Browse files Browse the repository at this point in the history
- remove deprecated use of async node
- fail if creating client returned nil
- use ptr pkg instead of pointer package as its deprecated

Signed-off-by: adrianc <[email protected]>
  • Loading branch information
adrianchiris committed Jan 29, 2024
1 parent 78fabc8 commit 6867541
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
3 changes: 3 additions & 0 deletions test/conformance/tests/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ func init() {
}

clients = testclient.New("")
if clients == nil {
panic("failed package init, failed to create ClientSet")
}
}
8 changes: 3 additions & 5 deletions test/e2e/e2e_tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestSriovTests(t *testing.T) {

var sriovIface *sriovnetworkv1.InterfaceExt

var _ = BeforeSuite(func(done Done) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

// Go to project root directory
Expand All @@ -64,7 +64,7 @@ var _ = BeforeSuite(func(done Done) {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("config", "crd", "bases"), filepath.Join("test", "util", "crds")},
UseExistingCluster: pointer.BoolPtr(true),
UseExistingCluster: ptr.To[bool](true),
}

var err error
Expand Down Expand Up @@ -102,8 +102,6 @@ var _ = BeforeSuite(func(done Done) {
doneNetNsSet = make(chan error, 1)
go netns.SetPfVfLinkNetNs(testPciDev, testNsPath, devPollInterval, quitNetNsSet, doneNetNsSet)
}

close(done)
})

var _ = AfterSuite(func() {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/sriovoperatornodepolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var _ = Describe("Operator", func() {

execute.BeforeAll(func() {
clients := testclient.New("")
Expect(clients).ToNot(BeNil())

Eventually(func() *cluster.EnabledNodes {
sriovInfos, _ = cluster.DiscoverSriov(clients, testNamespace)
return sriovInfos
Expand Down
4 changes: 4 additions & 0 deletions test/util/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func All() error {
operatorNamespace = "openshift-sriov-network-operator"
}
clients := client.New("")
if clients == nil {
return fmt.Errorf("failed to create ClientSet")
}

if RestoreNodeDrainState {
err := cluster.SetDisableNodeDrainState(clients, operatorNamespace, false)
if err != nil {
Expand Down
19 changes: 10 additions & 9 deletions test/validation/tests/test_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ var (
operatorNamespace string
)

func init() {
operatorNamespace = os.Getenv("OPERATOR_NAMESPACE")
if operatorNamespace == "" {
operatorNamespace = "openshift-sriov-network-operator"
}

clients = testclient.New("")
}

const (
sriovOperatorDeploymentName = "sriov-network-operator"
// SriovNetworkNodePolicies contains the name of the sriov network node policies CRD
Expand All @@ -45,6 +36,16 @@ const (
sriovOperatorConfigs = "sriovoperatorconfigs.sriovnetwork.openshift.io"
)

var _ = BeforeSuite(func() {
operatorNamespace = os.Getenv("OPERATOR_NAMESPACE")
if operatorNamespace == "" {
operatorNamespace = "openshift-sriov-network-operator"
}

clients = testclient.New("")
Expect(clients).ToNot(BeNil())
})

var _ = Describe("validation", func() {

Context("sriov", func() {
Expand Down

0 comments on commit 6867541

Please sign in to comment.