Skip to content

Commit

Permalink
Controllers test enhancements
Browse files Browse the repository at this point in the history
- skip sriovnetworkpoolconfig only test-case in
  kubernetes cluster as it only valid for openshift.
- general: only stop envtest if it was successfully started
  to avoid nil pointer dereference in case system was missconfigured
  since AfterSuite Ginkgo node would run even if BeforeSuite node failed

Signed-off-by: adrianc <[email protected]>
  • Loading branch information
adrianchiris committed Jan 29, 2024
1 parent 4107581 commit 78fabc8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions controllers/sriovnetworkpoolconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ import (
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"

sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
constants "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars"
)

var _ = Describe("Operator", func() {
Context("When is up", func() {
It("should be able to create machine config for MachineConfigPool specified in sriov pool config", func() {
if vars.ClusterType != consts.ClusterTypeOpenshift {
Skip("test should only be executed with openshift cluster type")
}

config := &sriovnetworkv1.SriovNetworkPoolConfig{}
config.SetNamespace(testNamespace)
config.SetName("ovs-hw-offload-config")
Expand Down
11 changes: 6 additions & 5 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const (
interval = time.Millisecond * 250
)

var _ = BeforeSuite(func(done Done) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(
zap.WriteTo(GinkgoWriter),
zap.UseDevMode(true),
Expand Down Expand Up @@ -213,15 +213,16 @@ var _ = BeforeSuite(func(done Done) {
poolConfig.SetName(constants.DefaultConfigName)
poolConfig.Spec = sriovnetworkv1.SriovNetworkPoolConfigSpec{}
Expect(k8sClient.Create(context.TODO(), poolConfig)).Should(Succeed())
close(done)
})

var _ = AfterSuite(func() {
By("tearing down the test environment")
cancel()
Eventually(func() error {
return testEnv.Stop()
}, timeout, time.Second).ShouldNot(HaveOccurred())
if testEnv != nil {
Eventually(func() error {
return testEnv.Stop()
}, timeout, time.Second).ShouldNot(HaveOccurred())
}
})

func TestAPIs(t *testing.T) {
Expand Down

0 comments on commit 78fabc8

Please sign in to comment.