1 package viztest
2
3 import (
4 "fmt"
5 "os"
6 "strconv"
7 "strings"
8 "testing"
9 "time"
10
11 "github.com/linkerd/linkerd2/testutil"
12 )
13
14
15
16
17
18 var (
19 TestHelper *testutil.TestHelper
20 )
21
22 func TestMain(m *testing.M) {
23 TestHelper = testutil.NewTestHelper()
24 os.Exit(m.Run())
25 }
26
27
28
29
30
31
32
33 func TestInstallLinkerd(t *testing.T) {
34
35 cmd := []string{
36 "install",
37 "--crds",
38 "--controller-log-level", "debug",
39 "--set", fmt.Sprintf("proxy.image.version=%s", TestHelper.GetVersion()),
40 "--set", "heartbeatSchedule=1 2 3 4 5",
41 }
42
43
44 out, err := TestHelper.LinkerdRun(cmd...)
45 if err != nil {
46 testutil.AnnotatedFatal(t, "'linkerd install --crds' command failed", err)
47 }
48
49 out, err = TestHelper.KubectlApplyWithArgs(out)
50 if err != nil {
51 testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
52 "'kubectl apply' command failed\n%s", out)
53 }
54
55
56 cmd = []string{
57 "install",
58 "--controller-log-level", "debug",
59 "--set", fmt.Sprintf("proxy.image.version=%s", TestHelper.GetVersion()),
60 "--set", "heartbeatSchedule=1 2 3 4 5",
61 }
62
63
64 out, err = TestHelper.LinkerdRun(cmd...)
65 if err != nil {
66 testutil.AnnotatedFatal(t, "'linkerd install' command failed", err)
67 }
68
69 out, err = TestHelper.KubectlApplyWithArgs(out)
70 if err != nil {
71 testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
72 "'kubectl apply' command failed\n%s", out)
73 }
74
75 TestHelper.WaitRollout(t, testutil.LinkerdDeployReplicasEdge)
76 }
77
78
79 func TestInstallVizHA(t *testing.T) {
80 cmd := []string{
81 "viz",
82 "install",
83 "--set", fmt.Sprintf("namespace=%s", TestHelper.GetVizNamespace()),
84 "--ha",
85 }
86
87 if TestHelper.NativeSidecar() {
88 cmd = append(cmd, "--set", "proxy.nativeSidecar=true")
89 }
90
91 out, err := TestHelper.LinkerdRun(cmd...)
92 if err != nil {
93 testutil.AnnotatedFatal(t, "'linkerd viz install' command failed", err)
94 }
95
96 out, err = TestHelper.KubectlApplyWithArgs(out, "--dry-run")
97 if err != nil {
98 testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
99 "'kubectl apply' command failed\n%s", out)
100 }
101 }
102
103
104
105 func TestInstallViz(t *testing.T) {
106 cmd := []string{
107 "viz",
108 "install",
109 "--set", fmt.Sprintf("namespace=%s", TestHelper.GetVizNamespace()),
110 }
111
112 out, err := TestHelper.LinkerdRun(cmd...)
113 if err != nil {
114 testutil.AnnotatedFatal(t, "'linkerd viz install' command failed", err)
115 }
116
117 out, err = TestHelper.KubectlApplyWithArgs(out)
118 if err != nil {
119 testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
120 "'kubectl apply' command failed\n%s", out)
121 }
122
123 TestHelper.WaitRollout(t, testutil.LinkerdVizDeployReplicas)
124
125 }
126
127 func TestCheckViz(t *testing.T) {
128 if err := TestHelper.TestCheck(); err != nil {
129 t.Fatalf("'linkerd check' command failed: %s", err)
130 }
131 }
132
133 func TestDashboard(t *testing.T) {
134 dashboardPort := 52237
135 dashboardURL := fmt.Sprintf("http://localhost:%d", dashboardPort)
136
137 outputStream, err := TestHelper.LinkerdRunStream("viz", "dashboard", "-p",
138 strconv.Itoa(dashboardPort), "--show", "url")
139 if err != nil {
140 testutil.AnnotatedFatalf(t, "error running command",
141 "error running command:\n%s", err)
142 }
143 defer outputStream.Stop()
144
145 outputLines, err := outputStream.ReadUntil(4, 1*time.Minute)
146 if err != nil {
147 testutil.AnnotatedFatalf(t, "error running command",
148 "error running command:\n%s", err)
149 }
150
151 output := strings.Join(outputLines, "")
152 if !strings.Contains(output, dashboardURL) {
153 testutil.AnnotatedFatalf(t,
154 "dashboard command failed. Expected url [%s] not present", dashboardURL)
155 }
156
157 resp, err := TestHelper.HTTPGetURL(dashboardURL + "/api/version")
158 if err != nil {
159 testutil.AnnotatedFatalf(t, "unexpected error",
160 "unexpected error: %v", err)
161 }
162
163 if !strings.Contains(resp, TestHelper.GetVersion()) {
164 testutil.AnnotatedFatalf(t, "dashboard command failed; response doesn't contain expected version",
165 "dashboard command failed. Expected response [%s] to contain version [%s]",
166 resp, TestHelper.GetVersion())
167 }
168 }
169
View as plain text