From 9ad89281aeb31d251f97af7ea419d5ca865b8199 Mon Sep 17 00:00:00 2001 From: Eric-Olivier Lamey Date: Thu, 11 Jun 2015 07:53:39 +0000 Subject: [PATCH] Display empty string instead of when IP opt is nil. Fixes #13878. Signed-off-by: Eric-Olivier Lamey --- opts/ip.go | 3 +++ opts/opts_test.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/opts/ip.go b/opts/ip.go index 90360056f7..d960dcd935 100644 --- a/opts/ip.go +++ b/opts/ip.go @@ -27,5 +27,8 @@ func (o *IpOpt) Set(val string) error { } func (o *IpOpt) String() string { + if *o.IP == nil { + return "" + } return o.IP.String() } diff --git a/opts/opts_test.go b/opts/opts_test.go index dfad430ac4..921009c6b3 100644 --- a/opts/opts_test.go +++ b/opts/opts_test.go @@ -2,6 +2,7 @@ package opts import ( "fmt" + "net" "strings" "testing" ) @@ -179,6 +180,18 @@ func TestValidateExtraHosts(t *testing.T) { } } +func TestIpOptString(t *testing.T) { + addresses := []string{"", "0.0.0.0"} + var ip net.IP + + for _, address := range addresses { + stringAddress := NewIpOpt(&ip, address).String() + if stringAddress != address { + t.Fatalf("IpOpt string should be `%s`, not `%s`", address, stringAddress) + } + } +} + func logOptsValidator(val string) (string, error) { allowedKeys := map[string]string{"max-size": "1", "max-file": "2"} vals := strings.Split(val, "=")