Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add containerenv unittest for appsync #1237

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions controllers/argocd/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1625,24 +1625,6 @@ func Test_UpdateNodePlacement(t *testing.T) {
}
}

func parallelismLimit(n int32) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.ParallelismLimit = n
}
}

func logFormat(f string) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.LogFormat = f
}
}

func logLevel(l string) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.LogLevel = l
}
}

func assertDeploymentHasProxyVars(t *testing.T, c client.Client, name string) {
t.Helper()
deployment := &appsv1.Deployment{}
Expand Down
55 changes: 54 additions & 1 deletion controllers/argocd/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"reflect"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -30,6 +31,30 @@ const (
redisHAProxyTestImage = "testing/redis-ha-haproxy:latest-ha"
)

func parallelismLimit(n int32) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.ParallelismLimit = n
}
}

func logFormat(f string) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.LogFormat = f
}
}

func logLevel(l string) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.LogLevel = l
}
}

func appSync(s int) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.AppSync = &metav1.Duration{Duration: time.Second * time.Duration(s)}
}
}

var imageTests = []struct {
name string
pre func(t *testing.T)
Expand Down Expand Up @@ -507,7 +532,7 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) {
},
{
"configured invalid loglevel",
[]argoCDOpt{logFormat("arbitrary")},
[]argoCDOpt{logLevel("arbitrary")},
defaultResult,
},
{
Expand Down Expand Up @@ -542,6 +567,34 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) {
}
}

func TestGetArgoApplicationContainerEnv(t *testing.T) {

sync60s := []v1.EnvVar{
v1.EnvVar{Name: "HOME", Value: "/home/argocd", ValueFrom: (*v1.EnvVarSource)(nil)},
v1.EnvVar{Name: "ARGOCD_RECONCILIATION_TIMEOUT", Value: "60s", ValueFrom: (*v1.EnvVarSource)(nil)}}

cmdTests := []struct {
name string
opts []argoCDOpt
want []v1.EnvVar
}{
{
"configured apsync to 60s",
[]argoCDOpt{appSync(60)},
sync60s,
},
}

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()
Expand Down
Loading