✨ Add bep.JSON helper for JSON assertion in tests
- Create internal/testutil/bep package with JSON helper - Use bep.JSON in formatters/json_test.go, models/entry_test.go, and models/meta_test.go
This commit is contained in:
parent
1110288d84
commit
ebb0b12069
4 changed files with 29 additions and 21 deletions
|
|
@ -1,11 +1,11 @@
|
|||
package formatters
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"codeberg.org/danjones000/my-log/internal/testutil/bep"
|
||||
"codeberg.org/danjones000/my-log/models"
|
||||
"github.com/nalgeon/be"
|
||||
)
|
||||
|
|
@ -21,10 +21,7 @@ func TestJsonMeta(t *testing.T) {
|
|||
exp := `{"foo":42}`
|
||||
o, err := f.Meta(m)
|
||||
be.Err(t, err, nil)
|
||||
var got, want any
|
||||
json.Unmarshal([]byte(exp), &want)
|
||||
json.Unmarshal(o, &got)
|
||||
be.Equal(t, got, want)
|
||||
bep.JSON(t, o, []byte(exp))
|
||||
}
|
||||
|
||||
func TestJsonEntry(t *testing.T) {
|
||||
|
|
@ -39,10 +36,7 @@ func TestJsonEntry(t *testing.T) {
|
|||
exp := fmt.Sprintf(`{"title":"%s","date":"%s","foo":42}`, e.Title, when.Format(time.RFC3339))
|
||||
o, err := f.Entry(e)
|
||||
be.Err(t, err, nil)
|
||||
var got, want any
|
||||
json.Unmarshal([]byte(exp), &want)
|
||||
json.Unmarshal(o, &got)
|
||||
be.Equal(t, got, want)
|
||||
bep.JSON(t, o, []byte(exp))
|
||||
}
|
||||
|
||||
func TestJsonLog(t *testing.T) {
|
||||
|
|
@ -58,10 +52,7 @@ func TestJsonLog(t *testing.T) {
|
|||
exp := fmt.Sprintf(`{"%s":[{"title":"%s","date":"%s","foo":42}]}`, l.Name, e.Title, when.Format(time.RFC3339))
|
||||
o, err := f.Log(l)
|
||||
be.Err(t, err, nil)
|
||||
var got, want any
|
||||
json.Unmarshal([]byte(exp), &want)
|
||||
json.Unmarshal(o, &got)
|
||||
be.Equal(t, got, want)
|
||||
bep.JSON(t, o, []byte(exp))
|
||||
}
|
||||
|
||||
func TestJsonNoLogs(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue