Commit 8b9625d2 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #41627 from gyliu513/kubelet-types

Automatic merge from submit-queue (batch tested with PRs 42740, 44980, 45039, 41627, 45044) Improved code coverage for /pkg/kubelet/types **What this PR does / why we need it**: The test coverage for /pkg/kubelet/types was increased from 50% to 87.5% **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 ```
parents a3c4d9d6 593336bd
......@@ -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",
],
)
......
......@@ -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{},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment