1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-23 19:23:48 +00:00

Merge pull request #421 from Fenny/master

Add static index test
This commit is contained in:
fenny 2020-05-29 04:26:49 -04:00 committed by GitHub
commit c9664609ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

14
.github/index.html vendored Normal file
View 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>

View File

@ -8,6 +8,7 @@ import (
"io/ioutil"
"net"
"net/http/httptest"
"strings"
"testing"
"time"
@ -204,6 +205,22 @@ func Test_App_Shutdown(t *testing.T) {
}
// 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) {
app := New()