Skip to content

Commit 0ca7e7a

Browse files
committed
tests
Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>
1 parent f3179d0 commit 0ca7e7a

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/operator/controllers/monitor_test.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,24 @@ func (f *FakeHTTPClient) Get(url string) (*http.Response, error) {
7474
func TestMonitor_queryPodStatusz(t *testing.T) {
7575
httpClient := &FakeHTTPClient{
7676
responses: map[string]string{
77-
"https://127.0.0.1:8080/statusz": "",
78-
"https://127.0.0.3:50100/statusz": "CloudConnectFailed",
77+
"https://127-0-0-1.pl.pod.cluster.local:8080/statusz": "",
78+
"https://127-0-0-3.pl2.pod.cluster.local:50100/statusz": "CloudConnectFailed",
7979
},
8080
}
8181

8282
tests := []struct {
8383
name string
8484
podPort int32
8585
podIP string
86+
podNamespace string
8687
expectedStatus string
8788
expectedOK bool
8889
}{
8990
{
9091
name: "OK",
9192
podPort: 8080,
9293
podIP: "127.0.0.1",
94+
podNamespace: "pl",
9395
expectedStatus: "",
9496
expectedOK: true,
9597
},
@@ -104,6 +106,7 @@ func TestMonitor_queryPodStatusz(t *testing.T) {
104106
name: "unhealthy",
105107
podPort: 50100,
106108
podIP: "127.0.0.3",
109+
podNamespace: "pl2",
107110
expectedStatus: "CloudConnectFailed",
108111
expectedOK: false,
109112
},
@@ -115,6 +118,9 @@ func TestMonitor_queryPodStatusz(t *testing.T) {
115118
Status: v1.PodStatus{
116119
PodIP: test.podIP,
117120
},
121+
ObjectMeta: metav1.ObjectMeta{
122+
Namespace: test.podNamespace,
123+
},
118124
Spec: v1.PodSpec{
119125
Containers: []v1.Container{
120126
{
@@ -169,7 +175,7 @@ func TestMonitor_getCloudConnState(t *testing.T) {
169175
t.Run(test.name, func(t *testing.T) {
170176
httpClient := &FakeHTTPClient{
171177
responses: map[string]string{
172-
"https://127.0.0.1:8080/statusz": test.cloudConnStatusz,
178+
"https://127-0-0-1.pl.pod.cluster.local:8080/statusz": test.cloudConnStatusz,
173179
},
174180
}
175181

@@ -183,6 +189,9 @@ func TestMonitor_getCloudConnState(t *testing.T) {
183189
PodIP: "127.0.0.1",
184190
Phase: test.cloudConnPhase,
185191
},
192+
ObjectMeta: metav1.ObjectMeta{
193+
Namespace: "pl",
194+
},
186195
Spec: v1.PodSpec{
187196
Containers: []v1.Container{
188197
{
@@ -500,9 +509,7 @@ func TestMonitor_repairVizier_PVC(t *testing.T) {
500509

501510
func TestMonitor_getCloudConnState_SeveralCloudConns(t *testing.T) {
502511
httpClient := &FakeHTTPClient{
503-
responses: map[string]string{
504-
"https://127.0.0.1:8080/statusz": "",
505-
},
512+
responses: map[string]string{},
506513
}
507514

508515
pods := &concurrentPodMap{unsafeMap: make(map[string]map[string]*podWrapper)}
@@ -545,8 +552,8 @@ func TestMonitor_getCloudConnState_SeveralCloudConns(t *testing.T) {
545552
func TestMonitor_NATSPods(t *testing.T) {
546553
httpClient := &FakeHTTPClient{
547554
responses: map[string]string{
548-
"http://127.0.0.1:8222": "",
549-
"http://127.0.0.3:8222": "NATS Failed",
555+
"http://127-0-0-1.pl.pod.cluster.local:8222": "",
556+
"http://127-0-0-3.pl.pod.cluster.local:8222": "NATS Failed",
550557
},
551558
}
552559

@@ -624,6 +631,9 @@ func TestMonitor_NATSPods(t *testing.T) {
624631
PodIP: test.natsIP,
625632
Phase: test.natsPhase,
626633
},
634+
ObjectMeta: metav1.ObjectMeta{
635+
Namespace: "pl",
636+
},
627637
},
628638
},
629639
)

src/utils/shared/k8s/BUILD.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ go_library(
6565

6666
pl_go_test(
6767
name = "k8s_test",
68-
srcs = ["apply_test.go"],
68+
srcs = [
69+
"apply_test.go",
70+
"dns_addr_test.go",
71+
],
6972
deps = [
7073
":k8s",
7174
"@com_github_stretchr_testify//assert",
7275
"@com_github_stretchr_testify//require",
76+
"@io_k8s_api//core/v1:core",
77+
"@io_k8s_apimachinery//pkg/apis/meta/v1:meta",
7378
],
7479
)

0 commit comments

Comments
 (0)