Skip to content

Commit fab4fe7

Browse files
Fix ListTunnelPorts in Go (#538)
In a for loop, a new address is created for the loopvar. Appending the pointer of the loopvar to a slice means that every element in the slice will point to the last element ranged over.
1 parent 1973647 commit fab4fe7

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

go/tunnels/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ func (m *Manager) ListTunnelPorts(
410410
return nil, fmt.Errorf("error parsing response json to tunnel ports: %w", err)
411411
}
412412

413-
for _, port := range tunnelPortsResponse.Value {
414-
tp = append(tp, &port)
413+
for i := range tunnelPortsResponse.Value {
414+
tp = append(tp, &tunnelPortsResponse.Value[i])
415415
}
416416

417417
return tp, nil

go/tunnels/manager_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,15 @@ func TestTunnelListPorts(t *testing.T) {
653653
if len(ports) != 2 {
654654
t.Errorf("ports not successfully listed")
655655
}
656+
657+
if ports[0].PortNumber != 3000 {
658+
t.Errorf("port 3000 not successfully listed")
659+
}
660+
661+
if ports[1].PortNumber != 3001 {
662+
t.Errorf("port 3001 not successfully listed")
663+
}
664+
656665
for _, port := range ports {
657666
logger.Printf("Port: %d", port.PortNumber)
658667
port.Table().Print()

go/tunnels/tunnels.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/rodaine/table"
1111
)
1212

13-
const PackageVersion = "0.1.18"
13+
const PackageVersion = "0.1.19"
1414

1515
func (tunnel *Tunnel) requestObject() (*Tunnel, error) {
1616
convertedTunnel := &Tunnel{

0 commit comments

Comments
 (0)