-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmanager_test.go
67 lines (53 loc) · 1.48 KB
/
manager_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
61
62
63
64
65
66
67
package loafergo_test
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
loafergo "github.com/justcodes/loafer-go/v2"
"github.com/justcodes/loafer-go/v2/fake"
)
func createTestConfig() *loafergo.Config {
return &loafergo.Config{
Logger: loafergo.LoggerFunc(func(args ...interface{}) {}),
}
}
func TestManager_RegisterRoute(t *testing.T) {
config := createTestConfig()
manager := loafergo.NewManager(config)
mockRoute := &fake.Router{}
manager.RegisterRoute(mockRoute)
assert.Len(t, manager.GetRoutes(), 1)
}
func TestManager_RegisterRoutes(t *testing.T) {
config := createTestConfig()
manager := loafergo.NewManager(config)
mockRoutes := []loafergo.Router{
&fake.Router{},
&fake.Router{},
}
manager.RegisterRoutes(mockRoutes)
assert.Len(t, manager.GetRoutes(), 2)
}
func TestManager_Run(t *testing.T) {
t.Run("Should return error when configure error", func(t *testing.T) {
ctx := context.Background()
config := createTestConfig()
manager := loafergo.NewManager(config)
mockRoute := &fake.Router{}
mockRoute.On("Configure", context.Background()).
Return(fmt.Errorf("error")).
Once()
manager.RegisterRoute(mockRoute)
err := manager.Run(ctx)
assert.NotNil(t, err)
})
t.Run("Should return error no routes", func(t *testing.T) {
ctx := context.Background()
config := createTestConfig()
manager := loafergo.NewManager(config)
err := manager.Run(ctx)
assert.NotNil(t, err)
assert.ErrorIs(t, err, loafergo.ErrNoRoute)
})
}