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
9a4a69aa
Commit
9a4a69aa
authored
Oct 27, 2017
by
tianshapjq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new testcases to util.go
parent
52d87de1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
0 deletions
+117
-0
BUILD
pkg/api/v1/pod/BUILD
+1
-0
util_test.go
pkg/api/v1/pod/util_test.go
+116
-0
No files found.
pkg/api/v1/pod/BUILD
View file @
9a4a69aa
...
@@ -23,6 +23,7 @@ go_test(
...
@@ -23,6 +23,7 @@ go_test(
importpath = "k8s.io/kubernetes/pkg/api/v1/pod",
importpath = "k8s.io/kubernetes/pkg/api/v1/pod",
library = ":go_default_library",
library = ":go_default_library",
deps = [
deps = [
"//vendor/github.com/stretchr/testify/assert: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/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
...
...
pkg/api/v1/pod/util_test.go
View file @
9a4a69aa
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"testing"
"testing"
"time"
"time"
"github.com/stretchr/testify/assert"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/intstr"
...
@@ -404,3 +405,118 @@ func TestIsPodAvailable(t *testing.T) {
...
@@ -404,3 +405,118 @@ func TestIsPodAvailable(t *testing.T) {
}
}
}
}
}
}
func
TestGetContainerStatus
(
t
*
testing
.
T
)
{
type
ExpectedStruct
struct
{
status
v1
.
ContainerStatus
exists
bool
}
tests
:=
[]
struct
{
status
[]
v1
.
ContainerStatus
name
string
expected
ExpectedStruct
desc
string
}{
{
status
:
[]
v1
.
ContainerStatus
{{
Name
:
"test1"
,
Ready
:
false
,
Image
:
"image1"
},
{
Name
:
"test2"
,
Ready
:
true
,
Image
:
"image1"
}},
name
:
"test1"
,
expected
:
ExpectedStruct
{
status
:
v1
.
ContainerStatus
{
Name
:
"test1"
,
Ready
:
false
,
Image
:
"image1"
},
exists
:
true
},
desc
:
"retrieve ContainerStatus with Name=
\"
test1
\"
"
,
},
{
status
:
[]
v1
.
ContainerStatus
{{
Name
:
"test2"
,
Ready
:
false
,
Image
:
"image2"
}},
name
:
"test1"
,
expected
:
ExpectedStruct
{
status
:
v1
.
ContainerStatus
{},
exists
:
false
},
desc
:
"no matching ContainerStatus with Name=
\"
test1
\"
"
,
},
{
status
:
[]
v1
.
ContainerStatus
{{
Name
:
"test3"
,
Ready
:
false
,
Image
:
"image3"
}},
name
:
""
,
expected
:
ExpectedStruct
{
status
:
v1
.
ContainerStatus
{},
exists
:
false
},
desc
:
"retrieve an empty ContainerStatus with contianer name empty"
,
},
{
status
:
nil
,
name
:
""
,
expected
:
ExpectedStruct
{
status
:
v1
.
ContainerStatus
{},
exists
:
false
},
desc
:
"retrieve an empty ContainerStatus with status nil"
,
},
}
for
_
,
test
:=
range
tests
{
resultStatus
,
exists
:=
GetContainerStatus
(
test
.
status
,
test
.
name
)
assert
.
Equal
(
t
,
test
.
expected
.
status
,
resultStatus
,
"GetContainerStatus: "
+
test
.
desc
)
assert
.
Equal
(
t
,
test
.
expected
.
exists
,
exists
,
"GetContainerStatus: "
+
test
.
desc
)
resultStatus
=
GetExistingContainerStatus
(
test
.
status
,
test
.
name
)
assert
.
Equal
(
t
,
test
.
expected
.
status
,
resultStatus
,
"GetExistingContainerStatus: "
+
test
.
desc
)
}
}
func
TestUpdatePodCondition
(
t
*
testing
.
T
)
{
time
:=
metav1
.
Now
()
podStatus
:=
v1
.
PodStatus
{
Conditions
:
[]
v1
.
PodCondition
{
{
Type
:
v1
.
PodReady
,
Status
:
v1
.
ConditionTrue
,
Reason
:
"successfully"
,
Message
:
"sync pod successfully"
,
LastProbeTime
:
time
,
LastTransitionTime
:
metav1
.
NewTime
(
time
.
Add
(
1000
)),
},
},
}
tests
:=
[]
struct
{
status
*
v1
.
PodStatus
conditions
v1
.
PodCondition
expected
bool
desc
string
}{
{
status
:
&
podStatus
,
conditions
:
v1
.
PodCondition
{
Type
:
v1
.
PodReady
,
Status
:
v1
.
ConditionTrue
,
Reason
:
"successfully"
,
Message
:
"sync pod successfully"
,
LastProbeTime
:
time
,
LastTransitionTime
:
metav1
.
NewTime
(
time
.
Add
(
1000
))},
expected
:
false
,
desc
:
"all equal, no update"
,
},
{
status
:
&
podStatus
,
conditions
:
v1
.
PodCondition
{
Type
:
v1
.
PodScheduled
,
Status
:
v1
.
ConditionTrue
,
Reason
:
"successfully"
,
Message
:
"sync pod successfully"
,
LastProbeTime
:
time
,
LastTransitionTime
:
metav1
.
NewTime
(
time
.
Add
(
1000
))},
expected
:
true
,
desc
:
"not equal Type, should get updated"
,
},
{
status
:
&
podStatus
,
conditions
:
v1
.
PodCondition
{
Type
:
v1
.
PodReady
,
Status
:
v1
.
ConditionFalse
,
Reason
:
"successfully"
,
Message
:
"sync pod successfully"
,
LastProbeTime
:
time
,
LastTransitionTime
:
metav1
.
NewTime
(
time
.
Add
(
1000
))},
expected
:
true
,
desc
:
"not equal Status, should get updated"
,
},
}
for
_
,
test
:=
range
tests
{
var
resultStatus
bool
resultStatus
=
UpdatePodCondition
(
test
.
status
,
&
test
.
conditions
)
assert
.
Equal
(
t
,
test
.
expected
,
resultStatus
,
test
.
desc
)
}
}
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