istio
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
15package cmd16
17import (18"bytes"19"regexp"20"testing"21)
22
23// nolint: lll
24var 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
32func TestLogHelp(t *testing.T) {33var out bytes.Buffer34rootCmd := GetRootCmd([]string{"options"})35rootCmd.SetOut(&out)36rootCmd.SetErr(&out)37
38fErr := rootCmd.Execute()39if fErr != nil {40t.Fatalf("options failed with %v and %q\n", fErr, out.String())41}42if !regexp.MustCompile(expectedOutput).Match(out.Bytes()) {43t.Fatalf("'istioctl options' expected output\n%s\n got\n%s",44expectedOutput, out.String())45}46}
47