@@ -29,7 +29,7 @@ import (
29
29
)
30
30
31
31
func TestTestParseFlagPWithPlatformSpec (t * testing.T ) {
32
- if runtime .GOOS != "Linux " || rootlessutil .IsRootless () {
32
+ if runtime .GOOS != "linux " || rootlessutil .IsRootless () {
33
33
t .Skip ("no non-Linux platform or rootless mode in Linux are not supported yet" )
34
34
}
35
35
type args struct {
@@ -48,7 +48,6 @@ func TestTestParseFlagPWithPlatformSpec(t *testing.T) {
48
48
},
49
49
want : []cni.PortMapping {
50
50
{
51
- HostPort : 3000 ,
52
51
ContainerPort : 3000 ,
53
52
Protocol : "tcp" ,
54
53
HostIP : "0.0.0.0" ,
@@ -63,13 +62,11 @@ func TestTestParseFlagPWithPlatformSpec(t *testing.T) {
63
62
},
64
63
want : []cni.PortMapping {
65
64
{
66
- HostPort : 3000 ,
67
65
ContainerPort : 3000 ,
68
66
Protocol : "tcp" ,
69
67
HostIP : "0.0.0.0" ,
70
68
},
71
69
{
72
- HostPort : 3001 ,
73
70
ContainerPort : 3001 ,
74
71
Protocol : "tcp" ,
75
72
HostIP : "0.0.0.0" ,
@@ -92,13 +89,11 @@ func TestTestParseFlagPWithPlatformSpec(t *testing.T) {
92
89
},
93
90
want : []cni.PortMapping {
94
91
{
95
- HostPort : 3000 ,
96
92
ContainerPort : 3000 ,
97
93
Protocol : "tcp" ,
98
94
HostIP : "0.0.0.0" ,
99
95
},
100
96
{
101
- HostPort : 3001 ,
102
97
ContainerPort : 3001 ,
103
98
Protocol : "tcp" ,
104
99
HostIP : "0.0.0.0" ,
@@ -113,15 +108,13 @@ func TestTestParseFlagPWithPlatformSpec(t *testing.T) {
113
108
},
114
109
want : []cni.PortMapping {
115
110
{
116
- HostPort : 3000 ,
117
111
ContainerPort : 3000 ,
118
- Protocol : "tcp " ,
112
+ Protocol : "udp " ,
119
113
HostIP : "0.0.0.0" ,
120
114
},
121
115
{
122
- HostPort : 3001 ,
123
116
ContainerPort : 3001 ,
124
- Protocol : "tcp " ,
117
+ Protocol : "udp " ,
125
118
HostIP : "0.0.0.0" ,
126
119
},
127
120
},
@@ -138,7 +131,7 @@ func TestTestParseFlagPWithPlatformSpec(t *testing.T) {
138
131
}
139
132
if ! reflect .DeepEqual (got , tt .want ) {
140
133
if len (got ) == len (tt .want ) {
141
- if len (got ) > 1 {
134
+ if len (got ) > 0 {
142
135
var hostPorts []int32
143
136
var containerPorts []int32
144
137
for _ , value := range got {
@@ -154,6 +147,14 @@ func TestTestParseFlagPWithPlatformSpec(t *testing.T) {
154
147
if (hostPorts [len (hostPorts )- 1 ] - hostPorts [0 ]) != (containerPorts [len (hostPorts )- 1 ] - containerPorts [0 ]) {
155
148
t .Errorf ("ParseFlagP() = %v, want %v" , got , tt .want )
156
149
}
150
+ sort .Slice (got , func (i , j int ) bool {
151
+ return got [i ].HostPort < got [j ].HostPort
152
+ })
153
+ for i := 0 ; i < len (got ); i ++ {
154
+ if got [i ].ContainerPort != tt .want [i ].ContainerPort || got [i ].Protocol != tt .want [i ].Protocol || got [i ].HostIP != tt .want [i ].HostIP {
155
+ t .Errorf ("ParseFlagP() = %v, want %v" , got , tt .want )
156
+ }
157
+ }
157
158
}
158
159
} else {
159
160
t .Errorf ("ParseFlagP() = %v, want %v" , got , tt .want )
0 commit comments