MCPcopy
hub / github.com/sirupsen/logrus / TestEntryWithTimeCopiesData

Function TestEntryWithTimeCopiesData

entry_test.go:96–129  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

94}
95
96func TestEntryWithTimeCopiesData(t *testing.T) {
97 assert := assert.New(t)
98
99 // Initialize a parent Entry object with a key/value set in its Data map
100 logger := New()
101 logger.Out = &bytes.Buffer{}
102 parentEntry := NewEntry(logger).WithField("parentKey", "parentValue")
103
104 // Create two children Entry objects from the parent with two different times
105 childEntry1 := parentEntry.WithTime(time.Now().AddDate(0, 0, 1))
106 childEntry2 := parentEntry.WithTime(time.Now().AddDate(0, 0, 2))
107
108 // Ensure that data set in the parent Entry are preserved to both children
109 assert.Equal("parentValue", childEntry1.Data["parentKey"])
110 assert.Equal("parentValue", childEntry2.Data["parentKey"])
111
112 // Modify data stored in the child entry
113 childEntry1.Data["childKey"] = "childValue"
114
115 // Verify that data is successfully stored in the child it was set on
116 val, exists := childEntry1.Data["childKey"]
117 assert.True(exists)
118 assert.Equal("childValue", val)
119
120 // Verify that the data change to child 1 has not affected its sibling
121 val, exists = childEntry2.Data["childKey"]
122 assert.False(exists)
123 assert.Empty(val)
124
125 // Verify that the data change to child 1 has not affected its parent
126 val, exists = parentEntry.Data["childKey"]
127 assert.False(exists)
128 assert.Empty(val)
129}
130
131func TestEntryPanicln(t *testing.T) {
132 errBoom := fmt.Errorf("boom time")

Callers

nothing calls this directly

Calls 4

NewFunction · 0.85
NewEntryFunction · 0.85
WithFieldMethod · 0.65
WithTimeMethod · 0.45

Tested by

no test coverage detected