-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparseRoutes_test.go
87 lines (76 loc) · 1.73 KB
/
parseRoutes_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package astra
import (
"github.com/stretchr/testify/require"
"os"
"path"
"testing"
)
func TestService_ParseRoutes(t *testing.T) {
t.Run("parse routes is called and create routes is not", func(t *testing.T) {
var createRoutesCalled bool
var parseRoutesCalled bool
service := &Service{
Inputs: []Input{
{
Mode: "",
CreateRoutes: func(service *Service) error {
createRoutesCalled = true
return nil
},
ParseRoutes: func(service *Service) error {
parseRoutesCalled = true
return nil
},
},
},
}
err := service.ParseRoutes()
require.NoError(t, err)
require.False(t, createRoutesCalled)
require.True(t, parseRoutesCalled)
})
t.Run("caches service if enabled", func(t *testing.T) {
t.Run("enabled", func(t *testing.T) {
service := &Service{
CacheEnabled: true,
Inputs: []Input{
{
ParseRoutes: func(service *Service) error {
return nil
},
},
},
}
err := service.Setup()
require.NoError(t, err)
defer func() {
err = service.ClearCache()
require.NoError(t, err)
}()
err = service.Generate()
require.NoError(t, err)
stat, err := os.Stat(path.Join(service.getAstraDirPath(), cacheFileName))
require.NoError(t, err)
require.NotNil(t, stat)
})
t.Run("disabled", func(t *testing.T) {
service := &Service{
CacheEnabled: false,
Inputs: []Input{
{
ParseRoutes: func(service *Service) error {
return nil
},
},
},
}
err := service.Setup()
require.NoError(t, err)
err = service.ParseRoutes()
require.NoError(t, err)
stat, err := os.Stat(path.Join(service.getAstraDirPath(), cacheFileName))
require.Error(t, err)
require.Nil(t, stat)
})
})
}