forked from RedHatInsights/sources-api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenapi_handlers_test.go
56 lines (46 loc) · 1019 Bytes
/
openapi_handlers_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
package main
import (
"encoding/json"
"io"
"net/http"
"os"
"reflect"
"testing"
"github.com/RedHatInsights/sources-api-go/internal/testutils/request"
)
func TestOpenApiReturn(t *testing.T) {
raw, err := os.ReadFile("public/openapi-3-v3.1.json")
if err != nil {
t.Errorf("Failed to read openapi file: %v", err)
}
rawFile := make(map[string]interface{})
err = json.Unmarshal(raw, &rawFile)
if err != nil {
t.Errorf("Failed to marshal json: %v", err)
}
c, rec := request.CreateTestContext(
http.MethodGet,
"/api/sources/v3.1/openapi.json",
nil,
map[string]interface{}{},
)
err = PublicOpenApi("v3.1")(c)
if err != nil {
t.Error(err)
}
if rec.Code != 200 {
t.Errorf("Did not return 200")
}
output, err := io.ReadAll(rec.Body)
if err != nil {
t.Error(err)
}
out := make(map[string]interface{})
err = json.Unmarshal(output, &out)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(out, rawFile) {
t.Errorf("Endpoint did not return the same file as on disk")
}
}