Skip to content

Commit

Permalink
integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Julio Camarero <[email protected]>
  • Loading branch information
juliocamarero committed Oct 23, 2024
1 parent 9769df6 commit 223b7af
Showing 1 changed file with 216 additions and 0 deletions.
216 changes: 216 additions & 0 deletions test/integration/bundle/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,29 @@ var _ = Describe("Integration", func() {
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when a ConfigMap source including all keys is added", func() {
Expect(cl.Create(ctx, &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "new-bundle-source",
Namespace: opts.Namespace,
},
Data: map[string]string{
"new-source-key-1": dummy.TestCertificate4,
"new-source-key-2": dummy.TestCertificate5,
},
})).NotTo(HaveOccurred())

Expect(komega.Update(testBundle, func() {
testBundle.Spec.Sources = append(testBundle.Spec.Sources, trustapi.BundleSource{
ConfigMap: &trustapi.SourceObjectKeySelector{Name: "new-bundle-source", IncludeAllKeys: true},
})
})()).To(Succeed())

expectedData := dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3, dummy.TestCertificate5)

testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when a Secret source is added", func() {
Expect(cl.Create(ctx, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -205,6 +228,29 @@ var _ = Describe("Integration", func() {
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when a Secret source including all keys is added", func() {
Expect(cl.Create(ctx, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "new-bundle-source",
Namespace: opts.Namespace,
},
Data: map[string][]byte{
"new-source-key-1": []byte(dummy.TestCertificate4),
"new-source-key-2": []byte(dummy.TestCertificate5),
},
})).NotTo(HaveOccurred())

Expect(komega.Update(testBundle, func() {
testBundle.Spec.Sources = append(testBundle.Spec.Sources, trustapi.BundleSource{
Secret: &trustapi.SourceObjectKeySelector{Name: "new-bundle-source", IncludeAllKeys: true},
})
})()).To(Succeed())

expectedData := dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3, dummy.TestCertificate5)

testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when an inLine source is added", func() {
newInLine := dummy.TestCertificate4

Expand Down Expand Up @@ -276,6 +322,91 @@ var _ = Describe("Integration", func() {
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when a ConfigMap source including all keys has a new key", func() {
secret := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "new-bundle-source",
Namespace: opts.Namespace,
},
Data: map[string][]byte{
"new-source-key-1": []byte(dummy.TestCertificate4),
},
}

Expect(cl.Create(ctx, &secret)).NotTo(HaveOccurred())
Expect(komega.Update(testBundle, func() {
testBundle.Spec.Sources = append(testBundle.Spec.Sources, trustapi.BundleSource{
Secret: &trustapi.SourceObjectKeySelector{Name: "new-bundle-source", IncludeAllKeys: true},
})
})()).To(Succeed())

expectedData := dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)

secret.Data["new-source-key-2"] = []byte(dummy.TestCertificate5)
Expect(cl.Update(ctx, &secret)).NotTo(HaveOccurred())

expectedData = dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3, dummy.TestCertificate5)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when a ConfigMap source including all keys has a key removed", func() {
secret := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "new-bundle-source",
Namespace: opts.Namespace,
},
Data: map[string][]byte{
"new-source-key-1": []byte(dummy.TestCertificate4),
"new-source-key-2": []byte(dummy.TestCertificate5),
},
}

Expect(cl.Create(ctx, &secret)).NotTo(HaveOccurred())
Expect(komega.Update(testBundle, func() {
testBundle.Spec.Sources = append(testBundle.Spec.Sources, trustapi.BundleSource{
Secret: &trustapi.SourceObjectKeySelector{Name: "new-bundle-source", IncludeAllKeys: true},
})
})()).To(Succeed())

expectedData := dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3, dummy.TestCertificate5)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)

delete(secret.Data, "new-source-key-2")
Expect(cl.Update(ctx, &secret)).NotTo(HaveOccurred())

expectedData = dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when a ConfigMap source including all keys has a key updated", func() {
secret := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "new-bundle-source",
Namespace: opts.Namespace,
},
Data: map[string][]byte{
"new-source-key-1": []byte(dummy.TestCertificate4),
},
}

Expect(cl.Create(ctx, &secret)).NotTo(HaveOccurred())
Expect(komega.Update(testBundle, func() {
testBundle.Spec.Sources = append(testBundle.Spec.Sources, trustapi.BundleSource{
Secret: &trustapi.SourceObjectKeySelector{Name: "new-bundle-source", IncludeAllKeys: true},
})
})()).To(Succeed())

expectedData := dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)

secret.Data["new-source-key-1"] = []byte(dummy.TestCertificate5)
Expect(cl.Update(ctx, &secret)).NotTo(HaveOccurred())

expectedData = dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate3, dummy.TestCertificate5)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when a Secret source has been modified", func() {
var secret corev1.Secret

Expand All @@ -290,6 +421,91 @@ var _ = Describe("Integration", func() {
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when a Secret source including all keys has a new key", func() {
configMap := corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "new-bundle-source",
Namespace: opts.Namespace,
},
Data: map[string]string{
"new-source-key-1": dummy.TestCertificate4,
},
}

Expect(cl.Create(ctx, &configMap)).NotTo(HaveOccurred())
Expect(komega.Update(testBundle, func() {
testBundle.Spec.Sources = append(testBundle.Spec.Sources, trustapi.BundleSource{
ConfigMap: &trustapi.SourceObjectKeySelector{Name: "new-bundle-source", IncludeAllKeys: true},
})
})()).To(Succeed())

expectedData := dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)

configMap.Data["new-source-key-2"] = dummy.TestCertificate5
Expect(cl.Update(ctx, &configMap)).NotTo(HaveOccurred())

expectedData = dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3, dummy.TestCertificate5)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when a Secret source including all keys has a key removed", func() {
configMap := corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "new-bundle-source",
Namespace: opts.Namespace,
},
Data: map[string]string{
"new-source-key-1": dummy.TestCertificate4,
"new-source-key-2": dummy.TestCertificate5,
},
}

Expect(cl.Create(ctx, &configMap)).NotTo(HaveOccurred())
Expect(komega.Update(testBundle, func() {
testBundle.Spec.Sources = append(testBundle.Spec.Sources, trustapi.BundleSource{
ConfigMap: &trustapi.SourceObjectKeySelector{Name: "new-bundle-source", IncludeAllKeys: true},
})
})()).To(Succeed())

expectedData := dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3, dummy.TestCertificate5)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)

delete(configMap.Data, "new-source-key-2")
Expect(cl.Update(ctx, &configMap)).NotTo(HaveOccurred())

expectedData = dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when a Secret source including all keys has a key updated", func() {
configMap := corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "new-bundle-source",
Namespace: opts.Namespace,
},
Data: map[string]string{
"new-source-key-1": dummy.TestCertificate4,
},
}

Expect(cl.Create(ctx, &configMap)).NotTo(HaveOccurred())
Expect(komega.Update(testBundle, func() {
testBundle.Spec.Sources = append(testBundle.Spec.Sources, trustapi.BundleSource{
ConfigMap: &trustapi.SourceObjectKeySelector{Name: "new-bundle-source", IncludeAllKeys: true},
})
})()).To(Succeed())

expectedData := dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate4, dummy.TestCertificate3)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)

configMap.Data["new-source-key-1"] = dummy.TestCertificate5
Expect(cl.Update(ctx, &configMap)).NotTo(HaveOccurred())

expectedData = dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate3, dummy.TestCertificate5)
testenv.EventuallyBundleHasSyncedAllNamespaces(ctx, cl, testBundle.Name, expectedData)
})

It("should update all targets when an InLine source has been modified", func() {
newInLine := dummy.TestCertificate4

Expand Down

0 comments on commit 223b7af

Please sign in to comment.