mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #116931 from my-git9/CreateListener-ut
[ut] increase covrage for kubelet/prober/results
This commit is contained in:
commit
af18989486
@ -21,7 +21,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"k8s.io/api/core/v1"
|
|
||||||
|
corev1 "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/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||||
@ -36,7 +37,7 @@ func TestCacheOperations(t *testing.T) {
|
|||||||
_, found := m.Get(unsetID)
|
_, found := m.Get(unsetID)
|
||||||
assert.False(t, found, "unset result found")
|
assert.False(t, found, "unset result found")
|
||||||
|
|
||||||
m.Set(setID, Success, &v1.Pod{})
|
m.Set(setID, Success, &corev1.Pod{})
|
||||||
result, found := m.Get(setID)
|
result, found := m.Get(setID)
|
||||||
assert.True(t, result == Success, "set result")
|
assert.True(t, result == Success, "set result")
|
||||||
assert.True(t, found, "set result found")
|
assert.True(t, found, "set result found")
|
||||||
@ -49,7 +50,7 @@ func TestCacheOperations(t *testing.T) {
|
|||||||
func TestUpdates(t *testing.T) {
|
func TestUpdates(t *testing.T) {
|
||||||
m := NewManager()
|
m := NewManager()
|
||||||
|
|
||||||
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "test-pod"}}
|
pod := &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "test-pod"}}
|
||||||
fooID := kubecontainer.ContainerID{Type: "test", ID: "foo"}
|
fooID := kubecontainer.ContainerID{Type: "test", ID: "foo"}
|
||||||
barID := kubecontainer.ContainerID{Type: "test", ID: "bar"}
|
barID := kubecontainer.ContainerID{Type: "test", ID: "bar"}
|
||||||
|
|
||||||
@ -97,3 +98,65 @@ func TestUpdates(t *testing.T) {
|
|||||||
m.Set(barID, Success, pod)
|
m.Set(barID, Success, pod)
|
||||||
expectUpdate(Update{barID, Success, pod.UID}, "changed bar")
|
expectUpdate(Update{barID, Success, pod.UID}, "changed bar")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResult_ToPrometheusType(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
result Result
|
||||||
|
expected float64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "result is Success",
|
||||||
|
result: Success,
|
||||||
|
expected: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "result is Failure",
|
||||||
|
result: Failure,
|
||||||
|
expected: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "result is other",
|
||||||
|
result: 123,
|
||||||
|
expected: -1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
if got := test.result.ToPrometheusType(); got != test.expected {
|
||||||
|
t.Errorf("Result.ToPrometheusType() = %v, expected %v", got, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResult_String(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
result Result
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "result is Success",
|
||||||
|
result: Success,
|
||||||
|
expected: "Success",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "result is Failure",
|
||||||
|
result: Failure,
|
||||||
|
expected: "Failure",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "result is other",
|
||||||
|
result: -123,
|
||||||
|
expected: "UNKNOWN",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
if got := test.result.String(); got != test.expected {
|
||||||
|
t.Errorf("Result.String() = %v, expected %v", got, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user