Skip to content

Commit

Permalink
query_test.go added - TestValidate method defined
Browse files Browse the repository at this point in the history
Validate funtion: removed unused arguments

minor change: Copyright 2020 to Copyright 2021

Unnecessary comment is removed
  • Loading branch information
Shekharrajak committed Jan 26, 2021
1 parent 0fba843 commit 6cbbc42
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/kepctl/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ type QueryOpts struct {
Output string
}

// Validate checks the args and cleans them up if needed
func (c *QueryOpts) Validate(args []string) error {

func (c *QueryOpts) Validate() error {
if len(c.SIG) > 0 {
sigs, err := selectByRegexp(util.Groups(), c.SIG)
if err != nil {
Expand Down
89 changes: 89 additions & 0 deletions pkg/kepctl/query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
Copyright 2021 The Kubernetes 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.
*/

/*
TO run the test case: go test -v query_test.go create.go kepctl.go promote.go query.go
*/

package kepctl

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)


func TestValidate(t *testing.T) {
testcases := []struct {
name string
queryOpts QueryOpts
err error
}{
{
name: "Valid SIG",
queryOpts: QueryOpts{
CommonArgs: CommonArgs {
Name: "1011-test",
},
SIG: []string{"sig-multicluster"},
IncludePRs: true,
Output: "json",
},
err: nil,
},
{
name: "Invalid SIG",
queryOpts: QueryOpts{
CommonArgs: CommonArgs {
Name: "1011-test-xyz",
},
SIG: []string{"sig-xyz"},
IncludePRs: true,
Output: "json",
},
err: fmt.Errorf("No SIG matches any of the passed regular expressions"),
},
{
name: "Unsupported Output format",
queryOpts: QueryOpts{
CommonArgs: CommonArgs {
Name: "1011-test-testing",
},
SIG: []string{"sig-testing"},
IncludePRs: true,
Output: "PDF",
},
err: fmt.Errorf("unsupported output format: PDF. Valid values: [table json yaml]"),
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
var queryOpts = tc.queryOpts
var err = queryOpts.Validate()
if tc.err == nil {
assert.NoError(t, err)
} else {
assert.EqualError(t, err, tc.err.Error())
}

})
}
}

0 comments on commit 6cbbc42

Please sign in to comment.