From 44c0f1a04db7d1d5fe2f965e9eba884ce3e7d1d5 Mon Sep 17 00:00:00 2001 From: VaibhavMalik4187 Date: Sun, 11 Feb 2024 15:44:54 +0530 Subject: [PATCH] Added tests for the vtaclcheck/cli package This commit introduces new tests for the `go/cmd/vtaclcheck/cli` package. Signed-off-by: VaibhavMalik4187 --- go/cmd/vtaclcheck/cli/vtactlcheck_test.go | 73 +++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 go/cmd/vtaclcheck/cli/vtactlcheck_test.go diff --git a/go/cmd/vtaclcheck/cli/vtactlcheck_test.go b/go/cmd/vtaclcheck/cli/vtactlcheck_test.go new file mode 100644 index 00000000000..30bb76e021b --- /dev/null +++ b/go/cmd/vtaclcheck/cli/vtactlcheck_test.go @@ -0,0 +1,73 @@ +/* +Copyright 2024 The Vitess Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cli + +import ( + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/require" +) + +func TestRun(t *testing.T) { + tests := []struct { + name string + aclFile string + staticAuthFile string + expectErr bool + }{ + { + name: "no options specified", + expectErr: true, + }, + { + name: "valid acl file", + aclFile: "../tableacl1.json", + }, + { + name: "valid acl file", + aclFile: "../tableacl2.json", + }, + { + name: "bad acl file", + aclFile: "../tableacl_bad.json", + expectErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + oldAclFile := aclFile + oldStaticAuthFile := staticAuthFile + + defer func() { + aclFile = oldAclFile + staticAuthFile = oldStaticAuthFile + }() + + aclFile = tt.aclFile + staticAuthFile = tt.staticAuthFile + + err := Main.RunE(&cobra.Command{}, []string{}) + if tt.expectErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +}