I'm trying to test a method. Its signature is func (gv *myType) Update(all map[string][]SomeType) error
Although the test fails (the expected value doesn't match the received value) I've found that also the map it receives(allSub
) is "updated" after the method is evaluated. Here is the code:
t.Logf("allsub %v", allSub)
if err := gv.Update(allSub); err != nil {
t.Error(err)
return
}
if !reflect.DeepEqual(egv, gv) {
t.Errorf("allSub %v", allSub)
return
}
The output
mth_test.go:265: allsub map[b:[{1 3 3}] a:[{1 0 0} {1 2 0}]]
mth_test.go:271: allSub map[a:[{1 2 0}]]
As you can see on t.Logf("allsub %v", allSub)
we have map[b:[{1 3 3}] a:[{1 0 0} {1 2 0}]]
and then after the evaluation if !reflect.DeepEqual(egv, gv)
allSub becomes allSub map[a:[{1 2 0}]]
. This drives me crazy and I'm wondering how is this possible? allSub is not a pointer.