Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thegridman committed Jul 9, 2024
1 parent d214eb7 commit 019e1f8
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func TestShouldUpdateV1CRDs(t *testing.T) {
err = crdv1.AddToScheme(mgr.Scheme)
g.Expect(err).NotTo(HaveOccurred())

viper.GetViper().Set(operator.FlagJobCRD, true)

oldCRDs := make(map[string]*crdv1.CustomResourceDefinition)
oldCRDs["coherence.coherence.oracle.com"] = nil
oldCRDs["coherencejob.coherence.oracle.com"] = nil
Expand Down Expand Up @@ -132,3 +134,44 @@ func TestShouldUpdateV1CRDs(t *testing.T) {
g.Expect(crd.GetResourceVersion()).To(Equal(oldCRD.GetResourceVersion()))
}
}

func TestShouldNotUpdateJobCRDWhenFlagIsFalse(t *testing.T) {
var err error

g := NewGomegaWithT(t)
mgr, err := fakes.NewFakeManager()
g.Expect(err).NotTo(HaveOccurred())
err = crdv1.AddToScheme(mgr.Scheme)
g.Expect(err).NotTo(HaveOccurred())

viper.GetViper().Set(operator.FlagJobCRD, false)

oldCRDs := make(map[string]*crdv1.CustomResourceDefinition)
oldCRDs["coherence.coherence.oracle.com"] = nil

for name := range oldCRDs {
crd := crdv1.CustomResourceDefinition{}
crd.SetName(name)
crd.SetResourceVersion("1")
oldCRDs[name] = &crd
_ = mgr.GetClient().Create(context.TODO(), &crd)
}

ctx := context.TODO()
log := logr.New(fakes.TestLogSink{T: t})

err = v1.EnsureV1CRDs(ctx, log, mgr.Scheme, mgr.Client)
g.Expect(err).NotTo(HaveOccurred())

crdList := crdv1.CustomResourceDefinitionList{}
err = mgr.Client.List(ctx, &crdList)
g.Expect(err).NotTo(HaveOccurred())

g.Expect(len(crdList.Items)).To(Equal(1))

for _, crd := range crdList.Items {
oldCRD := oldCRDs[crd.Name]
g.Expect(crd).NotTo(Equal(oldCRD))
g.Expect(crd.GetResourceVersion()).To(Equal(oldCRD.GetResourceVersion()))
}
}

0 comments on commit 019e1f8

Please sign in to comment.