forked from medik8s/node-maintenance-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create utils testing for OpenShift validator
Remove OpenShift validation from Webhook, and add a test for validating it in Utils package
- Loading branch information
Showing
5 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"go.uber.org/zap/zapcore" | ||
|
||
"k8s.io/client-go/rest" | ||
"sigs.k8s.io/controller-runtime/pkg/envtest" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
) | ||
var cfg *rest.Config | ||
|
||
func TestEvents(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Utils Suite") | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
opts := zap.Options{ | ||
Development: true, | ||
TimeEncoder: zapcore.RFC3339NanoTimeEncoder, | ||
} | ||
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseFlagOptions(&opts))) | ||
|
||
var err error | ||
testEnv := &envtest.Environment{} | ||
cfg, err = testEnv.Start() | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(cfg).NotTo(BeNil()) | ||
|
||
// call start or refactor when moving to "normal" testEnv test | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
// call stop or refactor when moving to "normal" testEnv test | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,4 @@ func (v *OpenshiftValidator) validateIsOpenshift(config *rest.Config) error { | |
} | ||
} | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package utils | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Check OpenShift Existance Validation", func() { | ||
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()) | ||
}) | ||
}) | ||
}) |