forked from go-sprout/sprout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprout_test.go
60 lines (45 loc) · 1.22 KB
/
sprout_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package sprout
import (
"log/slog"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewFunctionHandler_DefaultValues(t *testing.T) {
handler := NewFunctionHandler()
assert.NotNil(t, handler)
assert.NotNil(t, handler.Logger)
}
func TestNewFunctionHandler_CustomValues(t *testing.T) {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
handler := NewFunctionHandler(
WithLogger(logger),
)
assert.NotNil(t, handler)
assert.Equal(t, logger, handler.Logger())
}
func TestWithLogger(t *testing.T) {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
option := WithLogger(logger)
handler := NewFunctionHandler()
option(handler) // Apply the option
assert.Equal(t, logger, handler.Logger())
}
func TestWithParser(t *testing.T) {
fnHandler := &DefaultHandler{
logger: slog.New(slog.NewTextHandler(os.Stdout, nil)),
}
option := WithHandler(fnHandler)
handler := New()
option(handler) // Apply the option
assert.Equal(t, fnHandler, handler)
}
func TestWithNilHandler(t *testing.T) {
fnHandler := &DefaultHandler{
logger: slog.New(slog.NewTextHandler(os.Stdout, nil)),
}
option := WithHandler(nil)
beforeApply := fnHandler
option(beforeApply)
assert.Equal(t, beforeApply, fnHandler)
}