forked from gnolang/gno
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
55 lines (51 loc) · 1.51 KB
/
main_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
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"github.com/gotuna/gotuna/test/assert"
)
func TestRoutes(t *testing.T) {
ok := http.StatusOK
routes := []struct {
route string
status int
substring string
}{
{"/", ok, "Welcome"}, // assert / gives 200 (OK). assert / contains "Welcome".
{"/about", ok, "blockchain"},
{"/r/gnoland/blog", ok, ""}, // whatever content
{"/r/gnoland/blog?help", ok, "exposed"},
{"/r/gnoland/blog/", ok, "admin.gno"},
{"/r/gnoland/blog/admin.gno", ok, "func "},
{"/r/demo/users:administrator", ok, "address"},
{"/r/demo/users", ok, "manfred"},
{"/r/demo/users/types.gno", ok, "type "},
{"/r/demo/deep/very/deep", ok, "it works!"},
{"/r/demo/deep/very/deep:bob", ok, "hi bob"},
{"/r/demo/deep/very/deep?help", ok, "exposed"},
{"/r/demo/deep/very/deep/", ok, "render.gno"},
{"/r/demo/deep/very/deep/render.gno", ok, "func Render("},
}
if wd, err := os.Getwd(); err == nil {
if strings.HasSuffix(wd, "cmd/gnoweb") {
os.Chdir("../..")
}
} else {
panic("os.Getwd() -> err: " + err.Error())
}
app := makeApp()
for _, r := range routes {
t.Run(fmt.Sprintf("test route %s", r.route), func(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, r.route, nil)
response := httptest.NewRecorder()
app.Router.ServeHTTP(response, request)
assert.Equal(t, r.status, response.Code)
assert.Equal(t, strings.Contains(response.Body.String(), r.substring), true)
println(response.Body.String())
})
}
}