-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathredoc_test.go
39 lines (28 loc) · 1.2 KB
/
redoc_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
package micro
import (
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRedoc(t *testing.T) {
req := httptest.NewRequest("GET", "/docs", nil)
recorder := httptest.NewRecorder()
redoc := &RedocOpts{}
redoc.Serve(recorder, req, map[string]string{})
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "text/html; charset=utf-8", recorder.Header().Get("Content-Type"))
assert.Contains(t, recorder.Body.String(), "<title>API documentation</title>")
}
func TestRedoc2(t *testing.T) {
req := httptest.NewRequest("GET", "/docs", nil)
recorder := httptest.NewRecorder()
redoc := &RedocOpts{}
redoc.AddSpec("PetStore", "https://rebilly.github.io/ReDoc/swagger.yaml")
redoc.AddSpec("Instagram", "https://api.apis.guru/v2/specs/instagram.com/1.0.0/swagger.yaml")
redoc.AddSpec("Google Calendar", "https://api.apis.guru/v2/specs/googleapis.com/calendar/v3/swagger.yaml")
redoc.Serve(recorder, req, map[string]string{})
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "text/html; charset=utf-8", recorder.Header().Get("Content-Type"))
assert.Contains(t, recorder.Body.String(), "<title>API documentation</title>")
assert.Contains(t, recorder.Body.String(), "Google Calendar")
}