-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils_test.go
152 lines (133 loc) · 3.15 KB
/
utils_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package files
import (
"os"
"github.com/brianvoe/gofakeit"
"github.com/go-catupiry/catu"
files_storages "github.com/go-catupiry/files/storages"
"github.com/pkg/errors"
)
var appInstance catu.App
func GetAppInstance() catu.App {
if appInstance != nil {
return appInstance
}
os.Setenv("DB_URI", "file::memory:?cache=shared")
os.Setenv("DB_ENGINE", "sqlite")
// os.Setenv("LOG_QUERY", "1")
app := catu.Init(&catu.AppOptions{})
app.RegisterPlugin(NewPlugin(&FilePluginCfgs{
Storages: map[string]Storager{
"file": files_storages.NewLocal(&files_storages.LocalCfg{
App: app,
DestinationPath: "/tmp/_test_files",
}),
"image": files_storages.NewLocal(&files_storages.LocalCfg{
App: app,
DestinationPath: "/tmp/_test_files",
}),
},
FileStorageName: "file",
ImageStorageName: "image",
ImageStyles: map[string]ImageStyleCfg{
"thumbnail": {
Width: 75,
Height: 75,
},
"medium": {
Width: 250,
Height: 250,
},
"large": {
Width: 640,
Height: 400,
},
"banner": {
Width: 900,
Height: 300,
},
},
}))
err := app.Bootstrap()
if err != nil {
panic(err)
}
// fake content stub for tests:
err = app.GetDB().AutoMigrate(
&ContentModelStub{},
&ImageModel{},
&ImageAssocsModel{},
&FileModel{},
&FileAssocsModel{},
)
if err != nil {
panic(errors.Wrap(err, "file.GetAppInstance Error on run auto migration"))
}
return app
}
type ContentModelStub struct {
ID uint64 `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
Published bool `json:"published"`
ClickCount int64 `json:"clickCount"`
Secret string `json:"-"`
Email string `json:"email"`
Email2 string `json:"email2"`
PrivateBio string `json:"-"`
}
func GetContentModelStub() ContentModelStub {
return ContentModelStub{
// ID: gofakeit.Uint64(),
Title: gofakeit.Paragraph(1, 4, 4, " "),
Body: gofakeit.Paragraph(1, 3, 5, " "),
Published: true,
Secret: gofakeit.Word(),
Email: gofakeit.Email(),
Email2: gofakeit.Email(),
PrivateBio: gofakeit.Paragraph(1, 4, 4, ""),
}
}
func GetImageModelStub() ImageModel {
label := gofakeit.Word()
description := gofakeit.Paragraph(1, 4, 4, " ")
size := int64(10)
mime := "image/jpeg"
extension := "jpg"
r := ImageModel{
Name: gofakeit.Name(),
Label: &label,
Description: &description,
Size: &size,
Mime: &mime,
Originalname: "mimimiim.jpg",
Extension: &extension,
}
r.SetURLs(ImageURL{
"original": gofakeit.Word(),
"thumbnail": gofakeit.Word(),
"medium": gofakeit.Word(),
"large": gofakeit.Word(),
"banner": gofakeit.Word(),
})
return r
}
func GetFileModelStub() FileModel {
label := gofakeit.Word()
description := gofakeit.Paragraph(1, 4, 4, " ")
size := int64(10)
mime := "image/jpeg"
extension := "jpg"
r := FileModel{
Name: gofakeit.Name(),
Label: &label,
Description: &description,
Size: &size,
Mime: &mime,
Originalname: "mimimiim.jpg",
Extension: &extension,
}
r.SetURLs(ImageURL{
"original": gofakeit.Word(),
})
return r
}