diff --git a/pkg/kubelet/types/BUILD b/pkg/kubelet/types/BUILD index ebe35e31c9b..67477e9431d 100644 --- a/pkg/kubelet/types/BUILD +++ b/pkg/kubelet/types/BUILD @@ -35,6 +35,7 @@ go_test( tags = ["automanaged"], deps = [ "//pkg/api/v1:go_default_library", + "//vendor/github.com/stretchr/testify/assert:go_default_library", "//vendor/github.com/stretchr/testify/require:go_default_library", ], ) diff --git a/pkg/kubelet/types/types_test.go b/pkg/kubelet/types/types_test.go index 9bb9acbea8d..8613b65b1d0 100644 --- a/pkg/kubelet/types/types_test.go +++ b/pkg/kubelet/types/types_test.go @@ -20,9 +20,83 @@ import ( "reflect" "testing" + "github.com/stretchr/testify/assert" "k8s.io/kubernetes/pkg/api/v1" ) +func TestConvertToTimestamp(t *testing.T) { + timestamp := "2017-02-17T15:34:49.830882016+08:00" + convertedTimeStamp := ConvertToTimestamp(timestamp).GetString() + assert.Equal(t, timestamp, convertedTimeStamp) +} + +func TestLen(t *testing.T) { + var cases = []struct { + statuses SortedContainerStatuses + expected int + }{ + { + statuses: SortedContainerStatuses{{Name: "first"}}, + expected: 1, + }, + { + statuses: SortedContainerStatuses{{Name: "first"}, {Name: "second"}}, + expected: 2, + }, + } + for _, data := range cases { + assert.Equal(t, data.expected, data.statuses.Len()) + } +} + +func TestSwap(t *testing.T) { + var cases = []struct { + statuses SortedContainerStatuses + expected SortedContainerStatuses + }{ + { + statuses: SortedContainerStatuses{{Name: "first"}, {Name: "second"}}, + expected: SortedContainerStatuses{{Name: "second"}, {Name: "first"}}, + }, + } + for _, data := range cases { + data.statuses.Swap(0, 1) + if !reflect.DeepEqual(data.statuses, data.expected) { + t.Errorf( + "failed Swap:\n\texpected: %v\n\t actual: %v", + data.expected, + data.statuses, + ) + } + } +} + +func TestLess(t *testing.T) { + var cases = []struct { + statuses SortedContainerStatuses + expected bool + }{ + { + statuses: SortedContainerStatuses{{Name: "first"}, {Name: "second"}}, + expected: true, + }, + { + statuses: SortedContainerStatuses{{Name: "second"}, {Name: "first"}}, + expected: false, + }, + } + for _, data := range cases { + actual := data.statuses.Less(0, 1) + if actual != data.expected { + t.Errorf( + "failed Less:\n\texpected: %t\n\t actual: %t", + data.expected, + actual, + ) + } + } +} + func TestSortInitContainerStatuses(t *testing.T) { pod := v1.Pod{ Spec: v1.PodSpec{},