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"testing"19
20istioctlutil "istio.io/istio/istioctl/pkg/util"21)
22
23func TestBadParse(t *testing.T) {24// unknown flags should be a command parse25rootCmd := GetRootCmd([]string{"--unknown-flag"})26fErr := rootCmd.Execute()27
28switch fErr.(type) {29case istioctlutil.CommandParseError:30// do nothing31default:32t.Errorf("Expected a CommandParseError, but got %q.", fErr)33}34
35// we should propagate to subcommands36rootCmd = GetRootCmd([]string{"analyze", "--unknown-flag"})37fErr = rootCmd.Execute()38
39switch fErr.(type) {40case istioctlutil.CommandParseError:41// do nothing42default:43t.Errorf("Expected a CommandParseError, but got %q.", fErr)44}45
46// all of the subcommands47rootCmd = GetRootCmd([]string{"x", "authz", "check", "--unknown-flag"})48fErr = rootCmd.Execute()49
50switch fErr.(type) {51case istioctlutil.CommandParseError:52// do nothing53default:54t.Errorf("Expected a CommandParseError, but got %q.", fErr)55}56}
57