istio.io/istio@v0.0.0-20240520182934-d79c90f27776/istioctl/pkg/authz/authz_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 authz
    16  
    17  import (
    18  	"fmt"
    19  	"strings"
    20  	"testing"
    21  
    22  	"istio.io/istio/istioctl/pkg/cli"
    23  	"istio.io/istio/istioctl/pkg/util/testutil"
    24  )
    25  
    26  func TestAuthz(t *testing.T) {
    27  	cases := []testutil.TestCase{
    28  		{
    29  			Args:           []string{"-f fake.yaml"},
    30  			ExpectedOutput: "Error: failed to get config dump from file  fake.yaml: open  fake.yaml: no such file or directory\n",
    31  			WantException:  true,
    32  		},
    33  		{
    34  			Args: []string{"-f", "testdata/configdump.yaml"},
    35  			ExpectedOutput: `ACTION   AuthorizationPolicy         RULES
    36  ALLOW    _anonymous_match_nothing_   1
    37  ALLOW    httpbin.default             1
    38  `,
    39  		},
    40  	}
    41  
    42  	authzCmd := checkCmd(cli.NewFakeContext(&cli.NewFakeContextOption{}))
    43  	for i, c := range cases {
    44  		t.Run(fmt.Sprintf("case %d %s", i, strings.Join(c.Args, " ")), func(t *testing.T) {
    45  			testutil.VerifyOutput(t, authzCmd, c)
    46  		})
    47  	}
    48  }