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
daea190b
Unverified
Commit
daea190b
authored
Nov 09, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 09, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70753 from logicalhan/healthz-test
fix healthz checkerNames test so that it tests against the expected output
parents
c3d05c81
0623f630
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
11 deletions
+39
-11
healthz.go
staging/src/k8s.io/apiserver/pkg/server/healthz/healthz.go
+16
-10
healthz_test.go
...g/src/k8s.io/apiserver/pkg/server/healthz/healthz_test.go
+23
-1
No files found.
staging/src/k8s.io/apiserver/pkg/server/healthz/healthz.go
View file @
daea190b
...
...
@@ -112,7 +112,7 @@ func InstallPathHandler(mux mux, path string, checks ...HealthzChecker) {
checks
=
[]
HealthzChecker
{
PingHealthz
}
}
glog
.
V
(
5
)
.
Info
(
"Installing healthz checkers:"
,
strings
.
Join
(
checkerNames
(
checks
...
),
", "
))
glog
.
V
(
5
)
.
Info
(
"Installing healthz checkers:"
,
formatQuoted
(
checkerNames
(
checks
...
)
...
))
mux
.
Handle
(
path
,
handleRootHealthz
(
checks
...
))
for
_
,
check
:=
range
checks
{
...
...
@@ -187,14 +187,20 @@ func adaptCheckToHandler(c func(r *http.Request) error) http.HandlerFunc {
// checkerNames returns the names of the checks in the same order as passed in.
func
checkerNames
(
checks
...
HealthzChecker
)
[]
string
{
if
len
(
checks
)
>
0
{
// accumulate the names of checks for printing them out.
checkerNames
:=
make
([]
string
,
0
,
len
(
checks
))
for
_
,
check
:=
range
checks
{
// quote the Name so we can disambiguate
checkerNames
=
append
(
checkerNames
,
fmt
.
Sprintf
(
"%q"
,
check
.
Name
()))
}
return
checkerNames
// accumulate the names of checks for printing them out.
checkerNames
:=
make
([]
string
,
0
,
len
(
checks
))
for
_
,
check
:=
range
checks
{
checkerNames
=
append
(
checkerNames
,
check
.
Name
())
}
return
nil
return
checkerNames
}
// formatQuoted returns a formatted string of the health check names,
// preserving the order passed in.
func
formatQuoted
(
names
...
string
)
string
{
quoted
:=
make
([]
string
,
0
,
len
(
names
))
for
_
,
name
:=
range
names
{
quoted
=
append
(
quoted
,
fmt
.
Sprintf
(
"%q"
,
name
))
}
return
strings
.
Join
(
quoted
,
","
)
}
staging/src/k8s.io/apiserver/pkg/server/healthz/healthz_test.go
View file @
daea190b
...
...
@@ -148,10 +148,32 @@ func TestCheckerNames(t *testing.T) {
for
_
,
tc
:=
range
testCases
{
result
:=
checkerNames
(
tc
.
have
...
)
t
.
Run
(
tc
.
desc
,
func
(
t
*
testing
.
T
)
{
if
reflect
.
DeepEqual
(
tc
.
want
,
result
)
{
if
!
reflect
.
DeepEqual
(
tc
.
want
,
result
)
{
t
.
Errorf
(
"want %#v, got %#v"
,
tc
.
want
,
result
)
}
})
}
}
func
TestFormatQuoted
(
t
*
testing
.
T
)
{
n1
:=
"n1"
n2
:=
"n2"
testCases
:=
[]
struct
{
desc
string
names
[]
string
expected
string
}{
{
"empty"
,
[]
string
{},
""
},
{
"single name"
,
[]
string
{
n1
},
"
\"
n1
\"
"
},
{
"two names"
,
[]
string
{
n1
,
n2
},
"
\"
n1
\"
,
\"
n2
\"
"
},
{
"two names, reverse order"
,
[]
string
{
n2
,
n1
},
"
\"
n2
\"
,
\"
n1
\"
"
},
}
for
_
,
tc
:=
range
testCases
{
result
:=
formatQuoted
(
tc
.
names
...
)
t
.
Run
(
tc
.
desc
,
func
(
t
*
testing
.
T
)
{
if
result
!=
tc
.
expected
{
t
.
Errorf
(
"expected %#v, got %#v"
,
tc
.
expected
,
result
)
}
})
}
}
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