From bd78abd256d238dda955b1de2d874ad5eba28af3 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Mon, 8 Apr 2024 08:32:19 +0200 Subject: [PATCH] [helpers] add SimulateTLSMemcachedReady adds helper which sets status.TLSSupport = true. This allows to add tests where the memcached instance is configured for tls. OSPRH-5283 --- apis/test/helpers/memcached.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apis/test/helpers/memcached.go b/apis/test/helpers/memcached.go index e0e5fc6e..dbbdf485 100644 --- a/apis/test/helpers/memcached.go +++ b/apis/test/helpers/memcached.go @@ -125,3 +125,28 @@ func (tc *TestHelper) SimulateMemcachedReady(name types.NamespacedName) { tc.Logger.Info("Simulated memcached ready", "on", name) } + +// SimulateTLSMemcachedReady simulates a ready state for a Memcached instance in a Kubernetes cluster which supports TLS. +func (tc *TestHelper) SimulateTLSMemcachedReady(name types.NamespacedName) { + t.Eventually(func(g t.Gomega) { + mc := tc.GetMemcached(name) + mc.Status.Conditions.MarkTrue(condition.ReadyCondition, condition.ReadyMessage) + mc.Status.ReadyCount = *mc.Spec.Replicas + + serverList := []string{} + serverListWithInet := []string{} + for i := 0; i < int(*mc.Spec.Replicas); i++ { + serverList = append(serverList, fmt.Sprintf("%s-%d.%s.%s.svc:11211", mc.Name, i, mc.Name, mc.Namespace)) + serverListWithInet = append(serverListWithInet, fmt.Sprintf("inet:[%s-%d.%s.%s.svc]:11211", mc.Name, i, mc.Name, mc.Namespace)) + } + mc.Status.ServerList = serverList + mc.Status.ServerListWithInet = serverListWithInet + mc.Status.TLSSupport = true + + // This can return conflict so we have the t.Eventually block to retry + g.Expect(tc.K8sClient.Status().Update(tc.Ctx, mc)).To(t.Succeed()) + + }, tc.Timeout, tc.Interval).Should(t.Succeed()) + + tc.Logger.Info("Simulated memcached ready", "on", name) +}