File: factory_test.go

package info (click to toggle)
gitlab-agent 16.1.3-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 6,324 kB
  • sloc: makefile: 175; sh: 52; ruby: 3
file content (68 lines) | stat: -rw-r--r-- 2,046 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package agent

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/modagent"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/modshared"
)

func TestGetAgentNamespaceAndServiceAccount(t *testing.T) {
	testCases := []struct {
		description            string
		inputNamespace         string
		expectedNamespace      string
		inputServiceAccount    string
		expectedServiceAccount string
	}{
		{
			description:            "Default namespace and default service account",
			inputNamespace:         "",
			inputServiceAccount:    "",
			expectedNamespace:      "gitlab-agent",
			expectedServiceAccount: "gitlab-agent",
		},
		{
			description:            "Custom service account",
			inputNamespace:         "",
			inputServiceAccount:    "custom-account",
			expectedNamespace:      "gitlab-agent",
			expectedServiceAccount: "custom-account",
		},
		{
			description:            "Custom namespace",
			inputNamespace:         "custom-namespace",
			inputServiceAccount:    "",
			expectedNamespace:      "custom-namespace",
			expectedServiceAccount: "gitlab-agent",
		},
		{
			description:            "Custom namespace and account",
			inputNamespace:         "custom-namespace",
			inputServiceAccount:    "custom-account",
			expectedNamespace:      "custom-namespace",
			expectedServiceAccount: "custom-account",
		},
	}

	for _, tc := range testCases {
		t.Run(tc.description, func(t *testing.T) {
			cfg := getAgentConfig(tc.inputNamespace, tc.inputServiceAccount)
			assert.Equal(t, tc.expectedNamespace, getAgentNamespace(cfg))
			assert.Equal(t, tc.expectedServiceAccount, getAgentServiceAccount(cfg))
		})
	}
}

func getAgentConfig(podNamespace string, serviceAccountName string) *modagent.Config {
	return &modagent.Config{
		AgentMeta: &modshared.AgentMeta{
			Version:      "v1.2.3",
			CommitId:     "32452345",
			PodNamespace: podNamespace,
			PodName:      "n1",
		},
		ServiceAccountName: serviceAccountName,
	}
}