Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
5510b4c9
Commit
5510b4c9
authored
Mar 08, 2018
by
Lubomir I. Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubeadm: add test coverage to completion.go
Included tests: - TestNewCmdCompletion - TestRunCompletion
parent
8303f8ec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
0 deletions
+97
-0
BUILD
cmd/kubeadm/app/cmd/BUILD
+2
-0
completion_test.go
cmd/kubeadm/app/cmd/completion_test.go
+95
-0
No files found.
cmd/kubeadm/app/cmd/BUILD
View file @
5510b4c9
...
...
@@ -81,6 +81,7 @@ go_library(
go_test(
name = "go_default_test",
srcs = [
"completion_test.go",
"join_test.go",
"reset_test.go",
"token_test.go",
...
...
@@ -95,6 +96,7 @@ go_test(
"//cmd/kubeadm/app/preflight:go_default_library",
"//pkg/api/legacyscheme:go_default_library",
"//vendor/github.com/ghodss/yaml:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
...
...
cmd/kubeadm/app/cmd/completion_test.go
0 → 100644
View file @
5510b4c9
/*
Copyright 2018 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.
*/
package
cmd
import
(
"bytes"
"testing"
"github.com/spf13/cobra"
)
const
shellsError
=
"Unexpected empty completion shells list"
func
TestNewCmdCompletion
(
t
*
testing
.
T
)
{
var
out
bytes
.
Buffer
shells
:=
GetSupportedShells
()
if
len
(
shells
)
==
0
{
t
.
Errorf
(
shellsError
)
}
// test NewCmdCompletion with a valid shell.
// use a dummy parent command as NewCmdCompletion needs it.
parentCmd
:=
&
cobra
.
Command
{}
args
:=
[]
string
{
"completion"
,
shells
[
0
]}
parentCmd
.
SetArgs
(
args
)
cmd
:=
NewCmdCompletion
(
&
out
,
""
)
parentCmd
.
AddCommand
(
cmd
)
if
err
:=
parentCmd
.
Execute
();
err
!=
nil
{
t
.
Errorf
(
"Cannot exectute NewCmdCompletion: %v"
,
err
)
}
}
func
TestRunCompletion
(
t
*
testing
.
T
)
{
var
out
bytes
.
Buffer
type
TestCase
struct
{
name
string
args
[]
string
expectedError
bool
}
testCases
:=
[]
TestCase
{
{
name
:
"invalid: missing argument"
,
args
:
[]
string
{},
expectedError
:
true
,
},
{
name
:
"invalid: too many arguments"
,
args
:
[]
string
{
""
,
""
},
expectedError
:
true
,
},
{
name
:
"invalid: unsupported shell name"
,
args
:
[]
string
{
"unsupported"
},
expectedError
:
true
,
},
}
// test all supported shells
shells
:=
GetSupportedShells
()
if
len
(
shells
)
==
0
{
t
.
Errorf
(
shellsError
)
}
for
_
,
shell
:=
range
shells
{
test
:=
TestCase
{
name
:
"valid: test shell "
+
shell
,
args
:
[]
string
{
shell
},
}
testCases
=
append
(
testCases
,
test
)
}
// use dummy cobra commands
parentCmd
:=
&
cobra
.
Command
{}
cmd
:=
&
cobra
.
Command
{}
parentCmd
.
AddCommand
(
cmd
)
for
_
,
tc
:=
range
testCases
{
if
err
:=
RunCompletion
(
&
out
,
""
,
cmd
,
tc
.
args
);
(
err
!=
nil
)
!=
tc
.
expectedError
{
t
.
Errorf
(
"Test case %q: TestRunCompletion expected error: %v, saw: %v"
,
tc
.
name
,
tc
.
expectedError
,
(
err
!=
nil
))
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment