Skip to content

Commit b7a46d6

Browse files
authored
Merge pull request #4260 from haytok/update_portutil_test
test: update test logic in TestParsePortsLabel
2 parents 772bb09 + cbd4ef2 commit b7a46d6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pkg/portutil/portutil_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ func TestParsePortsLabel(t *testing.T) {
178178
},
179179
want: []cni.PortMapping{
180180
{
181-
HostPort: 3000,
182-
ContainerPort: 8080,
181+
HostPort: 12345,
182+
ContainerPort: 10000,
183183
Protocol: "tcp",
184-
HostIP: "127.0.0.1",
184+
HostIP: "0.0.0.0",
185185
},
186186
},
187187
wantErr: false,
@@ -219,7 +219,7 @@ func TestParsePortsLabel(t *testing.T) {
219219
}
220220
if !reflect.DeepEqual(got, tt.want) {
221221
if len(got) == len(tt.want) {
222-
if len(got) > 1 {
222+
if len(got) > 0 {
223223
var hostPorts []int32
224224
var containerPorts []int32
225225
for _, value := range got {
@@ -235,6 +235,14 @@ func TestParsePortsLabel(t *testing.T) {
235235
if (hostPorts[len(hostPorts)-1] - hostPorts[0]) != (containerPorts[len(hostPorts)-1] - containerPorts[0]) {
236236
t.Errorf("ParsePortsLabel() = %v, want %v", got, tt.want)
237237
}
238+
sort.Slice(got, func(i, j int) bool {
239+
return got[i].HostPort < got[j].HostPort
240+
})
241+
for i := 0; i < len(got); i++ {
242+
if got[i].HostPort != tt.want[i].HostPort || got[i].ContainerPort != tt.want[i].ContainerPort || got[i].Protocol != tt.want[i].Protocol || got[i].HostIP != tt.want[i].HostIP {
243+
t.Errorf("ParsePortsLabel() = %v, want %v", got, tt.want)
244+
}
245+
}
238246
}
239247
} else {
240248
t.Errorf("ParsePortsLabel() = %v, want %v", got, tt.want)

0 commit comments

Comments
 (0)