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)
| 227 | // pointer with the original, which would let a mutation on one leak into the |
| 228 | // other. |
| 229 | func 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 | } |