1package log
 2
 3import (
 4	"path/filepath"
 5	"testing"
 6
 7	"github.com/charmbracelet/soft-serve/pkg/config"
 8)
 9
10func TestGoodNewLogger(t *testing.T) {
11	for _, c := range []*config.Config{
12		config.DefaultConfig(),
13		{},
14		{Log: config.LogConfig{Path: filepath.Join(t.TempDir(), "logfile.txt")}},
15	} {
16		_, f, err := NewLogger(c)
17		if err != nil {
18			t.Errorf("expected nil got %v", err)
19		}
20		if f != nil {
21			if err := f.Close(); err != nil {
22				t.Errorf("failed to close logger: %v", err)
23			}
24		}
25	}
26}
27
28func TestBadNewLogger(t *testing.T) {
29	for _, c := range []*config.Config{
30		nil,
31		{Log: config.LogConfig{Path: "\x00"}},
32	} {
33		_, f, err := NewLogger(c)
34		if err == nil {
35			t.Errorf("expected error got nil")
36		}
37		if f != nil {
38			if err := f.Close(); err != nil {
39				t.Errorf("failed to close logger: %v", err)
40			}
41		}
42	}
43}