From 46a1c4043cb7eff7439ee956875212d42b7119dd Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Mon, 25 Nov 2024 16:20:39 +0100 Subject: [PATCH] SYSENG-1822: panic when faking ResourceWithTag (#419) --- CHANGELOG.md | 5 +++++ pkg/api/mock/mock_api_implementation.go | 5 +++++ pkg/apis/lbaas/v1/e2e_connection_test.go | 2 +- pkg/vlan/integration_test.go | 9 +++++---- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4b18c3d..d7bdf05f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,11 @@ Some examples, more below in the actual changelog (newer entries are more likely * (internal) generic client: add hook FilterRequestURLHook (#123, @marioreggiori) --> + +### Added + +* api/mock/mock_api_implementation: panic when trying to fake `ResourceWithTag` (#419, @drpsychick) + ## [0.7.6] -- 2024-11-04 ### Added diff --git a/pkg/api/mock/mock_api_implementation.go b/pkg/api/mock/mock_api_implementation.go index 5f9d9d2d..bad1a0a1 100644 --- a/pkg/api/mock/mock_api_implementation.go +++ b/pkg/api/mock/mock_api_implementation.go @@ -296,6 +296,11 @@ func (a *mockAPI) FakeExisting(o types.Object, tags ...string) string { a.dataMu.Lock() defer a.dataMu.Unlock() + // SYSENG-1822: faking ResourceWithTag blindly overwrites object with same identifier. + if _, ok := o.(*corev1.ResourceWithTag); ok { + panic("mock: cannot fake ResourceWithTag, pass tags to the object or use the FakeExisting method") + } + identifier := makeObjectIdentifiable(o) mao := APIObject{ diff --git a/pkg/apis/lbaas/v1/e2e_connection_test.go b/pkg/apis/lbaas/v1/e2e_connection_test.go index 7b37f6ba..21ab579b 100644 --- a/pkg/apis/lbaas/v1/e2e_connection_test.go +++ b/pkg/apis/lbaas/v1/e2e_connection_test.go @@ -40,7 +40,7 @@ func unavailableServerConnectionCheck(url string) { resp, err := http.Get(url) g.Expect(err).NotTo(HaveOccurred()) g.Expect(resp.StatusCode).To(Equal(http.StatusServiceUnavailable)) - }, 5*time.Second, 1*time.Second).Should(Succeed()) + }, 60*time.Second, 5*time.Second).Should(Succeed()) }) } diff --git a/pkg/vlan/integration_test.go b/pkg/vlan/integration_test.go index 9fa8317f..445e2059 100644 --- a/pkg/vlan/integration_test.go +++ b/pkg/vlan/integration_test.go @@ -41,10 +41,11 @@ var _ = Describe("vlan client", func() { summary, err := api.Create(ctx, def) Expect(err).NotTo(HaveOccurred()) vlanID = summary.Identifier - }) - DeferCleanup(func(ctx context.Context) { - err := api.Delete(ctx, vlanID) - Expect(err).NotTo(HaveOccurred()) + + DeferCleanup(func(ctx context.Context) { + err := api.Delete(ctx, vlanID) + Expect(err).NotTo(HaveOccurred()) + }) }) It("lists VLANs including test VLAN", func() {