Skip to content

Commit

Permalink
Create utils testing for OpenShift validator
Browse files Browse the repository at this point in the history
Remove OpenShift validation from Webhook, and add a test for validating it in Utils package
  • Loading branch information
razo7 committed Jan 24, 2024
1 parent 472dae3 commit f6381c9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ test: test-no-verify verify-unchanged ## Generate and format code, run tests, ge

.PHONY: test-no-verify
test-no-verify: manifests generate go-verify test-imports fmt vet envtest ginkgo ## Generate and format code, and run tests
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path --bin-dir $(LOCALBIN))" $(GINKGO) -r --keep-going --require-suite --vv ./api/... ./controllers/... --coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path --bin-dir $(LOCALBIN))" $(GINKGO) -r --keep-going --require-suite --vv ./api/... ./pkg/... ./controllers/... --coverprofile cover.out

.PHONY: bundle-run
bundle-run: operator-sdk ## Run bundle image. Default NS is "openshift-workload-availability", redefine OPERATOR_NAMESPACE to override it.
Expand Down
6 changes: 0 additions & 6 deletions api/v1beta1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsServer "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

"github.com/medik8s/node-maintenance-operator/pkg/utils"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down Expand Up @@ -101,10 +99,6 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())

openshiftCheck, err := utils.NewOpenshiftValidator(cfg)
Expect(err).NotTo(HaveOccurred(), "failed to check if we run on Openshift")
Expect(openshiftCheck.IsOpenshiftSupported()).To(BeFalse())

// start webhook server using Manager
webhookInstallOptions := &testEnv.WebhookInstallOptions
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Expand Down
21 changes: 21 additions & 0 deletions pkg/utils/utils_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package utils

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestEvents(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Utils Suite")
}

var _ = BeforeSuite(func() {
// call start or refactor when moving to "normal" testEnv test
})

var _ = AfterSuite(func() {
// call stop or refactor when moving to "normal" testEnv test
})
23 changes: 23 additions & 0 deletions pkg/utils/validation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package utils

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"sigs.k8s.io/controller-runtime/pkg/envtest"
)

var _ = Describe("Check OpenShift Existance Validation", func() {
testEnv := &envtest.Environment{}
cfg, err := testEnv.Start()
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())
When("Validator doesn't aware of OpenShift", func() {
It("should not support OpenShift", func() {
openshiftCheck, err := NewOpenshiftValidator(cfg)
Expect(err).NotTo(HaveOccurred(), "failed to check if we run on Openshift")
Expect(openshiftCheck.IsOpenshiftSupported()).To(BeFalse())
})
})

})

0 comments on commit f6381c9

Please sign in to comment.