Display empty string instead of <nil> when IP opt is nil.

Fixes #13878.

Signed-off-by: Eric-Olivier Lamey <eo@lamey.me>
This commit is contained in:
Eric-Olivier Lamey 2015-06-11 07:53:39 +00:00 committed by Vincent Demeester
parent d1be0bd11e
commit 0c721e1ad5
2 changed files with 16 additions and 0 deletions

View File

@ -27,5 +27,8 @@ func (o *IpOpt) Set(val string) error {
} }
func (o *IpOpt) String() string { func (o *IpOpt) String() string {
if *o.IP == nil {
return ""
}
return o.IP.String() return o.IP.String()
} }

View File

@ -2,6 +2,7 @@ package opts
import ( import (
"fmt" "fmt"
"net"
"strings" "strings"
"testing" "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) { func logOptsValidator(val string) (string, error) {
allowedKeys := map[string]string{"max-size": "1", "max-file": "2"} allowedKeys := map[string]string{"max-size": "1", "max-file": "2"}
vals := strings.Split(val, "=") vals := strings.Split(val, "=")