diff --git a/config/types.go b/config/types.go index baa073ab460e..fccae22b5ae0 100644 --- a/config/types.go +++ b/config/types.go @@ -360,7 +360,7 @@ func (p OptionalString) String() string { if p.value == nil { return "default" } - return fmt.Sprintf("%d", p.value) + return *p.value } var _ json.Unmarshaler = (*OptionalInteger)(nil) diff --git a/config/types_test.go b/config/types_test.go index 2477f8bcf9a2..3a1fd6a8426a 100644 --- a/config/types_test.go +++ b/config/types_test.go @@ -407,11 +407,13 @@ func TestOptionalString(t *testing.T) { t.Fatal("should be the default") } if val := defaultOptionalString.WithDefault(""); val != "" { - t.Errorf("optional integer should have been empty, got %s", val) + t.Errorf("optional string should have been empty, got %s", val) + } + if val := defaultOptionalString.String(); val != "default" { + t.Fatalf("default optional string should be the 'default' string, got %s", val) } - if val := defaultOptionalString.WithDefault("foo"); val != "foo" { - t.Errorf("optional integer should have been foo, got %s", val) + t.Errorf("optional string should have been foo, got %s", val) } var filledStr OptionalString @@ -420,17 +422,20 @@ func TestOptionalString(t *testing.T) { t.Fatal("should not be the default") } if val := filledStr.WithDefault("bar"); val != "foo" { - t.Errorf("optional integer should have been foo, got %s", val) + t.Errorf("optional string should have been foo, got %s", val) + } + if val := filledStr.String(); val != "foo" { + t.Fatalf("optional string should have been foo, got %s", val) } - filledStr = OptionalString{value: makeStringPointer("")} if val := filledStr.WithDefault("foo"); val != "" { - t.Errorf("optional integer should have been 0, got %s", val) + t.Errorf("optional string should have been 0, got %s", val) } for jsonStr, goValue := range map[string]OptionalString{ "null": {}, "\"0\"": {value: makeStringPointer("0")}, + "\"\"": {value: makeStringPointer("")}, `"1"`: {value: makeStringPointer("1")}, `"-1"`: {value: makeStringPointer("-1")}, `"qwerty"`: {value: makeStringPointer("qwerty")},