Merge pull request #9 from uber-go/string_bug
Fix NewString disregarding the passed in string
diff --git a/string.go b/string.go
index 17eb42e..b3589ff 100644
--- a/string.go
+++ b/string.go
@@ -26,8 +26,12 @@
type String struct{ atomic.Value }
// NewString creates a String.
-func NewString(s string) *String {
- return &String{}
+func NewString(str string) *String {
+ s := &String{}
+ if str != "" {
+ s.Store(str)
+ }
+ return s
}
// Load atomically loads the wrapped string.
diff --git a/string_test.go b/string_test.go
index 1c4ab8b..91b793e 100644
--- a/string_test.go
+++ b/string_test.go
@@ -39,5 +39,5 @@
require.Equal(t, "abc", atom.Load(), "Unexpected value after Store")
atom = NewString("bcd")
- require.Equal(t, "", atom.Load(), "Expected Load to return initialized value")
+ require.Equal(t, "bcd", atom.Load(), "Expected Load to return initialized value")
}