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
9ca1351e
Commit
9ca1351e
authored
Feb 18, 2017
by
Guangya Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved code coverage for pkg/kubelet/types/pod_update
The test coverage for pod_update.go was imprved from 36% to 100%.
parent
b66be981
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
0 deletions
+135
-0
BUILD
pkg/kubelet/types/BUILD
+1
-0
pod_update_test.go
pkg/kubelet/types/pod_update_test.go
+134
-0
No files found.
pkg/kubelet/types/BUILD
View file @
9ca1351e
...
...
@@ -38,6 +38,7 @@ go_test(
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/github.com/stretchr/testify/require:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
],
)
...
...
pkg/kubelet/types/pod_update_test.go
View file @
9ca1351e
...
...
@@ -19,7 +19,10 @@ package types
import
(
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
)
func
TestGetValidatedSources
(
t
*
testing
.
T
)
{
...
...
@@ -42,3 +45,134 @@ func TestGetValidatedSources(t *testing.T) {
sources
,
err
=
GetValidatedSources
([]
string
{
"taco"
})
require
.
Error
(
t
,
err
)
}
func
TestGetPodSource
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
pod
v1
.
Pod
expected
string
errExpected
bool
}{
{
pod
:
v1
.
Pod
{},
expected
:
""
,
errExpected
:
true
,
},
{
pod
:
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"kubernetes.io/config.source"
:
"host-ipc-sources"
,
},
},
},
expected
:
"host-ipc-sources"
,
errExpected
:
false
,
},
}
for
i
,
data
:=
range
cases
{
source
,
err
:=
GetPodSource
(
&
data
.
pod
)
if
data
.
errExpected
{
assert
.
Error
(
t
,
err
)
}
else
{
assert
.
NoError
(
t
,
err
)
}
assert
.
Equal
(
t
,
data
.
expected
,
source
,
"test[%d]"
,
i
)
t
.
Logf
(
"Test case [%d]"
,
i
)
}
}
func
TestString
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
sp
SyncPodType
expected
string
}{
{
sp
:
SyncPodCreate
,
expected
:
"create"
,
},
{
sp
:
SyncPodUpdate
,
expected
:
"update"
,
},
{
sp
:
SyncPodSync
,
expected
:
"sync"
,
},
{
sp
:
SyncPodKill
,
expected
:
"kill"
,
},
{
sp
:
50
,
expected
:
"unknown"
,
},
}
for
i
,
data
:=
range
cases
{
syncPodString
:=
data
.
sp
.
String
()
assert
.
Equal
(
t
,
data
.
expected
,
syncPodString
,
"test[%d]"
,
i
)
t
.
Logf
(
"Test case [%d]"
,
i
)
}
}
func
TestIsCriticalPod
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
pod
v1
.
Pod
expected
bool
}{
{
pod
:
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pod1"
,
Namespace
:
"ns"
,
Annotations
:
map
[
string
]
string
{
"scheduler.alpha.kubernetes.io/critical-pod"
:
""
,
},
},
},
expected
:
false
,
},
{
pod
:
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pod2"
,
Namespace
:
"ns"
,
Annotations
:
map
[
string
]
string
{
"scheduler.alpha.kubernetes.io/critical-pod"
:
"abc"
,
},
},
},
expected
:
false
,
},
{
pod
:
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pod3"
,
Namespace
:
"kube-system"
,
Annotations
:
map
[
string
]
string
{
"scheduler.alpha.kubernetes.io/critical-pod"
:
"abc"
,
},
},
},
expected
:
false
,
},
{
pod
:
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pod3"
,
Namespace
:
"kube-system"
,
Annotations
:
map
[
string
]
string
{
"scheduler.alpha.kubernetes.io/critical-pod"
:
""
,
},
},
},
expected
:
true
,
},
}
for
i
,
data
:=
range
cases
{
actual
:=
IsCriticalPod
(
&
data
.
pod
)
if
actual
!=
data
.
expected
{
t
.
Errorf
(
"IsCriticalPod result wrong:
\n
expected: %v
\n
actual: %v for test[%d] with Annotations: %v"
,
data
.
expected
,
actual
,
i
,
data
.
pod
.
Annotations
)
}
}
}
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