Skip to content

Commit

Permalink
introduce String method on PortMapping
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Jan 22, 2024
1 parent fa09c95 commit a314a9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nat/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ type PortMapping struct {
Binding PortBinding
}

func (p *PortMapping) String() string {
return net.JoinHostPort(p.Binding.HostIP, fmt.Sprintf("%s:%s", p.Binding.HostPort, p.Port))
}

func splitParts(rawport string) (string, string, string) {
parts := strings.Split(rawport, ":")
n := len(parts)
Expand Down
13 changes: 13 additions & 0 deletions nat/nat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,3 +703,16 @@ func TestParseNetworkOptsSctp(t *testing.T) {
}
}
}

func TestStringer(t *testing.T) {
spec := "192.168.1.100:8080:6000/udp"
mappings, err := ParsePortSpec(spec)
if err != nil {
t.Fatal(err)
}
for _, m := range mappings {
if m.String() != spec {
t.Fail()
}
}
}

0 comments on commit a314a9d

Please sign in to comment.