This repository was archived by the owner on Apr 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathswagger_test.go
72 lines (64 loc) · 1.6 KB
/
swagger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package swagger
import (
"net/http"
"testing"
_ "github.com/arsmn/fiber-swagger/v2/example/docs"
"github.com/gofiber/fiber/v2"
)
func Test_Swagger(t *testing.T) {
app := *fiber.New()
app.Get("/swag/*", HandlerDefault)
tests := []struct {
name string
url string
statusCode int
contentType string
}{
{
name: "Should be returns status 200 with 'text/html' content-type",
url: "/swag/index.html",
statusCode: 200,
contentType: "text/html",
},
{
name: "Should be returns status 200 with 'application/json' content-type",
url: "/swag/doc.json",
statusCode: 200,
contentType: "application/json",
},
{
name: "Should be returns status 200 with 'image/png' content-type",
url: "/swag/favicon-16x16.png",
statusCode: 200,
contentType: "image/png",
},
{
name: "Should return status 301",
url: "/swag/",
statusCode: 301,
},
{
name: "Should return status 404",
url: "/swag/notfound",
statusCode: 404,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest("GET", tt.url, nil)
resp, err := app.Test(req)
if err != nil {
t.Fatalf(`%s: %s`, t.Name(), err)
}
if resp.StatusCode != tt.statusCode {
t.Fatalf(`%s: StatusCode: got %v - expected %v`, t.Name(), resp.StatusCode, tt.statusCode)
}
if tt.contentType != "" {
ct := resp.Header.Get("Content-Type")
if ct != tt.contentType {
t.Fatalf(`%s: Content-Type: got %s - expected %s`, t.Name(), ct, tt.contentType)
}
}
})
}
}