From bf325ad8634224e5c390d08c8b3454a573df2e26 Mon Sep 17 00:00:00 2001 From: mehabhalodiya Date: Fri, 16 Feb 2024 15:17:38 +0530 Subject: [PATCH] Add unittest for env Signed-off-by: mehabhalodiya --- controllers/argocd/util_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/controllers/argocd/util_test.go b/controllers/argocd/util_test.go index c06812dcd..5c1619ba9 100644 --- a/controllers/argocd/util_test.go +++ b/controllers/argocd/util_test.go @@ -30,6 +30,12 @@ const ( redisHAProxyTestImage = "testing/redis-ha-haproxy:latest-ha" ) +func setEnv(e []v1.EnvVar) argoCDOpt { + return func(a *argoproj.ArgoCD) { + a.Spec.Controller.Env = e + } +} + var imageTests = []struct { name string pre func(t *testing.T) @@ -542,6 +548,33 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) { } } +func TestGetArgoApplicationEnv(t *testing.T) { + + validEnv := []v1.EnvVar{ + v1.EnvVar{Name: "HOME", Value: "/home/argocd", ValueFrom: (*v1.EnvVarSource)(nil)}} + + cmdTests := []struct { + name string + opts []argoCDOpt + want []v1.EnvVar + }{ + { + "configured setenv to test", + []argoCDOpt{setEnv(validEnv)}, + validEnv, + }, + } + + for _, tt := range cmdTests { + cr := makeTestArgoCD(tt.opts...) + env := getArgoControllerContainerEnv(cr) + + if !reflect.DeepEqual(env, tt.want) { + t.Fatalf("got %#v, want %#v", env, tt.want) + } + } +} + func TestDeleteRBACsForNamespace(t *testing.T) { a := makeTestArgoCD() testClient := testclient.NewSimpleClientset()