Fix tests. (#112)

Update .gitignore to ignore builds/ directory
This commit is contained in:
Nova Kwok 2022-03-24 21:25:44 +08:00 committed by GitHub
parent 8d3e493931
commit 7fcc0b0e5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

3
.gitignore vendored
View File

@ -13,10 +13,11 @@
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
exhaust/ exhaust/
builds/
/.idea/.gitignore /.idea/.gitignore
/.idea/misc.xml /.idea/misc.xml
/.idea/modules.xml /.idea/modules.xml
/.idea/vcs.xml /.idea/vcs.xml
/.idea/webp_server_go.iml /.idea/webp_server_go.iml
remote-raw/ remote-raw/
coverage.txt coverage.txt

View File

@ -5,13 +5,14 @@
package main package main
import ( import (
"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/assert"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
"testing" "testing"
"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/assert"
) )
var ( var (
@ -73,7 +74,7 @@ func TestConvert(t *testing.T) {
"http://127.0.0.1:3333/webp_server.bmp": "image/webp", "http://127.0.0.1:3333/webp_server.bmp": "image/webp",
"http://127.0.0.1:3333/webp_server.png": "image/webp", "http://127.0.0.1:3333/webp_server.png": "image/webp",
"http://127.0.0.1:3333/empty.jpg": "", "http://127.0.0.1:3333/empty.jpg": "",
"http://127.0.0.1:3333/png.jpg": "image/webp", "http://127.0.0.1:3333/png.jpg": "image/png",
"http://127.0.0.1:3333/12314.jpg": "", "http://127.0.0.1:3333/12314.jpg": "",
"http://127.0.0.1:3333/dir1/inside.jpg": "image/webp", "http://127.0.0.1:3333/dir1/inside.jpg": "image/webp",
"http://127.0.0.1:3333/%e5%a4%aa%e7%a5%9e%e5%95%a6.png": "image/webp", "http://127.0.0.1:3333/%e5%a4%aa%e7%a5%9e%e5%95%a6.png": "image/webp",
@ -116,11 +117,10 @@ func TestConvertNotAllowed(t *testing.T) {
var app = fiber.New() var app = fiber.New()
app.Get("/*", convert) app.Get("/*", convert)
// not allowed, but we have the file // not allowed, but we have the file, this should return File extension not allowed
url := "http://127.0.0.1:3333/webp_server.bmp" url := "http://127.0.0.1:3333/webp_server.bmp"
_, data := requestToServer(url, app, chromeUA, acceptWebP) _, data := requestToServer(url, app, chromeUA, acceptWebP)
contentType := getFileContentType(data) assert.Contains(t, string(data), "File extension not allowed")
assert.Equal(t, "image/bmp", contentType)
// not allowed, random file // not allowed, random file
url = url + "hagdgd" url = url + "hagdgd"