forked from mantzas/patron
-
Notifications
You must be signed in to change notification settings - Fork 67
/
service_test.go
60 lines (53 loc) · 1.45 KB
/
service_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 patron
import (
"log/slog"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNew(t *testing.T) {
httpBuilderAllErrors := "attributes are empty\nprovided WithSIGHUP handler was nil"
tests := map[string]struct {
name string
fields []slog.Attr
sighupHandler func()
uncompressedPaths []string
wantErr string
}{
"success": {
name: "name",
fields: []slog.Attr{slog.String("env", "dev")},
sighupHandler: func() { slog.Info("WithSIGHUP received: nothing setup") },
uncompressedPaths: []string{"/foo", "/bar"},
wantErr: "",
},
"name missing": {
wantErr: "name is required",
},
"nil inputs steps": {
name: "name",
wantErr: httpBuilderAllErrors,
},
"error in all builder steps": {
name: "name",
uncompressedPaths: []string{},
wantErr: httpBuilderAllErrors,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
gotService, gotErr := New(tt.name, "1.0",
WithLogFields(tt.fields...), WithJSONLogger(), WithSIGHUP(tt.sighupHandler))
if tt.wantErr != "" {
require.EqualError(t, gotErr, tt.wantErr)
assert.Nil(t, gotService)
} else {
require.NoError(t, gotErr)
assert.NotNil(t, gotService)
assert.IsType(t, &Service{}, gotService)
assert.NotNil(t, gotService.termSig)
assert.NotNil(t, gotService.sighupHandler)
}
})
}
}