Add plain text formatter

This commit is contained in:
Dan Jones 2024-03-07 10:10:54 -06:00
commit 89e6c2b3bd
5 changed files with 276 additions and 0 deletions

35
formatters/new_test.go Normal file
View file

@ -0,0 +1,35 @@
package formatters
import (
"fmt"
"os"
"testing"
"codeberg.org/danjones000/my-log/config"
"github.com/stretchr/testify/assert"
)
func TestKinds(t *testing.T) {
assert.Equal(t, []string{"plain"}, Kinds())
}
func TestNewUnsupported(t *testing.T) {
f, err := New("nope")
assert.Nil(t, f)
assert.Error(t, err)
}
func TestNewCantGetConfig(t *testing.T) {
f, _ := os.CreateTemp("", "test")
oldConf := config.ConfigPath
config.ConfigPath = f.Name()
defer f.Close()
defer func() {
config.ConfigPath = oldConf
}()
fmt.Fprint(f, `{"not":"toml"}`)
form, err := New("plain")
assert.Nil(t, form)
assert.Error(t, err)
}