Skip to content

Commit b734358

Browse files
author
leonsteinhaeuser
committed
fix(k8s): unit tests for pod status format
1 parent f790dfe commit b734358

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.23
44

55
require (
66
github.com/go-chi/chi/v5 v5.1.0
7+
github.com/google/go-cmp v0.6.0
78
github.com/gorilla/websocket v1.5.0
89
github.com/leonsteinhaeuser/observer/v2 v2.0.1
910
github.com/prometheus/client_golang v1.20.4
@@ -26,7 +27,6 @@ require (
2627
github.com/gogo/protobuf v1.3.2 // indirect
2728
github.com/golang/protobuf v1.5.4 // indirect
2829
github.com/google/gnostic-models v0.6.8 // indirect
29-
github.com/google/go-cmp v0.6.0 // indirect
3030
github.com/google/gofuzz v1.2.0 // indirect
3131
github.com/google/uuid v1.6.0 // indirect
3232
github.com/imdario/mergo v0.3.6 // indirect

internal/k8s/status_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"reflect"
66
"testing"
77

8+
"github.com/google/go-cmp/cmp"
89
appsv1 "k8s.io/api/apps/v1"
910
corev1 "k8s.io/api/core/v1"
1011
"k8s.io/client-go/kubernetes"
@@ -102,7 +103,7 @@ func TestGetPodStatusFormat(t *testing.T) {
102103
tests := []struct {
103104
name string
104105
args args
105-
want map[corev1.PodPhase]int
106+
want PodStatus
106107
}{
107108
{
108109
name: "one pod",
@@ -113,7 +114,7 @@ func TestGetPodStatusFormat(t *testing.T) {
113114
},
114115
},
115116
},
116-
want: map[corev1.PodPhase]int{
117+
want: PodStatus{
117118
corev1.PodRunning: 1,
118119
},
119120
},
@@ -129,16 +130,19 @@ func TestGetPodStatusFormat(t *testing.T) {
129130
},
130131
},
131132
},
132-
want: map[corev1.PodPhase]int{
133+
want: PodStatus{
133134
corev1.PodRunning: 1,
134135
corev1.PodPending: 1,
135136
},
136137
},
137138
}
138139
for _, tt := range tests {
139140
t.Run(tt.name, func(t *testing.T) {
140-
if got := GetPodStatusFormat(tt.args.pod); !reflect.DeepEqual(got, tt.want) {
141-
t.Errorf("GetPodStatusFormat() = %v, want %v", got, tt.want)
141+
got := GetPodStatusFormat(tt.args.pod)
142+
diff := cmp.Diff(got, tt.want)
143+
if diff != "" {
144+
t.Errorf("GetPodStatusFormat() mismatch (-got +want):\n%s", diff)
145+
return
142146
}
143147
})
144148
}

0 commit comments

Comments
 (0)