Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for the vtaclcheck/cli package #15203

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions go/cmd/vtaclcheck/cli/vtactlcheck_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
Loading