35 lines
845 B
Go
35 lines
845 B
Go
package main
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestIndependentExampleAndHTTP(t *testing.T) {
|
|
b, err := bundle()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if missing := b.Check(); len(missing) != 0 {
|
|
t.Fatal(missing)
|
|
}
|
|
a, err := application(b)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer a.Close()
|
|
for _, test := range []struct {
|
|
path, part string
|
|
status int
|
|
}{{"/api/limit", "数量不能超过 100", 409}, {"/locales/zh-Hans.json", `"namespace": "ui"`, 200}, {"/runtime.mjs", "createLanguageController", 200}, {"/", "draft", 200}} {
|
|
w := httptest.NewRecorder()
|
|
r := httptest.NewRequest("GET", test.path, nil)
|
|
r.Header.Set("Accept-Language", "zh-CN")
|
|
a.ServeHTTP(w, r)
|
|
if w.Code != test.status || !strings.Contains(w.Body.String(), test.part) {
|
|
t.Fatal(test.path, w.Code, w.Body.String())
|
|
}
|
|
}
|
|
}
|