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
63327647
Unverified
Commit
63327647
authored
Feb 02, 2017
by
Derek McQuay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubeadm: added tests for preflight checks
increased coverage from ~9% to ~71%
parent
8805a068
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
BUILD
cmd/kubeadm/app/preflight/BUILD
+1
-0
checks_test.go
cmd/kubeadm/app/preflight/checks_test.go
+59
-0
No files found.
cmd/kubeadm/app/preflight/BUILD
View file @
63327647
...
...
@@ -29,6 +29,7 @@ go_test(
srcs = ["checks_test.go"],
library = ":go_default_library",
tags = ["automanaged"],
deps = ["//cmd/kubeadm/app/apis/kubeadm:go_default_library"],
)
filegroup(
...
...
cmd/kubeadm/app/preflight/checks_test.go
View file @
63327647
...
...
@@ -20,6 +20,9 @@ import (
"bytes"
"fmt"
"testing"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmapi
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
)
type
preflightCheckTest
struct
{
...
...
@@ -36,6 +39,54 @@ func (pfct preflightCheckTest) Check() (warning, errors []error) {
return
}
func
TestRunInitMasterChecks
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
cfg
*
kubeadmapi
.
MasterConfiguration
expected
bool
}{
{
cfg
:
&
kubeadmapi
.
MasterConfiguration
{
API
:
kubeadm
.
API
{
AdvertiseAddresses
:
[]
string
{
"foo"
}},
},
expected
:
false
,
},
}
for
_
,
rt
:=
range
tests
{
actual
:=
RunInitMasterChecks
(
rt
.
cfg
)
if
(
actual
==
nil
)
!=
rt
.
expected
{
t
.
Errorf
(
"failed RunInitMasterChecks:
\n\t
expected: %t
\n\t
actual: %t"
,
rt
.
expected
,
(
actual
!=
nil
),
)
}
}
}
func
TestRunJoinNodeChecks
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
cfg
*
kubeadmapi
.
NodeConfiguration
expected
bool
}{
{
cfg
:
&
kubeadmapi
.
NodeConfiguration
{},
expected
:
false
,
},
}
for
_
,
rt
:=
range
tests
{
actual
:=
RunJoinNodeChecks
(
rt
.
cfg
)
if
(
actual
==
nil
)
!=
rt
.
expected
{
t
.
Errorf
(
"failed RunJoinNodeChecks:
\n\t
expected: %t
\n\t
actual: %t"
,
rt
.
expected
,
(
actual
!=
nil
),
)
}
}
}
func
TestRunChecks
(
t
*
testing
.
T
)
{
var
tokenTest
=
[]
struct
{
p
[]
Checker
...
...
@@ -46,6 +97,14 @@ func TestRunChecks(t *testing.T) {
{[]
Checker
{
preflightCheckTest
{
"warning"
}},
true
,
"[preflight] WARNING: warning
\n
"
},
// should just print warning
{[]
Checker
{
preflightCheckTest
{
"error"
}},
false
,
""
},
{[]
Checker
{
preflightCheckTest
{
"test"
}},
false
,
""
},
{[]
Checker
{
DirAvailableCheck
{
Path
:
"/does/not/exist"
}},
true
,
""
},
{[]
Checker
{
DirAvailableCheck
{
Path
:
"/"
}},
false
,
""
},
{[]
Checker
{
FileAvailableCheck
{
Path
:
"/does/not/exist"
}},
true
,
""
},
{[]
Checker
{
FileContentCheck
{
Path
:
"/does/not/exist"
}},
false
,
""
},
{[]
Checker
{
FileContentCheck
{
Path
:
"/"
}},
true
,
""
},
{[]
Checker
{
FileContentCheck
{
Path
:
"/"
,
Content
:
[]
byte
(
"does not exist"
)}},
false
,
""
},
{[]
Checker
{
InPathCheck
{
executable
:
"foobarbaz"
}},
true
,
"[preflight] WARNING: foobarbaz not found in system path
\n
"
},
{[]
Checker
{
InPathCheck
{
executable
:
"foobarbaz"
,
mandatory
:
true
}},
false
,
""
},
}
for
_
,
rt
:=
range
tokenTest
{
buf
:=
new
(
bytes
.
Buffer
)
...
...
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