✨ 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
|
|
@ -5,8 +5,7 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/nalgeon/be"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
|
|
@ -16,8 +15,8 @@ func TestLoad(t *testing.T) {
|
|||
fmt.Fprint(f, `[input]
|
||||
ext = "log"`)
|
||||
c, err := Load()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "log", c.Input.Ext)
|
||||
be.Err(t, err, nil)
|
||||
be.Equal(t, c.Input.Ext, "log")
|
||||
}
|
||||
|
||||
func TestLoadBadFile(t *testing.T) {
|
||||
|
|
@ -26,15 +25,15 @@ func TestLoadBadFile(t *testing.T) {
|
|||
defer f.Close()
|
||||
fmt.Fprint(f, `{"not":"toml"}`)
|
||||
_, err := Load()
|
||||
assert.Error(t, err)
|
||||
be.Err(t, err)
|
||||
}
|
||||
|
||||
func TestLoadIgnoreMissingFile(t *testing.T) {
|
||||
def, _ := DefaultConfig()
|
||||
ConfigPath = "/not/a/real/file"
|
||||
c, err := Load()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, def, c)
|
||||
be.Err(t, err, nil)
|
||||
be.Equal(t, c, def)
|
||||
}
|
||||
|
||||
func TestOverride(t *testing.T) {
|
||||
|
|
@ -43,30 +42,30 @@ func TestOverride(t *testing.T) {
|
|||
"input.ext": "~",
|
||||
}
|
||||
c, err := Load()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, Overrides["input.path"], c.Input.Path)
|
||||
assert.Equal(t, "txt", c.Input.Ext)
|
||||
be.Err(t, err, nil)
|
||||
be.Equal(t, c.Input.Path, Overrides["input.path"])
|
||||
be.Equal(t, c.Input.Ext, "txt")
|
||||
}
|
||||
|
||||
func TestOverrideJson(t *testing.T) {
|
||||
Overrides = map[string]string{"input.ext": `{"a":"b"}`}
|
||||
c, err := Load()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "txt", c.Input.Ext)
|
||||
be.Err(t, err, nil)
|
||||
be.Equal(t, c.Input.Ext, "txt")
|
||||
}
|
||||
|
||||
func TestTimeParse(t *testing.T) {
|
||||
Overrides = map[string]string{"input.ext": "now"}
|
||||
c, err := Load()
|
||||
assert.ErrorContains(t, err, "incompatible types: TOML value has type time.Time; destination has type string")
|
||||
assert.Equal(t, "txt", c.Input.Ext)
|
||||
be.Err(t, err, "incompatible types: TOML value has type time.Time; destination has type string")
|
||||
be.Equal(t, c.Input.Ext, "txt")
|
||||
}
|
||||
|
||||
func TestStdoutMissing(t *testing.T) {
|
||||
var oo Outputs = map[string]Output{}
|
||||
std, en := oo.Stdout()
|
||||
assert.False(t, en)
|
||||
assert.Equal(t, Stdout{}, std)
|
||||
be.True(t, !en)
|
||||
be.Equal(t, std, Stdout{})
|
||||
}
|
||||
|
||||
func TestStdoutLoad(t *testing.T) {
|
||||
|
|
@ -76,8 +75,8 @@ func TestStdoutLoad(t *testing.T) {
|
|||
defer os.Unsetenv("LOG_STDOUT_ENABLED")
|
||||
c, _ := Load()
|
||||
std, en := c.Outputs.Stdout()
|
||||
assert.True(t, en)
|
||||
assert.Equal(t, "json", std.Format)
|
||||
be.True(t, en)
|
||||
be.Equal(t, std.Format, "json")
|
||||
}
|
||||
|
||||
func TestFormatJson(t *testing.T) {
|
||||
|
|
@ -86,9 +85,9 @@ func TestFormatJson(t *testing.T) {
|
|||
}
|
||||
|
||||
js := ff.Json()
|
||||
assert.True(t, js.PrettyPrint)
|
||||
be.True(t, js.PrettyPrint)
|
||||
|
||||
ff = Formatters{}
|
||||
js = ff.Json()
|
||||
assert.False(t, js.PrettyPrint)
|
||||
be.True(t, !js.PrettyPrint)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue