forked from prymitive/karma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assets_test.go
82 lines (76 loc) · 2 KB
/
assets_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
package main
import (
"net/http/httptest"
"testing"
"github.com/prymitive/karma/internal/config"
)
type customizationAssetsTest struct {
customJS string
customCSS string
path string
code int
body string
mime string
}
func TestCustomizationAssets(t *testing.T) {
customizationAssetsTests := []customizationAssetsTest{
{
path: "/custom.js",
code: 200,
body: "",
mime: "application/javascript",
},
{
path: "/custom.css",
code: 200,
body: "",
mime: "text/css",
},
{
customJS: "foo/bar/custom.js",
path: "/custom.js",
code: 404,
body: "foo/bar/custom.js not found",
mime: "application/javascript",
},
{
customCSS: "foo/bar/custom.css",
path: "/custom.css",
code: 404,
body: "foo/bar/custom.css not found",
mime: "text/css",
},
{
customJS: "ui/.env",
path: "/custom.js",
code: 200,
body: "NODE_PATH=src\nPUBLIC_URL=.\n",
mime: "text/plain; charset=utf-8",
},
{
customCSS: "ui/.env",
path: "/custom.css",
code: 200,
body: "NODE_PATH=src\nPUBLIC_URL=.\n",
mime: "text/plain; charset=utf-8",
},
}
mockConfig()
for _, staticFileTest := range customizationAssetsTests {
config.Config.Custom.CSS = staticFileTest.customCSS
config.Config.Custom.JS = staticFileTest.customJS
r := ginTestEngine()
req := httptest.NewRequest("GET", staticFileTest.path, nil)
resp := httptest.NewRecorder()
r.ServeHTTP(resp, req)
if resp.Code != staticFileTest.code {
t.Errorf("Invalid status code for GET %s: %d", staticFileTest.path, resp.Code)
}
if resp.Body.String() != staticFileTest.body {
t.Errorf("Invalid body for GET %s: %s, expected %s", staticFileTest.path, resp.Body.String(), staticFileTest.body)
}
if resp.Result().Header.Get("Content-Type") != staticFileTest.mime {
t.Errorf("Invalid Content-Type for GET %s: %s, expected %s", staticFileTest.path, resp.Result().Header.Get("Content-Type"), staticFileTest.mime)
}
}
}