mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 15:58:37 +00:00
Merge pull request #41680 from gyliu513/pod-update
Automatic merge from submit-queue (batch tested with PRs 48425, 41680, 48457, 48619, 48635) Improved code coverage for pkg/kubelet/types/pod_update The test coverage for pod_update.go was imprved from 36% to 100%. **What this PR does / why we need it**: This fixed part of #40780 **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note ```
This commit is contained in:
commit
2a23d8bb43
@ -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",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -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:\nexpected: %v\nactual: %v for test[%d] with Annotations: %v",
|
||||
data.expected, actual, i, data.pod.Annotations)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user