✨ 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:
parent
79f58b3e6c
commit
1110288d84
16 changed files with 226 additions and 236 deletions
|
|
@ -4,8 +4,7 @@ import (
|
|||
"encoding"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/nalgeon/be"
|
||||
)
|
||||
|
||||
var _ encoding.TextUnmarshaler = new(Log)
|
||||
|
|
@ -32,15 +31,15 @@ const all = first + second + third + fourth + skip + fifth
|
|||
func TestLogUnmarshalBig(t *testing.T) {
|
||||
l := &Log{Name: "test-log"}
|
||||
err := l.UnmarshalText([]byte(all))
|
||||
require.NoError(t, err)
|
||||
require.Len(t, l.Entries, 5)
|
||||
be.Err(t, err, nil)
|
||||
be.Equal(t, len(l.Entries), 5)
|
||||
|
||||
var e Entry
|
||||
var f bool
|
||||
if e, f = findEntry(t, l, "This is simple", true); !f {
|
||||
return
|
||||
}
|
||||
assert.Len(t, e.Fields, 0)
|
||||
be.Equal(t, len(e.Fields), 0)
|
||||
|
||||
for _, e := range l.Entries {
|
||||
findMeta(t, e, "ignoreme", true, false)
|
||||
|
|
@ -51,28 +50,28 @@ func TestLogUnmarshalIgnoreGarbage(t *testing.T) {
|
|||
l := &Log{Name: "test-log"}
|
||||
in := "ignore this\n" + second + "some crap also skip -> " + third + skip
|
||||
err := l.UnmarshalText([]byte(in))
|
||||
require.NoError(t, err)
|
||||
require.Len(t, l.Entries, 1)
|
||||
be.Err(t, err, nil)
|
||||
be.Equal(t, len(l.Entries), 1)
|
||||
|
||||
en := l.Entries[0]
|
||||
assert.Equal(t, "We have one thing here", en.Title)
|
||||
assert.Len(t, en.Fields, 1)
|
||||
assert.Equal(t, "foo", en.Fields[0].Key)
|
||||
assert.Equal(t, "bar", en.Fields[0].Value)
|
||||
be.Equal(t, en.Title, "We have one thing here")
|
||||
be.Equal(t, len(en.Fields), 1)
|
||||
be.Equal(t, en.Fields[0].Key, "foo")
|
||||
be.Equal(t, en.Fields[0].Value, "bar")
|
||||
}
|
||||
|
||||
func TestLogUnmarshalEmpty(t *testing.T) {
|
||||
l := &Log{Name: "test-log"}
|
||||
err := l.UnmarshalText([]byte{})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, l.Entries, 0)
|
||||
be.Err(t, err, nil)
|
||||
be.Equal(t, len(l.Entries), 0)
|
||||
}
|
||||
|
||||
func TestLogUnmarshalBad(t *testing.T) {
|
||||
l := &Log{Name: "test-log"}
|
||||
err := l.UnmarshalText([]byte(badEntry))
|
||||
require.NoError(t, err)
|
||||
require.Len(t, l.Entries, 0)
|
||||
be.Err(t, err, nil)
|
||||
be.Equal(t, len(l.Entries), 0)
|
||||
}
|
||||
|
||||
func findEntry(t *testing.T, log *Log, title string, shouldFind bool) (Entry, bool) {
|
||||
|
|
@ -85,9 +84,9 @@ func findEntry(t *testing.T, log *Log, title string, shouldFind bool) (Entry, bo
|
|||
}
|
||||
}
|
||||
if shouldFind {
|
||||
found = assert.Truef(t, found, "Unable to found entry %s", title)
|
||||
be.True(t, found)
|
||||
} else {
|
||||
found = assert.Falsef(t, found, "Entry %s should not have been found but was", title)
|
||||
be.True(t, !found)
|
||||
}
|
||||
|
||||
return ret, found
|
||||
|
|
@ -103,9 +102,9 @@ func findMeta(t *testing.T, entry Entry, key string, value any, shouldFind bool)
|
|||
}
|
||||
}
|
||||
if shouldFind {
|
||||
found = assert.Truef(t, found, "Unable to found meta %s", key)
|
||||
be.True(t, found)
|
||||
} else {
|
||||
found = assert.Falsef(t, found, "Meta %s should not have been found but was", key)
|
||||
be.True(t, !found)
|
||||
}
|
||||
|
||||
return ret, found
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue