From b5331e79cae02be747446ea5b7b4bab94906321a Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Mon, 18 Sep 2023 12:04:08 +0200 Subject: [PATCH] [envtest]Add UpdateSecret helper This is pulled out from nova-operator as it is generic enough to be reused in other repos like in placement-operator --- modules/common/test/helpers/secret.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/common/test/helpers/secret.go b/modules/common/test/helpers/secret.go index a359b065..04e24495 100644 --- a/modules/common/test/helpers/secret.go +++ b/modules/common/test/helpers/secret.go @@ -96,3 +96,13 @@ func (tc *TestHelper) AssertSecretDoesNotExist(name types.NamespacedName) { g.Expect(k8s_errors.IsNotFound(err)).To(gomega.BeTrue()) }, tc.Timeout, tc.Interval).Should(gomega.Succeed()) } + +// UpdateSecret adds a new key or updates an existing key in the given Secret with a new value +func (tc *TestHelper) UpdateSecret(secretName types.NamespacedName, key string, newValue []byte) { + gomega.Eventually(func(g gomega.Gomega) { + secret := tc.GetSecret(secretName) + secret.Data[key] = newValue + g.Expect(tc.K8sClient.Update(tc.Ctx, &secret)).Should(gomega.Succeed()) + }, tc.Timeout, tc.Interval).Should(gomega.Succeed()) + tc.Logger.Info("Secret updated", "secret", secretName, "key", key) +}