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 16, 2024
1 parent fa09c95 commit 008e7cc
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 fmt.Sprintf("%s:%s:%s", p.Binding.HostIP, 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 008e7cc

Please sign in to comment.