Migrate from testify to nalgeon/be testing library

- Replace all testify/assert and testify/require with be library
- Update go.mod to use be v0.3.0 instead of testify
- Simplify test assertions using be.Equal, be.Err, and be.True
- Refactor append_test, entry_test, meta_test, log_test, and formatter tests
This commit is contained in:
Dan Jones 2026-02-13 14:12:30 -06:00
commit 1110288d84
16 changed files with 226 additions and 236 deletions

View file

@ -7,7 +7,7 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/nalgeon/be"
)
// Type assertions
@ -72,8 +72,8 @@ func getMetaTestRunner(key string, value any, out string, err error, newVal any)
if valE, ok := value.(error); !ok || !errors.Is(valE, skipMarshalTest) {
var o []byte
o, e = st.MarshalText()
assert.Equal(t, out, string(o))
assert.Equal(t, err, e)
be.Equal(t, string(o), out)
be.Equal(t, e, err)
if e != nil {
return
}
@ -83,17 +83,16 @@ func getMetaTestRunner(key string, value any, out string, err error, newVal any)
e = n.UnmarshalText([]byte(out))
}
if newE, ok := newVal.(error); ok {
assert.ErrorIs(t, e, newE)
be.Err(t, e, newE)
} else {
assert.Equal(t, key, n.Key)
be.Equal(t, n.Key, key)
if ti, ok := newVal.(time.Time); ok {
valT, ok := n.Value.(time.Time)
if assert.True(t, ok) {
assert.WithinRange(t, valT, ti.Add(-time.Second), ti.Add(time.Second))
}
be.True(t, ok)
be.True(t, valT.After(ti.Add(-time.Second)) && valT.Before(ti.Add(time.Second)))
} else {
assert.Equal(t, newVal, n.Value)
be.Equal(t, n.Value, newVal)
}
}
}
@ -103,42 +102,45 @@ func TestMetasJson(t *testing.T) {
ms := Metas{{"me", 41}, {"you", false}}
exp := `{"me":41,"you":false}`
o, err := json.Marshal(ms)
assert.NoError(t, err)
assert.JSONEq(t, exp, string(o))
be.Err(t, err, nil)
var got, want any
json.Unmarshal([]byte(exp), &want)
json.Unmarshal(o, &got)
be.Equal(t, got, want)
}
func TestMetasJsonUnmarshal(t *testing.T) {
ms := Metas{}
in := `{"me":"cool","you":false}`
err := json.Unmarshal([]byte(in), &ms)
assert.NoError(t, err)
assert.Len(t, ms, 2)
assert.ElementsMatch(t, Metas{
be.Err(t, err, nil)
be.Equal(t, len(ms), 2)
be.Equal(t, ms, Metas{
{"me", "cool"},
{"you", false},
}, ms)
})
}
func TestMetasJsonError(t *testing.T) {
ms := Metas{}
in := "not json"
err := (&ms).UnmarshalJSON([]byte(in))
assert.Error(t, err)
assert.Len(t, ms, 0)
be.Err(t, err)
be.Equal(t, len(ms), 0)
}
func TestMetasAppend(t *testing.T) {
ms := Metas{}
ms = ms.Append("foo", 42)
assert.Len(t, ms, 1)
assert.Equal(t, Meta{"foo", 42}, ms[0])
be.Equal(t, len(ms), 1)
be.Equal(t, ms[0], Meta{"foo", 42})
}
func TestMetasAppendTo(t *testing.T) {
ms := &Metas{}
ms.AppendTo("foo", 42)
assert.Len(t, *ms, 1)
assert.Equal(t, Meta{"foo", 42}, (*ms)[0])
be.Equal(t, len(*ms), 1)
be.Equal(t, (*ms)[0], Meta{"foo", 42})
}
func TestMetasSet(t *testing.T) {
@ -196,7 +198,7 @@ func TestMetasSet(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.initial.Set(tt.key, tt.value)
assert.ElementsMatch(t, tt.expected, result)
be.Equal(t, result, tt.expected)
})
}
}
@ -205,14 +207,14 @@ func TestMetasGet(t *testing.T) {
ms := Metas{{"foo", 42}, {"bar", "hello"}}
val, found := ms.Get("foo")
assert.True(t, found)
assert.Equal(t, 42, val)
be.True(t, found)
be.Equal(t, val, 42)
val, found = ms.Get("bar")
assert.True(t, found)
assert.Equal(t, "hello", val)
be.True(t, found)
be.Equal(t, val, "hello")
val, found = ms.Get("baz")
assert.False(t, found)
assert.Nil(t, val)
be.True(t, !found)
be.Equal(t, val, nil)
}