diff --git a/v2/metadata_test.go b/v2/metadata_test.go index 5d7e5fc..d67d56e 100644 --- a/v2/metadata_test.go +++ b/v2/metadata_test.go @@ -40,6 +40,16 @@ func (s _testStringer) String() string { return "something" } +type _testError struct{} + +func (s _testError) Error() string { + return "errorstr" +} + +type _testStruct struct { + Name *_testStringer +} + var account = _account{} var notifier = New(Configuration{}) @@ -100,6 +110,53 @@ func TestMetadataAddPointer(t *testing.T) { } } +func TestMetadataAddNil(t *testing.T) { + md := MetaData{} + md.AddStruct("map", map[string]interface{}{ + "data": _testStruct{Name: nil}, + }) + + var nilMap map[string]interface{} + md.AddStruct("nilmap", nilMap) + + var nilError _testError + md.AddStruct("error", nilError) + + var nilErrorPtr *_testError + md.AddStruct("errorNilPtr", nilErrorPtr) + + var timeVar time.Time + md.AddStruct("timeUnset", timeVar) + + var duration time.Duration + md.AddStruct("durationUnset", duration) + + var marshalNilPtr *_textMarshaller + md.AddStruct("marshalNilPtr", marshalNilPtr) + + var marshalFullPtr = &_textMarshaller{} + md.AddStruct("marshalFullPtr", marshalFullPtr) + + if !reflect.DeepEqual(md, MetaData{ + "map": { + "data": map[string]interface{}{ + "Name": "", + }, + }, + "nilmap": map[string]interface{}{}, + "Extra data": { + "error": "errorstr", + "errorNilPtr": "", + "timeUnset": "0001-01-01T00:00:00Z", + "durationUnset": "0s", + "marshalFullPtr": "marshalled text", + "marshalNilPtr": "", + }, + }) { + t.Errorf("metadata.AddStruct didn't work: %#v", md) + } +} + func TestMetaDataUpdate(t *testing.T) { m := MetaData{