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
a5919a93
Unverified
Commit
a5919a93
authored
Oct 21, 2016
by
Derek McQuay
Committed by
Paulo Pires
Oct 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubeadm: added unit test for app/preflight pkg
parent
569da522
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
5 deletions
+73
-5
checks.go
cmd/kubeadm/app/preflight/checks.go
+5
-5
checks_test.go
cmd/kubeadm/app/preflight/checks_test.go
+68
-0
No files found.
cmd/kubeadm/app/preflight/checks.go
View file @
a5919a93
...
...
@@ -200,7 +200,7 @@ func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error {
InPathCheck
{
executable
:
"touch"
,
mandatory
:
false
},
}
return
runChecks
(
checks
)
return
runChecks
(
checks
,
os
.
Stderr
)
}
func
RunJoinNodeChecks
()
error
{
...
...
@@ -223,7 +223,7 @@ func RunJoinNodeChecks() error {
InPathCheck
{
executable
:
"touch"
,
mandatory
:
false
},
}
return
runChecks
(
checks
)
return
runChecks
(
checks
,
os
.
Stderr
)
}
func
RunResetCheck
()
error
{
...
...
@@ -231,17 +231,17 @@ func RunResetCheck() error {
IsRootCheck
{
root
:
true
},
}
return
runChecks
(
checks
)
return
runChecks
(
checks
,
os
.
Stderr
)
}
// runChecks runs each check, displays it's warnings/errors, and once all
// are processed will exit if any errors occurred.
func
runChecks
(
checks
[]
PreFlightCheck
)
error
{
func
runChecks
(
checks
[]
PreFlightCheck
,
ww
io
.
Writer
)
error
{
found
:=
[]
error
{}
for
_
,
c
:=
range
checks
{
warnings
,
errs
:=
c
.
Check
()
for
_
,
w
:=
range
warnings
{
fmt
.
Printf
(
"WARNING: %s
\n
"
,
w
)
io
.
WriteString
(
ww
,
fmt
.
Sprintf
(
"WARNING: %s
\n
"
,
w
)
)
}
for
_
,
e
:=
range
errs
{
found
=
append
(
found
,
e
)
...
...
cmd/kubeadm/app/preflight/checks_test.go
0 → 100644
View file @
a5919a93
/*
Copyright 2016 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
preflight
import
(
"bytes"
"fmt"
"testing"
)
type
preflightCheckTest
struct
{
msg
string
}
func
(
pfct
preflightCheckTest
)
Check
()
(
warning
,
errors
[]
error
)
{
if
pfct
.
msg
==
"warning"
{
return
[]
error
{
fmt
.
Errorf
(
"warning"
)},
nil
}
if
pfct
.
msg
!=
""
{
return
nil
,
[]
error
{
fmt
.
Errorf
(
"fake error"
)}
}
return
}
func
TestRunChecks
(
t
*
testing
.
T
)
{
var
tokenTest
=
[]
struct
{
p
[]
PreFlightCheck
expected
bool
output
string
}{
{[]
PreFlightCheck
{},
true
,
""
},
{[]
PreFlightCheck
{
preflightCheckTest
{
"warning"
}},
true
,
"WARNING: warning
\n
"
},
// should just print warning
{[]
PreFlightCheck
{
preflightCheckTest
{
"error"
}},
false
,
""
},
{[]
PreFlightCheck
{
preflightCheckTest
{
"test"
}},
false
,
""
},
}
for
_
,
rt
:=
range
tokenTest
{
buf
:=
new
(
bytes
.
Buffer
)
actual
:=
runChecks
(
rt
.
p
,
buf
)
if
(
actual
==
nil
)
!=
rt
.
expected
{
t
.
Errorf
(
"failed runChecks:
\n\t
expected: %t
\n\t
actual: %t"
,
rt
.
expected
,
(
actual
==
nil
),
)
}
if
buf
.
String
()
!=
rt
.
output
{
t
.
Errorf
(
"failed runChecks:
\n\t
expected: %s
\n\t
actual: %s"
,
rt
.
output
,
buf
.
String
(),
)
}
}
}
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