MCPcopy Index your code
hub / github.com/docker/docker-agent / TestClone_DeepCopiesErrorItem

Function TestClone_DeepCopiesErrorItem

pkg/session/clone_test.go:229–241  ·  view source on GitHub ↗

TestClone_DeepCopiesErrorItem guards against the clone sharing the *Error pointer with the original, which would let a mutation on one leak into the other.

(t *testing.T)

Source from the content-addressed store, hash-verified

227// pointer with the original, which would let a mutation on one leak into the
228// other.
229func TestClone_DeepCopiesErrorItem(t *testing.T) {
230 t.Parallel()
231 orig := New()
232 orig.AddError(&Error{Message: "boom", Code: "model_error", AgentName: "root"})
233
234 clone := orig.Clone()
235 require.Len(t, clone.Messages, 1)
236 require.True(t, clone.Messages[0].IsError())
237 assert.Equal(t, "boom", clone.Messages[0].Error.Message)
238
239 clone.Messages[0].Error.Message = "mutated"
240 assert.Equal(t, "boom", orig.Messages[0].Error.Message, "Error must be deep-copied")
241}

Callers

nothing calls this directly

Calls 5

IsErrorMethod · 0.80
NewFunction · 0.70
AddErrorMethod · 0.65
LenMethod · 0.65
CloneMethod · 0.45

Tested by

no test coverage detected