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
b0803c16
Commit
b0803c16
authored
Mar 01, 2018
by
Lubomir I. Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubeadm: add better test coverage to version.go
add the following tests in the new file version_test.go: - TestNewCmdVersion() - TestRunVersion()
parent
ae1fc13a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
0 deletions
+98
-0
BUILD
cmd/kubeadm/app/cmd/BUILD
+2
-0
version_test.go
cmd/kubeadm/app/cmd/version_test.go
+96
-0
No files found.
cmd/kubeadm/app/cmd/BUILD
View file @
b0803c16
...
@@ -82,12 +82,14 @@ go_test(
...
@@ -82,12 +82,14 @@ go_test(
srcs = [
srcs = [
"reset_test.go",
"reset_test.go",
"token_test.go",
"token_test.go",
"version_test.go",
],
],
embed = [":go_default_library"],
embed = [":go_default_library"],
deps = [
deps = [
"//cmd/kubeadm/app/apis/kubeadm/v1alpha1:go_default_library",
"//cmd/kubeadm/app/apis/kubeadm/v1alpha1:go_default_library",
"//cmd/kubeadm/app/constants:go_default_library",
"//cmd/kubeadm/app/constants:go_default_library",
"//cmd/kubeadm/app/preflight:go_default_library",
"//cmd/kubeadm/app/preflight:go_default_library",
"//vendor/github.com/ghodss/yaml:go_default_library",
"//vendor/k8s.io/api/core/v1: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/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
...
...
cmd/kubeadm/app/cmd/version_test.go
0 → 100644
View file @
b0803c16
/*
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"
"encoding/json"
"fmt"
"github.com/ghodss/yaml"
"testing"
)
func
TestNewCmdVersion
(
t
*
testing
.
T
)
{
var
buf
bytes
.
Buffer
cmd
:=
NewCmdVersion
(
&
buf
)
if
err
:=
cmd
.
Execute
();
err
!=
nil
{
t
.
Errorf
(
"Cannot execute version command: %v"
,
err
)
}
}
func
TestRunVersion
(
t
*
testing
.
T
)
{
var
buf
bytes
.
Buffer
iface
:=
make
(
map
[
string
]
interface
{})
flagNameOutput
:=
"output"
cmd
:=
NewCmdVersion
(
&
buf
)
testCases
:=
[]
struct
{
name
string
flag
string
expectedError
bool
shouldBeValidYAML
bool
shouldBeValidJSON
bool
}{
{
name
:
"valid: run without flags"
,
},
{
name
:
"valid: run with flag 'short'"
,
flag
:
"short"
,
},
{
name
:
"valid: run with flag 'yaml'"
,
flag
:
"yaml"
,
shouldBeValidYAML
:
true
,
},
{
name
:
"valid: run with flag 'json'"
,
flag
:
"json"
,
shouldBeValidJSON
:
true
,
},
{
name
:
"invalid: run with unsupported flag"
,
flag
:
"unsupported-flag"
,
expectedError
:
true
,
},
}
for
_
,
tc
:=
range
testCases
{
var
err
error
if
len
(
tc
.
flag
)
>
0
{
if
err
=
cmd
.
Flags
()
.
Set
(
flagNameOutput
,
tc
.
flag
);
err
!=
nil
{
goto
error
}
}
buf
.
Reset
()
if
err
=
RunVersion
(
&
buf
,
cmd
);
err
!=
nil
{
goto
error
}
if
buf
.
String
()
==
""
{
err
=
fmt
.
Errorf
(
"empty output"
)
goto
error
}
if
tc
.
shouldBeValidYAML
{
err
=
yaml
.
Unmarshal
(
buf
.
Bytes
(),
&
iface
)
}
else
if
tc
.
shouldBeValidJSON
{
err
=
json
.
Unmarshal
(
buf
.
Bytes
(),
&
iface
)
}
error
:
if
(
err
!=
nil
)
!=
tc
.
expectedError
{
t
.
Errorf
(
"Test case %q: RunVersion expected error: %v, saw: %v; %v"
,
tc
.
name
,
tc
.
expectedError
,
err
!=
nil
,
err
)
}
}
}
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