...
1
2
3
4 package e2e
5
6 import (
7 "context"
8 "fmt"
9 "time"
10
11 . "github.com/onsi/ginkgo/v2"
12 . "github.com/onsi/gomega"
13 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14 "sigs.k8s.io/cli-utils/pkg/apply"
15 "sigs.k8s.io/cli-utils/test/e2e/e2eutil"
16 "sigs.k8s.io/cli-utils/test/e2e/invconfig"
17 "sigs.k8s.io/controller-runtime/pkg/client"
18 )
19
20 func applyWithExistingInvTest(ctx context.Context, c client.Client, invConfig invconfig.InventoryConfig, inventoryName, namespaceName string) {
21 By("Apply first set of resources")
22 applier := invConfig.ApplierFactoryFunc()
23 orgInventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
24
25 orgApplyInv := invConfig.InvWrapperFunc(invConfig.FactoryFunc(inventoryName, namespaceName, orgInventoryID))
26
27 resources := []*unstructured.Unstructured{
28 e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(deployment1), namespaceName),
29 }
30
31 e2eutil.RunWithNoErr(applier.Run(ctx, orgApplyInv, resources, apply.ApplierOptions{
32 ReconcileTimeout: 2 * time.Minute,
33 EmitStatusEvents: true,
34 }))
35
36 By("Verify inventory")
37 invConfig.InvSizeVerifyFunc(ctx, c, inventoryName, namespaceName, orgInventoryID, 1, 1)
38
39 By("Apply second set of resources, using same inventory name but different ID")
40 secondInventoryID := fmt.Sprintf("%s-%s-2", inventoryName, namespaceName)
41 secondApplyInv := invConfig.InvWrapperFunc(invConfig.FactoryFunc(inventoryName, namespaceName, secondInventoryID))
42
43 err := e2eutil.Run(applier.Run(ctx, secondApplyInv, resources, apply.ApplierOptions{
44 ReconcileTimeout: 2 * time.Minute,
45 EmitStatusEvents: true,
46 }))
47
48 By("Verify that we get the correct error")
49 Expect(err).To(HaveOccurred())
50 Expect(err.Error()).To(ContainSubstring("inventory-id of inventory object in cluster doesn't match provided id"))
51 }
52
View as plain text