...
1 package serviceaccounts
2
3 import (
4 "os"
5 "strings"
6 "testing"
7
8 "github.com/linkerd/linkerd2/pkg/healthcheck"
9 "github.com/linkerd/linkerd2/testutil"
10 )
11
12 var TestHelper *testutil.TestHelper
13
14 func TestMain(m *testing.M) {
15 TestHelper = testutil.NewTestHelper()
16
17 TestHelper.WaitUntilDeployReady(testutil.LinkerdDeployReplicasEdge)
18 os.Exit(m.Run())
19 }
20
21
22
23 func namesMatch(names []string) bool {
24 for _, expectedname := range healthcheck.ExpectedServiceAccountNames {
25 found := false
26 for _, name := range names {
27 if expectedname == name {
28 found = true
29 break
30 }
31 }
32 if !found {
33 return false
34 }
35 }
36 return true
37 }
38
39 func TestServiceAccountsMatch(t *testing.T) {
40 expectedNames := healthcheck.ExpectedServiceAccountNames
41
42 res, err := TestHelper.Kubectl("",
43 "-n", TestHelper.GetLinkerdNamespace(),
44 "get", "serviceaccounts",
45 "--output", "name",
46 )
47 if err != nil {
48 testutil.AnnotatedFatalf(t, "Error retrieving list of service accounts",
49 "error retrieving list of service accounts: %s", err)
50 }
51 names := strings.Split(strings.TrimSpace(res), "\n")
52 var saNames []string
53 for _, name := range names {
54 saNames = append(saNames, strings.TrimPrefix(name, "serviceaccount/"))
55 }
56
57 if len(saNames) < len(expectedNames) || !namesMatch(saNames) {
58 testutil.Fatalf(t, "the service account list doesn't match the expected list: %s", expectedNames)
59 }
60 }
61
View as plain text