- commit
- 220bdce
- parent
- 72b3683
- author
- Eric Bower
- date
- 2024-10-16 22:34:58 +0000 UTC
chore(pgs): api tests
1 files changed,
+98,
-0
+98,
-0
1@@ -82,6 +82,104 @@ func TestApiBasic(t *testing.T) {
2 },
3 },
4 },
5+ {
6+ name: "direct-file",
7+ path: "/test.html",
8+ want: "hello world!",
9+ status: http.StatusOK,
10+ contentType: "text/html",
11+
12+ dbpool: NewPgsDb(cfg.Logger),
13+ storage: map[string]map[string]string{
14+ bucketName: {
15+ "test/test.html": "hello world!",
16+ },
17+ },
18+ },
19+ {
20+ name: "subdir-301-redirect",
21+ path: "/subdir",
22+ want: `<a href="/subdir/">Moved Permanently</a>.`,
23+ status: http.StatusMovedPermanently,
24+ contentType: "text/html; charset=utf-8",
25+
26+ dbpool: NewPgsDb(cfg.Logger),
27+ storage: map[string]map[string]string{
28+ bucketName: {
29+ "test/subdir/index.html": "hello world!",
30+ },
31+ },
32+ },
33+ {
34+ name: "redirects-file-301",
35+ path: "/anything",
36+ want: `<a href="/about.html">Moved Permanently</a>.`,
37+ status: http.StatusMovedPermanently,
38+ contentType: "text/html; charset=utf-8",
39+
40+ dbpool: NewPgsDb(cfg.Logger),
41+ storage: map[string]map[string]string{
42+ bucketName: {
43+ "test/_redirects": "/anything /about.html 301",
44+ "test/about.html": "hello world!",
45+ },
46+ },
47+ },
48+ {
49+ name: "subdir-direct",
50+ path: "/subdir/index.html",
51+ want: "hello world!",
52+ status: http.StatusOK,
53+ contentType: "text/html",
54+
55+ dbpool: NewPgsDb(cfg.Logger),
56+ storage: map[string]map[string]string{
57+ bucketName: {
58+ "test/subdir/index.html": "hello world!",
59+ },
60+ },
61+ },
62+ {
63+ name: "spa",
64+ path: "/anything",
65+ want: "hello world!",
66+ status: http.StatusOK,
67+ contentType: "text/html",
68+
69+ dbpool: NewPgsDb(cfg.Logger),
70+ storage: map[string]map[string]string{
71+ bucketName: {
72+ "test/_redirects": "/* /index.html 200",
73+ "test/index.html": "hello world!",
74+ },
75+ },
76+ },
77+ {
78+ name: "not-found",
79+ path: "/anything",
80+ want: "404 not found",
81+ status: http.StatusNotFound,
82+ contentType: "text/plain; charset=utf-8",
83+
84+ dbpool: NewPgsDb(cfg.Logger),
85+ storage: map[string]map[string]string{
86+ bucketName: {},
87+ },
88+ },
89+ {
90+ name: "not-found-custom",
91+ path: "/anything",
92+ want: "boom!",
93+ status: http.StatusNotFound,
94+ contentType: "text/html",
95+
96+ dbpool: NewPgsDb(cfg.Logger),
97+ storage: map[string]map[string]string{
98+ bucketName: {
99+ "test/404.html": "boom!",
100+ },
101+ },
102+ },
103 }
104
105 for _, tc := range tt {