-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathswagger_test.go
83 lines (66 loc) · 1.94 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
73
74
75
76
77
78
79
80
81
82
83
package atreugoswagger
import (
"strings"
"testing"
"github.com/savsgio/atreugo/v11"
_ "github.com/swaggo/gin-swagger/example/basic/docs"
"github.com/valyala/fasthttp"
)
func TestWrapHandler(t *testing.T) {
config := atreugo.Config{
Addr: "0.0.0.0:1337",
}
a := atreugo.New(config)
a.GET("/docs/{doc:*}", AtreugoWrapHandler())
a.GET("/api/v1/hello", func(ctx *atreugo.RequestCtx) error {
return ctx.TextResponse("hello", fasthttp.StatusOK)
})
go a.ListenAndServe()
t.Run("Get Index.html", func(t *testing.T) {
status, result, err := fasthttp.Get(nil, "http://localhost:1337/docs/index.html")
if err != nil {
t.Error("failed to call hello: ", err)
}
if status != fasthttp.StatusOK {
t.Error("received wrong statuscode")
}
stringResult := string(result)
if !strings.Contains(stringResult, "<title>Swagger UI</title>") {
t.Error("Could not find swagger title")
}
})
t.Run("Get doc.json", func(t *testing.T) {
status, result, err := fasthttp.Get(nil, "http://localhost:1337/docs/doc.json")
if err != nil {
t.Error("failed to call hello: ", err)
}
if status != fasthttp.StatusOK {
t.Error("received wrong statuscode")
}
stringResult := string(result)
if !strings.Contains(stringResult, `"title": "Swagger Example API",`) {
t.Error("Could not find swagger title")
}
})
t.Run("NotFound", func(t *testing.T) {
status, _, err := fasthttp.Get(nil, "http://localhost:1337/notfound")
if err != nil {
t.Error("failed to call hello: ", err)
}
if status != fasthttp.StatusNotFound {
t.Error("received wrong statuscode")
}
})
t.Run("Get Hello", func(t *testing.T) {
status, response, err := fasthttp.Get(nil, "http://localhost:1337/api/v1/hello")
if err != nil {
t.Error("failed to call hello: ", err)
}
if status != fasthttp.StatusOK {
t.Error("received wrong statuscode")
}
if string(response) != "hello" {
t.Errorf("received wrong response: %s", string(response))
}
})
}