istio.io/istio@v0.0.0-20240520182934-d79c90f27776/istioctl/pkg/dashboard/dashboard_test.go (about) 1 // Copyright Istio Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package dashboard 16 17 import ( 18 "fmt" 19 "regexp" 20 "strings" 21 "testing" 22 23 "istio.io/istio/istioctl/pkg/cli" 24 "istio.io/istio/istioctl/pkg/util/testutil" 25 ) 26 27 func TestDashboard(t *testing.T) { 28 cases := []testutil.TestCase{ 29 { // case 0 30 Args: strings.Split("--browser=false", " "), 31 ExpectedRegexp: regexp.MustCompile("Access to Istio web UIs"), 32 }, 33 { // case 1 34 Args: strings.Split("invalid --browser=false", " "), 35 ExpectedRegexp: regexp.MustCompile(`unknown dashboard "invalid"`), 36 WantException: true, 37 }, 38 { // case 2 39 Args: strings.Split("controlz --browser=false", " "), 40 ExpectedRegexp: regexp.MustCompile(".*Error: specify a pod or --selector"), 41 WantException: true, 42 }, 43 { // case 3 44 Args: strings.Split("controlz --browser=false pod-123456-7890", " "), 45 ExpectedRegexp: regexp.MustCompile(".*http://localhost:3456"), 46 WantException: false, 47 }, 48 { // case 4 49 Args: strings.Split("envoy --browser=false", " "), 50 ExpectedRegexp: regexp.MustCompile(".*Error: specify a pod or --selector"), 51 WantException: true, 52 }, 53 { // case 5 54 Args: strings.Split("envoy --browser=false pod-123456-7890", " "), 55 ExpectedRegexp: regexp.MustCompile("http://localhost:3456"), 56 WantException: false, 57 }, 58 { // case 6 59 Args: strings.Split("grafana --browser=false", " "), 60 ExpectedOutput: "Error: no pods found with selector app.kubernetes.io/name=grafana\n", 61 WantException: true, 62 }, 63 { // case 7 64 Args: strings.Split("jaeger --browser=false", " "), 65 ExpectedOutput: "Error: no pods found with selector app=jaeger\n", 66 WantException: true, 67 }, 68 { // case 8 69 Args: strings.Split("kiali --browser=false", " "), 70 ExpectedOutput: "Error: no pods found with selector app=kiali\n", 71 WantException: true, 72 }, 73 { // case 9 74 Args: strings.Split("prometheus --browser=false", " "), 75 ExpectedOutput: "Error: no pods found with selector app.kubernetes.io/name=prometheus\n", 76 WantException: true, 77 }, 78 { // case 10 79 Args: strings.Split("zipkin --browser=false", " "), 80 ExpectedOutput: "Error: no pods found with selector app=zipkin\n", 81 WantException: true, 82 }, 83 { // case 11 84 Args: strings.Split("envoy --selector app=example --browser=false", " "), 85 ExpectedRegexp: regexp.MustCompile(".*no pods found"), 86 WantException: true, 87 }, 88 { // case 12 89 Args: strings.Split("envoy --browser=false --selector app=example pod-123456-7890", " "), 90 ExpectedRegexp: regexp.MustCompile(".*Error: name cannot be provided when a selector is specified"), 91 WantException: true, 92 }, 93 { // case 13 94 Args: strings.Split("--browser=false controlz --selector app=example", " "), 95 ExpectedRegexp: regexp.MustCompile(".*no pods found"), 96 WantException: true, 97 }, 98 { // case 14 99 Args: strings.Split("--browser=false controlz --selector app=example pod-123456-7890", " "), 100 ExpectedRegexp: regexp.MustCompile(".*Error: name cannot be provided when a selector is specified"), 101 WantException: true, 102 }, 103 { // case 16 104 Args: strings.Split("controlz --browser=false pod-123456-7890", " "), 105 ExpectedRegexp: regexp.MustCompile(".*http://localhost:3456"), 106 WantException: false, 107 }, 108 { // case 17 109 Args: strings.Split("envoy --browser=false pod-123456-7890", " "), 110 ExpectedRegexp: regexp.MustCompile("http://localhost:3456"), 111 WantException: false, 112 }, 113 } 114 115 dbCmd := Dashboard(cli.NewFakeContext(&cli.NewFakeContextOption{ 116 Namespace: "istio-system", 117 })) 118 for i, c := range cases { 119 t.Run(fmt.Sprintf("case %d %s", i, strings.Join(c.Args, " ")), func(t *testing.T) { 120 testutil.VerifyOutput(t, dbCmd, c) 121 cleanupTestCase() 122 }) 123 } 124 } 125 126 func cleanupTestCase() { 127 labelSelector = "" 128 }