-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
query_test.go added - TestValidate method defined
Validate funtion: removed unused arguments minor change: Copyright 2020 to Copyright 2021 Unnecessary comment is removed
- Loading branch information
1 parent
0fba843
commit 6cbbc42
Showing
2 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
|
||
}) | ||
} | ||
} |