diff --git a/clues_test.go b/clues_test.go index 9edc975..7440141 100644 --- a/clues_test.go +++ b/clues_test.go @@ -40,8 +40,8 @@ func mustEquals[K comparable, V any]( ) { e, g := toMSS(expect), toMSS(got) - if hasCluesTrace && len(g) > 0 { - if _, ok := g["clues_trace"]; !ok { + if len(g) > 0 { + if _, ok := g["clues_trace"]; hasCluesTrace && !ok { t.Errorf( "expected map to contain key [clues_trace]\ngot: %+v", g) @@ -163,7 +163,7 @@ func assert( eS, eSns sa, ) { vs := clues.In(ctx) - mustEquals(t, eM, vs.Map(), true) + mustEquals(t, eM, vs.Map(), false) eS.equals(t, vs.Slice()) } @@ -175,7 +175,7 @@ func assertMSA( eS, eSns sa, ) { vs := clues.In(ctx) - mustEquals(t, eM, toMSA(vs.Map()), true) + mustEquals(t, eM, toMSA(vs.Map()), false) eS.equals(t, vs.Slice()) } @@ -197,12 +197,12 @@ func TestAdd(t *testing.T) { t.Run(test.name, func(t *testing.T) { ctx := context.WithValue(context.Background(), testCtx{}, "instance") check := msa{} - mustEquals(t, check, clues.In(ctx).Map(), true) + mustEquals(t, check, clues.In(ctx).Map(), false) for _, kv := range test.kvs { ctx = clues.Add(ctx, kv[0], kv[1]) check[kv[0]] = kv[1] - mustEquals(t, check, clues.In(ctx).Map(), true) + mustEquals(t, check, clues.In(ctx).Map(), false) } assert( @@ -229,14 +229,14 @@ func TestAddMap(t *testing.T) { t.Run(test.name, func(t *testing.T) { ctx := context.WithValue(context.Background(), testCtx{}, "instance") check := msa{} - mustEquals(t, check, clues.In(ctx).Map(), true) + mustEquals(t, check, clues.In(ctx).Map(), false) for _, m := range test.ms { ctx = clues.AddMap(ctx, m) for k, v := range m { check[k] = v } - mustEquals(t, check, clues.In(ctx).Map(), true) + mustEquals(t, check, clues.In(ctx).Map(), false) } assert( @@ -261,7 +261,7 @@ func TestAddTrace(t *testing.T) { t.Run(test.name, func(t *testing.T) { ctx := context.WithValue(context.Background(), testCtx{}, "instance") check := msa{} - mustEquals(t, check, clues.In(ctx).Map(), true) + mustEquals(t, check, clues.In(ctx).Map(), false) ctx = clues.AddTrace(ctx, "") @@ -292,7 +292,7 @@ func TestAddTraceName(t *testing.T) { for _, test := range table { t.Run(test.name, func(t *testing.T) { ctx := context.WithValue(context.Background(), testCtx{}, "instance") - mustEquals(t, msa{}, clues.In(ctx).Map(), true) + mustEquals(t, msa{}, clues.In(ctx).Map(), false) for _, name := range test.names { ctx = clues.AddTraceWith(ctx, name, test.kvs...) @@ -319,7 +319,7 @@ func TestImmutableCtx(t *testing.T) { pre = clues.In(testCtx) preMap = pre.Map() ) - mustEquals(t, check, preMap, true) + mustEquals(t, check, preMap, false) ctx2 := clues.Add(testCtx, "k", "v") if _, ok := preMap["k"]; ok { @@ -343,11 +343,11 @@ func TestImmutableCtx(t *testing.T) { lr = clues.Add(l, "beaux", "regard") ) - mustEquals(t, msa{}, clues.In(ctx).Map(), true) - mustEquals(t, msa{"foo": "bar"}, clues.In(l).Map(), true) - mustEquals(t, msa{"baz": "qux"}, clues.In(r).Map(), true) - mustEquals(t, msa{"foo": "bar", "fnords": "smarf"}, clues.In(ll).Map(), true) - mustEquals(t, msa{"foo": "bar", "beaux": "regard"}, clues.In(lr).Map(), true) + mustEquals(t, msa{}, clues.In(ctx).Map(), false) + mustEquals(t, msa{"foo": "bar"}, clues.In(l).Map(), false) + mustEquals(t, msa{"baz": "qux"}, clues.In(r).Map(), false) + mustEquals(t, msa{"foo": "bar", "fnords": "smarf"}, clues.In(ll).Map(), false) + mustEquals(t, msa{"foo": "bar", "beaux": "regard"}, clues.In(lr).Map(), false) } var _ cecrets.Concealer = &safe{} @@ -428,12 +428,12 @@ func TestAdd_concealed(t *testing.T) { t.Run(test.name, func(t *testing.T) { ctx := context.WithValue(context.Background(), testCtx{}, "instance") check := msa{} - mustEquals(t, check, toMSA(clues.In(ctx).Map()), true) + mustEquals(t, check, toMSA(clues.In(ctx).Map()), false) for _, cs := range test.concealers { ctx = clues.Add(ctx, cs...) check[concealed(cs[0])] = concealed(cs[1]) - mustEquals(t, check, toMSA(clues.In(ctx).Map()), true) + mustEquals(t, check, toMSA(clues.In(ctx).Map()), false) } assertMSA( @@ -577,7 +577,7 @@ func TestAddAgent(t *testing.T) { mapEquals(t, ctx, msa{ "one": 1, - }, true) + }, false) ctxWithWit := clues.AddAgent(ctx, "wit") clues.Relay(ctx, "wit", "zero", 0) @@ -585,7 +585,7 @@ func TestAddAgent(t *testing.T) { mapEquals(t, ctx, msa{ "one": 1, - }, true) + }, false) mapEquals(t, ctxWithWit, msa{ "one": 1, @@ -594,14 +594,14 @@ func TestAddAgent(t *testing.T) { "two": 2, }, }, - }, true) + }, false) ctxWithTim := clues.AddAgent(ctxWithWit, "tim") clues.Relay(ctxWithTim, "tim", "three", 3) mapEquals(t, ctx, msa{ "one": 1, - }, true) + }, false) mapEquals(t, ctxWithTim, msa{ "one": 1, @@ -613,14 +613,14 @@ func TestAddAgent(t *testing.T) { "three": 3, }, }, - }, true) + }, false) ctxWithBob := clues.AddAgent(ctx, "bob") clues.Relay(ctxWithBob, "bob", "four", 4) mapEquals(t, ctx, msa{ "one": 1, - }, true) + }, false) // should not have changed since its first usage mapEquals(t, ctxWithWit, msa{ @@ -630,7 +630,7 @@ func TestAddAgent(t *testing.T) { "two": 2, }, }, - }, true) + }, false) // should not have changed since its first usage mapEquals(t, ctxWithTim, msa{ @@ -643,7 +643,7 @@ func TestAddAgent(t *testing.T) { "three": 3, }, }, - }, true) + }, false) mapEquals(t, ctxWithBob, msa{ "one": 1, @@ -652,5 +652,5 @@ func TestAddAgent(t *testing.T) { "four": 4, }, }, - }, true) + }, false) } diff --git a/datanode.go b/datanode.go index 18f247a..21c0b12 100644 --- a/datanode.go +++ b/datanode.go @@ -86,7 +86,6 @@ func (dn *dataNode) addValues(m map[string]any) *dataNode { } spawn := dn.spawnDescendant() - spawn.id = makeNodeID() spawn.setValues(m) return spawn diff --git a/err_fmt_test.go b/err_fmt_test.go index b82e360..d9ad8d9 100644 --- a/err_fmt_test.go +++ b/err_fmt_test.go @@ -1734,11 +1734,10 @@ func TestComment(t *testing.T) { func TestErrCore_String(t *testing.T) { table := []struct { - name string - core *clues.ErrCore - expectS string - expectVPlus string - expectCluesTrace bool + name string + core *clues.ErrCore + expectS string + expectVPlus string }{ { name: "nil", @@ -1753,18 +1752,16 @@ func TestErrCore_String(t *testing.T) { With("key", "value"). Label("label"). Core(), - expectS: `{"message", [label], {key:value}}`, - expectVPlus: `{msg:"message", labels:[label], values:{key:value}, comments:[]}`, - expectCluesTrace: true, + expectS: `{"message", [label], {key:value}}`, + expectVPlus: `{msg:"message", labels:[label], values:{key:value}, comments:[]}`, }, { name: "message only", core: clues. New("message"). Core(), - expectS: `{"message"}`, - expectVPlus: `{msg:"message", labels:[], values:{}, comments:[]}`, - expectCluesTrace: false, + expectS: `{"message"}`, + expectVPlus: `{msg:"message", labels:[], values:{}, comments:[]}`, }, { name: "labels only", @@ -1772,9 +1769,8 @@ func TestErrCore_String(t *testing.T) { New(""). Label("label"). Core(), - expectS: `{[label]}`, - expectVPlus: `{msg:"", labels:[label], values:{}, comments:[]}`, - expectCluesTrace: false, + expectS: `{[label]}`, + expectVPlus: `{msg:"", labels:[label], values:{}, comments:[]}`, }, { name: "values only", @@ -1782,18 +1778,17 @@ func TestErrCore_String(t *testing.T) { New(""). With("key", "value"). Core(), - expectS: `{{key:value}}`, - expectVPlus: `{msg:"", labels:[], values:{key:value}, comments:[]}`, - expectCluesTrace: true, + expectS: `{{key:value}}`, + expectVPlus: `{msg:"", labels:[], values:{key:value}, comments:[]}`, }, } for _, test := range table { t.Run(test.name, func(t *testing.T) { tc := test.core if tc != nil { - if _, ok := tc.Values["clues_trace"]; ok != test.expectCluesTrace { + if _, ok := tc.Values["clues_trace"]; ok { t.Errorf( - "expected core values to contain key [clues_trace]\ngot: %+v", + "did not expect core values to contain key [clues_trace]\ngot: %+v", tc.Values) } delete(tc.Values, "clues_trace") diff --git a/err_test.go b/err_test.go index fd64fcf..a1e9238 100644 --- a/err_test.go +++ b/err_test.go @@ -292,8 +292,8 @@ func TestWith(t *testing.T) { for _, kv := range test.with { err = err.With(kv...) } - mustEquals(t, test.expect, clues.InErr(err).Map(), true) - mustEquals(t, test.expect, err.Values().Map(), true) + mustEquals(t, test.expect, clues.InErr(err).Map(), false) + mustEquals(t, test.expect, err.Values().Map(), false) }) } } @@ -332,8 +332,8 @@ func TestWithMap(t *testing.T) { t.Run(test.name, func(t *testing.T) { err := clues.WithMap(test.initial, test.kv) err = err.WithMap(test.with) - mustEquals(t, test.expect, clues.InErr(err).Map(), true) - mustEquals(t, test.expect, err.Values().Map(), true) + mustEquals(t, test.expect, clues.InErr(err).Map(), false) + mustEquals(t, test.expect, err.Values().Map(), false) }) } } @@ -375,8 +375,8 @@ func TestWithClues(t *testing.T) { tctx := clues.AddMap(ctx, test.kv) err := clues.WithClues(test.initial, tctx) err = err.WithMap(test.with) - mustEquals(t, test.expect, clues.InErr(err).Map(), true) - mustEquals(t, test.expect, err.Values().Map(), true) + mustEquals(t, test.expect, clues.InErr(err).Map(), false) + mustEquals(t, test.expect, err.Values().Map(), false) }) } } @@ -426,7 +426,7 @@ func TestValuePriority(t *testing.T) { } for _, test := range table { t.Run(test.name, func(t *testing.T) { - mustEquals(t, test.expect, clues.InErr(test.err).Map(), true) + mustEquals(t, test.expect, clues.InErr(test.err).Map(), false) }) } } @@ -681,7 +681,7 @@ func TestErrValues_stacks(t *testing.T) { for _, test := range table { t.Run(test.name, func(t *testing.T) { vs := clues.InErr(test.err) - mustEquals(t, test.expect, vs.Map(), true) + mustEquals(t, test.expect, vs.Map(), false) }) } } @@ -690,7 +690,7 @@ func TestImmutableErrors(t *testing.T) { err := clues.New("an error").With("k", "v") check := msa{"k": "v"} pre := clues.InErr(err) - mustEquals(t, check, pre.Map(), true) + mustEquals(t, check, pre.Map(), false) err2 := err.With("k2", "v2") if _, ok := pre.Map()["k2"]; ok { @@ -1073,7 +1073,7 @@ func TestToCore(t *testing.T) { t.Errorf("expected Msg [%v], got [%v]", test.expectMsg, c.Msg) } mustEquals(t, test.expectLabels, toMSA(c.Labels), false) - mustEquals(t, test.expectValues, toMSA(c.Values), true) + mustEquals(t, test.expectValues, toMSA(c.Values), false) }) } }