-
Notifications
You must be signed in to change notification settings - Fork 0
/
default-api-test.go
75 lines (58 loc) · 1.36 KB
/
default-api-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
package testools
import (
"net/http/httptest"
"testing"
"github.com/cdvelop/api"
"github.com/cdvelop/cutkey"
"github.com/cdvelop/fetchserver"
"github.com/cdvelop/fileserver"
"github.com/cdvelop/logserver"
"github.com/cdvelop/model"
)
// default:
// h.FileRootFolder = "./test_folder"
// h.App_name = "testApp"
func NewApiTestDefault(t *testing.T, h *model.MainHandler, add_modules ...*model.Module) (at *ApiTest, err string) {
if h.AppInfo.App_name == "" {
h.App_name = "testApp"
h.Business_name = "Business Testing"
h.Business_address = "Street 54 New York"
h.Business_phone = "555-4255-455"
}
h.ProductionMode = false
if h.FileRootFolder == "" {
h.FileRootFolder = "./test_folder"
}
if h.SessionBackendAdapter == nil {
h.SessionBackendAdapter = AuthTest{}
}
if h.Logger == nil {
h.Logger = logserver.AddLoggerAdapter()
}
h.AddModules(add_modules...)
cutkey.AddDataConverter(h)
err = fetchserver.AddFetchAdapter(h)
if err != "" {
return nil, err
}
if h.FileApi == nil {
_, err := fileserver.AddFileApi(h)
if err != "" {
return nil, err
}
}
if h.BackendBootDataUser == nil {
h.BackendBootDataUser = AuthTest{}
}
conf, err := api.Add(h, nil)
if err != "" {
return nil, err
}
mux := conf.ServeMuxAndRoutes()
new := &ApiTest{
T: t,
Server: httptest.NewServer(mux),
MainHandler: h,
}
return new, ""
}