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
6144b491
Commit
6144b491
authored
May 15, 2015
by
Prashanth B
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8336 from brendandburns/kubectl
Add a test for status message generation.
parents
c4fa7850
a197b24f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
2 deletions
+108
-2
resource_printer.go
pkg/kubectl/resource_printer.go
+6
-2
resource_printer_test.go
pkg/kubectl/resource_printer_test.go
+102
-0
No files found.
pkg/kubectl/resource_printer.go
View file @
6144b491
...
@@ -364,7 +364,7 @@ func interpretContainerStatus(status *api.ContainerStatus) (string, string, stri
...
@@ -364,7 +364,7 @@ func interpretContainerStatus(status *api.ContainerStatus) (string, string, stri
if
state
!=
nil
{
if
state
!=
nil
{
message
=
fmt
.
Sprintf
(
"exit code %d"
,
state
.
ExitCode
)
message
=
fmt
.
Sprintf
(
"exit code %d"
,
state
.
ExitCode
)
if
state
.
Reason
!=
""
{
if
state
.
Reason
!=
""
{
message
=
fmt
.
Sprintf
(
"%s, reason: %s"
,
state
.
Reason
)
message
=
fmt
.
Sprintf
(
"%s, reason: %s"
,
message
,
state
.
Reason
)
}
}
}
}
return
message
return
message
...
@@ -380,7 +380,11 @@ func interpretContainerStatus(status *api.ContainerStatus) (string, string, stri
...
@@ -380,7 +380,11 @@ func interpretContainerStatus(status *api.ContainerStatus) (string, string, stri
if
message
!=
""
{
if
message
!=
""
{
message
=
"last termination: "
+
message
message
=
"last termination: "
+
message
}
}
return
"Running"
,
translateTimestamp
(
state
.
Running
.
StartedAt
),
message
,
nil
stateMsg
:=
"Running"
if
!
status
.
Ready
{
stateMsg
=
stateMsg
+
" *not ready*"
}
return
stateMsg
,
translateTimestamp
(
state
.
Running
.
StartedAt
),
message
,
nil
}
else
if
state
.
Termination
!=
nil
{
}
else
if
state
.
Termination
!=
nil
{
return
"Terminated"
,
translateTimestamp
(
state
.
Termination
.
StartedAt
),
getTermMsg
(
state
.
Termination
),
nil
return
"Terminated"
,
translateTimestamp
(
state
.
Termination
.
StartedAt
),
getTermMsg
(
state
.
Termination
),
nil
}
}
...
...
pkg/kubectl/resource_printer_test.go
View file @
6144b491
...
@@ -756,3 +756,105 @@ func TestPrintHumanReadableService(t *testing.T) {
...
@@ -756,3 +756,105 @@ func TestPrintHumanReadableService(t *testing.T) {
}
}
}
}
}
}
func
TestInterpretContainerStatus
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
status
*
api
.
ContainerStatus
expectedState
string
expectedMessage
string
expectErr
bool
name
string
}{
{
status
:
&
api
.
ContainerStatus
{
State
:
api
.
ContainerState
{
Running
:
&
api
.
ContainerStateRunning
{},
},
Ready
:
true
,
},
expectedState
:
"Running"
,
expectedMessage
:
""
,
name
:
"basic"
,
},
{
status
:
&
api
.
ContainerStatus
{
State
:
api
.
ContainerState
{
Running
:
&
api
.
ContainerStateRunning
{},
},
Ready
:
false
,
},
expectedState
:
"Running *not ready*"
,
expectedMessage
:
""
,
name
:
"basic not ready"
,
},
{
status
:
&
api
.
ContainerStatus
{
State
:
api
.
ContainerState
{
Waiting
:
&
api
.
ContainerStateWaiting
{},
},
Ready
:
false
,
},
expectedState
:
"Waiting"
,
expectedMessage
:
""
,
name
:
"waiting not ready"
,
},
{
status
:
&
api
.
ContainerStatus
{
State
:
api
.
ContainerState
{
Waiting
:
&
api
.
ContainerStateWaiting
{},
},
Ready
:
true
,
},
expectedState
:
"Waiting"
,
expectedMessage
:
""
,
name
:
"waiting"
,
},
{
status
:
&
api
.
ContainerStatus
{
State
:
api
.
ContainerState
{
Termination
:
&
api
.
ContainerStateTerminated
{
ExitCode
:
3
,
},
},
Ready
:
false
,
},
expectedState
:
"Terminated"
,
expectedMessage
:
"exit code 3"
,
name
:
"terminated not ready"
,
},
{
status
:
&
api
.
ContainerStatus
{
State
:
api
.
ContainerState
{
Termination
:
&
api
.
ContainerStateTerminated
{
ExitCode
:
5
,
Reason
:
"test reason"
,
},
},
Ready
:
true
,
},
expectedState
:
"Terminated"
,
expectedMessage
:
"exit code 5, reason: test reason"
,
name
:
"terminated"
,
},
}
for
_
,
test
:=
range
tests
{
// TODO: test timestamp printing.
state
,
_
,
msg
,
err
:=
interpretContainerStatus
(
test
.
status
)
if
test
.
expectErr
&&
err
==
nil
{
t
.
Errorf
(
"unexpected non-error (%s)"
,
test
.
name
)
continue
}
if
!
test
.
expectErr
&&
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v (%s)"
,
err
,
test
.
name
)
continue
}
if
state
!=
test
.
expectedState
{
t
.
Errorf
(
"expected: %s, got: %s"
,
test
.
expectedState
,
state
)
}
if
msg
!=
test
.
expectedMessage
{
t
.
Errorf
(
"expected: %s, got: %s"
,
test
.
expectedMessage
,
msg
)
}
}
}
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