Skip to content

Commit

Permalink
Merge pull request kubernetes#116931 from my-git9/CreateListener-ut
Browse files Browse the repository at this point in the history
[ut] increase covrage for kubelet/prober/results
  • Loading branch information
k8s-ci-robot committed Oct 31, 2023
2 parents 2a4d5c5 + 55d4716 commit af18989
Showing 1 changed file with 66 additions and 3 deletions.
69 changes: 66 additions & 3 deletions pkg/kubelet/prober/results/results_manager_test.go
Expand Up @@ -21,7 +21,8 @@ import (
"time"

"github.com/stretchr/testify/assert"
"k8s.io/api/core/v1"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
Expand All @@ -36,7 +37,7 @@ func TestCacheOperations(t *testing.T) {
_, found := m.Get(unsetID)
assert.False(t, found, "unset result found")

m.Set(setID, Success, &v1.Pod{})
m.Set(setID, Success, &corev1.Pod{})
result, found := m.Get(setID)
assert.True(t, result == Success, "set result")
assert.True(t, found, "set result found")
Expand All @@ -49,7 +50,7 @@ func TestCacheOperations(t *testing.T) {
func TestUpdates(t *testing.T) {
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"}
barID := kubecontainer.ContainerID{Type: "test", ID: "bar"}

Expand Down Expand Up @@ -97,3 +98,65 @@ func TestUpdates(t *testing.T) {
m.Set(barID, Success, pod)
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)
}
})
}
}

0 comments on commit af18989

Please sign in to comment.