1 package get
2
3 import (
4 "fmt"
5 "os"
6 "strings"
7 "testing"
8
9 "github.com/linkerd/linkerd2/testutil"
10 )
11
12
13
14
15
16 var TestHelper *testutil.TestHelper
17
18 func TestMain(m *testing.M) {
19 TestHelper = testutil.NewTestHelper()
20
21 TestHelper.WaitUntilDeployReady(testutil.LinkerdVizDeployReplicas)
22 os.Exit(m.Run())
23 }
24
25 type testCase struct {
26 s string
27 c int
28 }
29
30
31
32
33
34
35
36
37 func TestRoutes(t *testing.T) {
38
39 cmd := []string{"viz", "routes", "--namespace", TestHelper.GetLinkerdNamespace(), "deploy"}
40 out, err := TestHelper.LinkerdRun(cmd...)
41 if err != nil {
42 testutil.AnnotatedFatal(t, "'linkerd routes' command failed", err)
43 }
44
45 routeStrings := []testCase{
46 {"linkerd-destination", 1},
47 {"linkerd-identity", 3},
48 {"linkerd-proxy-injector", 2},
49 }
50
51 for _, r := range routeStrings {
52 count := strings.Count(out, r.s)
53 if count != r.c {
54 testutil.AnnotatedFatalf(t, fmt.Sprintf("expected %d occurrences of \"%s\", got %d", r.c, r.s, count),
55 "expected %d occurrences of \"%s\", got %d\n%s", r.c, r.s, count, out)
56 }
57 }
58
59
60 cmd = []string{"viz", "routes", "--namespace", TestHelper.GetVizNamespace(), "deploy"}
61 out, err = TestHelper.LinkerdRun(cmd...)
62 if err != nil {
63 testutil.AnnotatedFatal(t, "'linkerd routes' command failed", err)
64 }
65
66 vizRouteStrings := []testCase{
67 {"metrics-api", 9},
68 {"tap", 4},
69 {"tap-injector", 2},
70 {"web", 2},
71 }
72
73 if !TestHelper.ExternalPrometheus() {
74 vizRouteStrings = append(vizRouteStrings, testCase{
75 "prometheus",
76 5,
77 })
78 }
79 for _, r := range vizRouteStrings {
80 count := strings.Count(out, r.s)
81 if count != r.c {
82 testutil.AnnotatedFatalf(t, fmt.Sprintf("expected %d occurrences of \"%s\", got %d", r.c, r.s, count),
83 "expected %d occurrences of \"%s\", got %d\n%s", r.c, r.s, count, out)
84 }
85 }
86 }
87
View as plain text