iris/_examples/routing/custom-wrapper/main_test.go
Gerasimos (Makis) Maropoulos d0104defa8 create the new FileServer and HandleDir, deprecate the rest APIBuilder/Party static methods and more
relative: https://github.com/kataras/iris/issues/1283 and removing pongo2 from vendor: https://github.com/kataras/iris/issues/1284

Former-commit-id: 3ec57b349f99faca2b8e36d9f7252db0b6ea080d
2019-06-21 19:43:25 +03:00

62 lines
1004 B
Go

package main
import (
"io/ioutil"
"path/filepath"
"strings"
"testing"
"github.com/kataras/iris/httptest"
)
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)
b, err := ioutil.ReadFile(fullpath)
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().
Status(httptest.StatusOK).
Body().Equal(contents)
}
e.GET("/other/something").Expect().Status(httptest.StatusOK)
}