@@ -113,10 +113,10 @@ func TestForwardPorts(t *testing.T) {
113
113
serverSends map [int32 ]string
114
114
}{
115
115
"forward 1 port with no data either direction" : {
116
- ports : []string {"5000" },
116
+ ports : []string {": 5000" },
117
117
},
118
118
"forward 2 ports with bidirectional data" : {
119
- ports : []string {"5001" , "6000" },
119
+ ports : []string {": 5001" , ": 6000" },
120
120
clientSends : map [int32 ]string {
121
121
5001 : "abcd" ,
122
122
6000 : "ghij" ,
@@ -152,8 +152,18 @@ func TestForwardPorts(t *testing.T) {
152
152
}()
153
153
<- pf .Ready
154
154
155
+ forwardedPorts , err := pf .GetPorts ()
156
+ if err != nil {
157
+ t .Fatal (err )
158
+ }
159
+
160
+ remoteToLocalMap := map [int32 ]int32 {}
161
+ for _ , forwardedPort := range forwardedPorts {
162
+ remoteToLocalMap [int32 (forwardedPort .Remote )] = int32 (forwardedPort .Local )
163
+ }
164
+
155
165
for port , data := range test .clientSends {
156
- clientConn , err := net .Dial ("tcp" , fmt .Sprintf ("localhost:%d" , port ))
166
+ clientConn , err := net .Dial ("tcp" , fmt .Sprintf ("localhost:%d" , remoteToLocalMap [ port ] ))
157
167
if err != nil {
158
168
t .Errorf ("%s: error dialing %d: %s" , testName , port , err )
159
169
server .Close ()
@@ -213,16 +223,25 @@ func TestForwardPortsReturnsErrorWhenAllBindsFailed(t *testing.T) {
213
223
defer close (stopChan1 )
214
224
readyChan1 := make (chan struct {})
215
225
216
- pf1 , err := New (dialer , []string {"5555" }, stopChan1 , readyChan1 , os .Stdout , os .Stderr )
226
+ pf1 , err := New (dialer , []string {": 5555" }, stopChan1 , readyChan1 , os .Stdout , os .Stderr )
217
227
if err != nil {
218
228
t .Fatalf ("error creating pf1: %v" , err )
219
229
}
220
230
go pf1 .ForwardPorts ()
221
231
<- pf1 .Ready
222
232
233
+ forwardedPorts , err := pf1 .GetPorts ()
234
+ if err != nil {
235
+ t .Fatal (err )
236
+ }
237
+ if len (forwardedPorts ) != 1 {
238
+ t .Fatalf ("expected 1 forwarded port, got %#v" , forwardedPorts )
239
+ }
240
+ duplicateSpec := fmt .Sprintf ("%d:%d" , forwardedPorts [0 ].Local , forwardedPorts [0 ].Remote )
241
+
223
242
stopChan2 := make (chan struct {}, 1 )
224
243
readyChan2 := make (chan struct {})
225
- pf2 , err := New (dialer , []string {"5555" }, stopChan2 , readyChan2 , os .Stdout , os .Stderr )
244
+ pf2 , err := New (dialer , []string {duplicateSpec }, stopChan2 , readyChan2 , os .Stdout , os .Stderr )
226
245
if err != nil {
227
246
t .Fatalf ("error creating pf2: %v" , err )
228
247
}
0 commit comments