Merge pull request #9 from uber-go/string_bug
Fix NewString disregarding the passed in string
This commit is contained in:
@@ -26,8 +26,12 @@ import "sync/atomic"
|
||||
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.
|
||||
|
||||
@@ -39,5 +39,5 @@ func TestString(t *testing.T) {
|
||||
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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user