mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Improved code coverage for pkg/kubelet/types/labels
The test coverage improved from 0% to 100%.
This commit is contained in:
parent
8f6df26755
commit
f97337211d
@ -28,6 +28,7 @@ go_library(
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"labels_test.go",
|
||||
"pod_update_test.go",
|
||||
"types_test.go",
|
||||
],
|
||||
|
119
pkg/kubelet/types/labels_test.go
Normal file
119
pkg/kubelet/types/labels_test.go
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetContainerName(t *testing.T) {
|
||||
var cases = []struct {
|
||||
labels map[string]string
|
||||
containerName string
|
||||
}{
|
||||
{
|
||||
labels: map[string]string{
|
||||
"io.kubernetes.container.name": "c1",
|
||||
},
|
||||
containerName: "c1",
|
||||
},
|
||||
{
|
||||
labels: map[string]string{
|
||||
"io.kubernetes.container.name": "c2",
|
||||
},
|
||||
containerName: "c2",
|
||||
},
|
||||
}
|
||||
for _, data := range cases {
|
||||
containerName := GetContainerName(data.labels)
|
||||
assert.Equal(t, data.containerName, containerName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPodName(t *testing.T) {
|
||||
var cases = []struct {
|
||||
labels map[string]string
|
||||
podName string
|
||||
}{
|
||||
{
|
||||
labels: map[string]string{
|
||||
"io.kubernetes.pod.name": "p1",
|
||||
},
|
||||
podName: "p1",
|
||||
},
|
||||
{
|
||||
labels: map[string]string{
|
||||
"io.kubernetes.pod.name": "p2",
|
||||
},
|
||||
podName: "p2",
|
||||
},
|
||||
}
|
||||
for _, data := range cases {
|
||||
podName := GetPodName(data.labels)
|
||||
assert.Equal(t, data.podName, podName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPodUID(t *testing.T) {
|
||||
var cases = []struct {
|
||||
labels map[string]string
|
||||
podUID string
|
||||
}{
|
||||
{
|
||||
labels: map[string]string{
|
||||
"io.kubernetes.pod.uid": "uid1",
|
||||
},
|
||||
podUID: "uid1",
|
||||
},
|
||||
{
|
||||
labels: map[string]string{
|
||||
"io.kubernetes.pod.uid": "uid2",
|
||||
},
|
||||
podUID: "uid2",
|
||||
},
|
||||
}
|
||||
for _, data := range cases {
|
||||
podUID := GetPodUID(data.labels)
|
||||
assert.Equal(t, data.podUID, podUID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPodNamespace(t *testing.T) {
|
||||
var cases = []struct {
|
||||
labels map[string]string
|
||||
podNamespace string
|
||||
}{
|
||||
{
|
||||
labels: map[string]string{
|
||||
"io.kubernetes.pod.namespace": "ns1",
|
||||
},
|
||||
podNamespace: "ns1",
|
||||
},
|
||||
{
|
||||
labels: map[string]string{
|
||||
"io.kubernetes.pod.namespace": "ns2",
|
||||
},
|
||||
podNamespace: "ns2",
|
||||
},
|
||||
}
|
||||
for _, data := range cases {
|
||||
podNamespace := GetPodNamespace(data.labels)
|
||||
assert.Equal(t, data.podNamespace, podNamespace)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user