istio.io/istio@v0.0.0-20240520182934-d79c90f27776/istioctl/cmd/options_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 cmd 16 17 import ( 18 "bytes" 19 "regexp" 20 "testing" 21 ) 22 23 // nolint: lll 24 var expectedOutput = `The following options can be passed to any command: 25 --log_as_json: Whether to format output as JSON or in plain console-friendly format 26 --log_caller: Comma-separated list of scopes for which to include caller information, scopes can be any of \[.*\] 27 --log_output_level: Comma-separated minimum per-scope logging level of messages to output, in the form of <scope>:<level>,<scope>:<level>,... where scope can be one of \[.*\] and level can be one of \[.*\] 28 --log_stacktrace_level: Comma-separated minimum per-scope logging level at which stack traces are captured, in the form of <scope>:<level>,<scope:level>,... where scope can be one of \[.*\] and level can be one of \[.*\] 29 --log_target: The set of paths where to output the log. This can be any path as well as the special values stdout and stderr 30 ` 31 32 func TestLogHelp(t *testing.T) { 33 var out bytes.Buffer 34 rootCmd := GetRootCmd([]string{"options"}) 35 rootCmd.SetOut(&out) 36 rootCmd.SetErr(&out) 37 38 fErr := rootCmd.Execute() 39 if fErr != nil { 40 t.Fatalf("options failed with %v and %q\n", fErr, out.String()) 41 } 42 if !regexp.MustCompile(expectedOutput).Match(out.Bytes()) { 43 t.Fatalf("'istioctl options' expected output\n%s\n got\n%s", 44 expectedOutput, out.String()) 45 } 46 }