-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoasmodel_test.go
90 lines (80 loc) · 1.66 KB
/
oasmodel_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
84
85
86
87
88
89
90
package oasmodel
import (
"io/ioutil"
"os"
"testing"
"gopkg.in/yaml.v3"
)
func check(data string, t *testing.T) {
var oa OpenAPI
err := yaml.Unmarshal([]byte(data), &oa)
if err != nil {
t.Errorf("error unmarshalling : %v", err)
}
buf, err2 := yaml.Marshal(&oa)
if err2 != nil {
t.Errorf("Marshal: %v", err)
}
if string(buf) != data {
t.Errorf("UnMarshal -> MArshal differs :\n%s\n\n", buf)
// Helper : save the file
err := ioutil.WriteFile("/tmp/dat1.yaml", buf, 0644)
if err != nil {
t.Errorf("error saving tmp file : %v \n", err)
}
}
}
func TestResponseWithRef(t *testing.T) {
data :=
`openapi: 3.0.0
info:
title: test simple
version: 1.0.0
paths:
/test1:
get:
responses:
"200":
$ref: '#/a/b/c'
`
check(data, t)
}
func TestAllRequired(t *testing.T) {
data :=
`openapi: 3.0.0
info:
title: test simple
version: 1.0.0
paths:
/test1:
get:
responses:
"200":
description: pet response
content:
'*/*':
schema:
type: string
`
check(data, t)
}
func TestAssets(t *testing.T) {
var files []os.FileInfo
root := "./assets/"
files, err := ioutil.ReadDir(root)
if err != nil {
t.Errorf("error listings assets : %v", err)
return
}
for i := range files {
if !files[i].IsDir() {
t.Logf("Checking : %s", files[i].Name())
yamlFile, err := ioutil.ReadFile(root + files[i].Name())
if err != nil {
t.Errorf("error loading assets : %s", files[i].Name())
return
}
check(string(yamlFile), t)
}
}
}