Add Formatter.Logs

This commit is contained in:
Dan Jones 2024-03-10 11:31:07 -05:00
commit d1b3604e1e
3 changed files with 54 additions and 2 deletions

View file

@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require"
)
func TestPlainLog(t *testing.T) {
func TestPlainLogs(t *testing.T) {
m := []models.Meta{
{"foo", "bar"},
{"baz", 42},
@ -23,11 +23,17 @@ func TestPlainLog(t *testing.T) {
{Title: "small", Date: time.Now()},
}
l := models.Log{"stuff", e}
e2 := models.Entry{
Title: "three",
Date: time.Now(),
}
l2 := models.Log{"more-stuff", []models.Entry{e2}}
logs := []models.Log{l, l2}
f, err := New("plain")
require.NoError(t, err)
out, err := f.Log(l)
out, err := f.Logs(logs)
require.NoError(t, err)
read := bytes.NewReader(out)
@ -67,6 +73,24 @@ func TestPlainLog(t *testing.T) {
line = scan.Text()
assert.Equal(t, "Date: "+e[1].Date.Format(tools.DateFormat), line)
scan.Scan()
scan.Scan()
line = scan.Text()
assert.Equal(t, l2.Name, line)
scan.Scan()
line = scan.Text()
assert.Equal(t, "#######", line)
scan.Scan()
scan.Scan()
line = scan.Text()
assert.Equal(t, "Title: "+e2.Title, line)
scan.Scan()
line = scan.Text()
assert.Equal(t, "Date: "+e2.Date.Format(tools.DateFormat), line)
more := scan.Scan()
assert.False(t, more)
}
@ -76,6 +100,13 @@ func TestPlainName(t *testing.T) {
assert.Equal(t, "plain", f.Name())
}
func TestPlainLogNone(t *testing.T) {
f, _ := New("plain")
out, err := f.Logs([]models.Log{})
assert.NoError(t, err)
assert.Len(t, out, 0)
}
func TestPlainLogNoEntries(t *testing.T) {
f, _ := New("plain")
out, err := f.Log(models.Log{Name: "foo"})