2017-06-15 19:02:08 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-06-17 21:03:18 +02:00
|
|
|
"os"
|
2017-06-15 19:02:08 +02:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/httptest"
|
2017-06-15 19:02:08 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type resource string
|
|
|
|
|
|
|
|
func (r resource) String() string {
|
|
|
|
return string(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r resource) strip(strip string) string {
|
|
|
|
s := r.String()
|
|
|
|
return strings.TrimPrefix(s, strip)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r resource) loadFromBase(dir string) string {
|
|
|
|
filename := r.String()
|
|
|
|
|
|
|
|
if filename == "/" {
|
|
|
|
filename = "/index.html"
|
|
|
|
}
|
|
|
|
|
|
|
|
fullpath := filepath.Join(dir, filename)
|
|
|
|
|
2022-06-17 21:03:18 +02:00
|
|
|
b, err := os.ReadFile(fullpath)
|
2017-06-15 19:02:08 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(fullpath + " failed with error: " + err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
var urls = []resource{
|
|
|
|
"/",
|
|
|
|
"/index.html",
|
|
|
|
"/app.js",
|
|
|
|
"/css/main.css",
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCustomWrapper(t *testing.T) {
|
|
|
|
app := newApp()
|
|
|
|
e := httptest.New(t, app)
|
|
|
|
|
|
|
|
for _, u := range urls {
|
|
|
|
url := u.String()
|
|
|
|
contents := u.loadFromBase("./public")
|
|
|
|
|
|
|
|
e.GET(url).Expect().
|
2017-07-10 17:32:42 +02:00
|
|
|
Status(httptest.StatusOK).
|
2017-06-15 19:02:08 +02:00
|
|
|
Body().Equal(contents)
|
|
|
|
}
|
2019-06-21 18:43:25 +02:00
|
|
|
|
|
|
|
e.GET("/other/something").Expect().Status(httptest.StatusOK)
|
2017-06-15 19:02:08 +02:00
|
|
|
}
|