istio.io/istio@v0.0.0-20240520182934-d79c90f27776/istioctl/pkg/config/config_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 config
    16  
    17  import (
    18  	"fmt"
    19  	"strings"
    20  	"testing"
    21  
    22  	"github.com/spf13/viper"
    23  
    24  	"istio.io/istio/istioctl/pkg/util/testutil"
    25  	"istio.io/istio/pkg/config/constants"
    26  )
    27  
    28  func TestConfigList(t *testing.T) {
    29  	cases := []testutil.TestCase{
    30  		//{ // case 0
    31  		//	Args:           strings.Split("get istioNamespace", " "),
    32  		//	ExpectedRegexp: regexp.MustCompile("Configure istioctl defaults"),
    33  		//	WantException:  false,
    34  		//},
    35  		{ // case 1
    36  			Args: strings.Split("list", " "),
    37  			ExpectedOutput: `FLAG                    VALUE            FROM
    38  authority                                default
    39  cert-dir                                 default
    40  insecure                                 default
    41  istioNamespace          istio-system     default
    42  plaintext                                default
    43  prefer-experimental                      default
    44  xds-address                              default
    45  xds-port                15012            default
    46  `,
    47  			WantException: false,
    48  		},
    49  	}
    50  
    51  	for i, c := range cases {
    52  		t.Run(fmt.Sprintf("case %d %s", i, strings.Join(c.Args, " ")), func(t *testing.T) {
    53  			testutil.VerifyOutput(t, Cmd(), c)
    54  		})
    55  	}
    56  }
    57  
    58  func init() {
    59  	viper.SetDefault("istioNamespace", constants.IstioSystemNamespace)
    60  	viper.SetDefault("xds-port", 15012)
    61  }