istio

Форк
0
/
podutil_test.go 
77 строк · 1.7 Кб
1
// Copyright Istio Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package util
16

17
import (
18
	"testing"
19

20
	corev1 "k8s.io/api/core/v1"
21
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22

23
	"istio.io/istio/pkg/test/util/assert"
24
)
25

26
func TestGetPodIPIfPodIPPresent(t *testing.T) {
27
	pod := &corev1.Pod{
28
		ObjectMeta: metav1.ObjectMeta{
29
			Name:      "test",
30
			Namespace: "test",
31
		},
32
		Spec: corev1.PodSpec{
33
			NodeName: "derp",
34
		},
35
		Status: corev1.PodStatus{
36
			PodIP: "11.1.1.12",
37
		},
38
	}
39

40
	podIPs := GetPodIPsIfPresent(pod)
41
	assert.Equal(t, len(podIPs), 1)
42
}
43

44
func TestGetPodIPsIfPodIPPresent(t *testing.T) {
45
	pod := &corev1.Pod{
46
		ObjectMeta: metav1.ObjectMeta{
47
			Name:      "test",
48
			Namespace: "test",
49
		},
50
		Spec: corev1.PodSpec{
51
			NodeName: "derp",
52
		},
53
		Status: corev1.PodStatus{
54
			PodIP:  "2.2.2.2",
55
			PodIPs: []corev1.PodIP{{IP: "2.2.2.2"}, {IP: "3.3.3.3"}},
56
		},
57
	}
58

59
	podIPs := GetPodIPsIfPresent(pod)
60
	assert.Equal(t, len(podIPs), 2)
61
}
62

63
func TestGetPodIPsIfNoPodIPPresent(t *testing.T) {
64
	pod := &corev1.Pod{
65
		ObjectMeta: metav1.ObjectMeta{
66
			Name:      "test",
67
			Namespace: "test",
68
		},
69
		Spec: corev1.PodSpec{
70
			NodeName: "derp",
71
		},
72
		Status: corev1.PodStatus{},
73
	}
74

75
	podIPs := GetPodIPsIfPresent(pod)
76
	assert.Equal(t, len(podIPs), 0)
77
}
78

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.