-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils.go
More file actions
51 lines (45 loc) · 1.18 KB
/
Copy pathtest_utils.go
File metadata and controls
51 lines (45 loc) · 1.18 KB
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
package main
import (
"database/sql"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"testing"
"scadrialapi.abdulmoiz.net/internal/data"
"scadrialapi.abdulmoiz.net/internal/mailer"
)
func NewTestApplication(t *testing.T, mockUsers data.UserModelInterface, mockPermissions data.PermissionModelInterface) *application {
cfg := config{}
cfg.limiter.enabled = false
return &application{
config: cfg,
logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
models: data.Models{
Users: mockUsers,
Permissions: mockPermissions,
},
mailer: mailer.New("", 25, "", "", ""),
}
}
func newTestServer(t *testing.T, h http.Handler) *httptest.Server {
t.Helper()
ts := httptest.NewServer(h)
return ts
}
func newE2EApplication(t *testing.T, db *sql.DB) *application {
t.Helper()
cfg := config{}
cfg.limiter.enabled = false
return &application{
config: cfg,
logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
models: data.NewModels(
data.MovieModel{DB: db},
data.UserModel{DB: db},
data.TokenModel{DB: db},
data.PermissionModel{DB: db},
),
mailer: mailer.New(cfg.smtp.host, cfg.smtp.port, cfg.smtp.username, cfg.smtp.password, cfg.smtp.sender),
}
}