Skip to content

Commit

Permalink
Merge pull request openshift#604 from ykulazhenkov/pr-fix-tests
Browse files Browse the repository at this point in the history
Move default policy creation in controller tests to BeforeSuite.
  • Loading branch information
e0ne authored Jan 31, 2024
2 parents 48dbe6f + 224f2c0 commit 36394ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 40 deletions.
41 changes: 1 addition & 40 deletions controllers/sriovoperatorconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,13 @@ import (
. "github.com/onsi/gomega"

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

var _ = Describe("Operator", func() {
var config *sriovnetworkv1.SriovOperatorConfig
BeforeEach(func() {
defaultPolicy := &sriovnetworkv1.SriovNetworkNodePolicy{}
defaultPolicy.SetNamespace(vars.Namespace)
defaultPolicy.SetName(constants.DefaultPolicyName)
defaultPolicy.Spec = sriovnetworkv1.SriovNetworkNodePolicySpec{
NumVfs: 0,
NodeSelector: make(map[string]string),
NicSelector: sriovnetworkv1.SriovNetworkNicSelector{},
}
Expect(k8sClient.Create(goctx.TODO(), defaultPolicy)).Should(Succeed())
})
AfterEach(func() {
defaultPolicy := &sriovnetworkv1.SriovNetworkNodePolicy{}
defaultPolicy.SetNamespace(vars.Namespace)
defaultPolicy.SetName(constants.DefaultPolicyName)
Expect(k8sClient.Delete(goctx.TODO(), defaultPolicy)).Should(Succeed())
})
// BeforeEach(func() {
// config = &sriovnetworkv1.SriovOperatorConfig{}
// config.SetNamespace(testNamespace)
// config.SetName(DEFAULT_CONFIG_NAME)
// config.Spec = sriovnetworkv1.SriovOperatorConfigSpec{
// EnableInjector: func() *bool { b := true; return &b }(),
// EnableOperatorWebhook: func() *bool { b := true; return &b }(),
// ConfigDaemonNodeSelector: map[string]string{},
// LogLevel: 2,
// }
// Expect(k8sClient.Create(goctx.TODO(), config)).Should(Succeed())
// })
// AfterEach(func() {
// config := &sriovnetworkv1.SriovOperatorConfig{}
// config.SetNamespace(testNamespace)
// config.SetName(DEFAULT_CONFIG_NAME)
// Expect(k8sClient.Delete(goctx.TODO(), config)).Should(Succeed())
// })

Context("When is up", func() {
JustBeforeEach(func() {
config = &sriovnetworkv1.SriovOperatorConfig{}
config := &sriovnetworkv1.SriovOperatorConfig{}
err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout)
Expect(err).NotTo(HaveOccurred())
config.Spec = sriovnetworkv1.SriovOperatorConfigSpec{
Expand Down
10 changes: 10 additions & 0 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ var _ = BeforeSuite(func() {
}
Expect(k8sClient.Create(context.TODO(), config)).Should(Succeed())

defaultPolicy := &sriovnetworkv1.SriovNetworkNodePolicy{}
defaultPolicy.SetNamespace(testNamespace)
defaultPolicy.SetName(constants.DefaultPolicyName)
defaultPolicy.Spec = sriovnetworkv1.SriovNetworkNodePolicySpec{
NumVfs: 0,
NodeSelector: make(map[string]string),
NicSelector: sriovnetworkv1.SriovNetworkNicSelector{},
}
Expect(k8sClient.Create(context.TODO(), defaultPolicy)).Should(Succeed())

infra := &openshiftconfigv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster",
Expand Down

0 comments on commit 36394ac

Please sign in to comment.