File: rapidoc_test.go

package info (click to toggle)
golang-github-go-openapi-runtime 0.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 944 kB
  • sloc: sh: 9; makefile: 4
file content (22 lines) | stat: -rw-r--r-- 675 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package middleware

import (
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestRapiDocMiddleware(t *testing.T) {
	rapidoc := RapiDoc(RapiDocOpts{}, nil)

	req, _ := http.NewRequest("GET", "/docs", nil)
	recorder := httptest.NewRecorder()
	rapidoc.ServeHTTP(recorder, req)
	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(), "<rapi-doc spec-url=\"/swagger.json\"></rapi-doc>")
	assert.Contains(t, recorder.Body.String(), rapidocLatest)
}