mirror of
https://github.com/gofiber/fiber.git
synced 2025-04-27 21:25:34 +00:00
Add static index test
This commit is contained in:
parent
4ac4a53802
commit
dfb992dcdf
14
.github/index.html
vendored
Normal file
14
.github/index.html
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Test file</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
Hello, World!
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
17
app_test.go
17
app_test.go
@ -8,6 +8,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -204,6 +205,22 @@ func Test_App_Shutdown(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// go test -run Test_App_Static
|
// go test -run Test_App_Static
|
||||||
|
func Test_App_Static_Index(t *testing.T) {
|
||||||
|
app := New()
|
||||||
|
|
||||||
|
app.Static("/", "./.github")
|
||||||
|
|
||||||
|
req := httptest.NewRequest("GET", "/", nil)
|
||||||
|
resp, err := app.Test(req)
|
||||||
|
utils.AssertEqual(t, nil, err, "app.Test(req)")
|
||||||
|
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
|
||||||
|
utils.AssertEqual(t, false, resp.Header.Get("Content-Length") == "")
|
||||||
|
utils.AssertEqual(t, "text/html; charset=utf-8", resp.Header.Get("Content-Type"))
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
utils.AssertEqual(t, nil, err)
|
||||||
|
utils.AssertEqual(t, true, strings.Contains(string(body), "Hello, World!"))
|
||||||
|
}
|
||||||
func Test_App_Static_Group(t *testing.T) {
|
func Test_App_Static_Group(t *testing.T) {
|
||||||
app := New()
|
app := New()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user