forked from Tufin/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_test.go
90 lines (70 loc) · 2.54 KB
/
text_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 report_test
import (
"fmt"
"testing"
"github.com/getkin/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/report"
)
func l(t *testing.T, v int) *openapi3.T {
t.Helper()
loader := openapi3.NewLoader()
oas, err := loader.LoadFromFile(fmt.Sprintf("../data/openapi-test%d.yaml", v))
require.NoError(t, err)
return oas
}
func d(t *testing.T, config *diff.Config, v1, v2 int) *diff.Diff {
t.Helper()
d, err := diff.Get(config, l(t, v1), l(t, v2))
require.NoError(t, err)
return d
}
func Test_NoChanges(t *testing.T) {
require.Equal(t, report.GetTextReportAsString(d(t, diff.NewConfig(), 3, 3)), "No changes\n")
}
func Test_NoEndpointChanges(t *testing.T) {
s1 := openapi3.T{
Info: &openapi3.Info{},
}
s2 := openapi3.T{
Info: &openapi3.Info{
Title: "reuven",
},
}
dd, err := diff.Get(diff.NewConfig(), &s1, &s2)
require.NoError(t, err)
require.Equal(t, report.GetTextReportAsString(dd), "No endpoint changes, but there are some other changes\n")
}
func TestText1(t *testing.T) {
require.Contains(t, report.GetTextReportAsString(d(t, &diff.Config{}, 3, 5)), "GET /api/{domain}/{project}/install-command")
}
func TestText2(t *testing.T) {
require.Contains(t, report.GetTextReportAsString(d(t, &diff.Config{}, 5, 3)), "Deleted response: 201")
}
func TestText3(t *testing.T) {
textReport := report.GetTextReportAsString(d(t, &diff.Config{}, 1, 3))
require.Contains(t, textReport, "New enum values: [test1]")
require.Contains(t, textReport, "Scheme OAuth Added scopes: [write:pets]")
}
func TestText4(t *testing.T) {
textReport := report.GetTextReportAsString(d(t, &diff.Config{}, 3, 1))
require.Contains(t, textReport, "New security requirements: bearerAuth")
require.Contains(t, textReport, "Scheme OAuth Deleted scopes: [write:pets]")
}
func TestText5(t *testing.T) {
textReport := report.GetTextReportAsString(d(t, &diff.Config{}, 2, 1))
require.Contains(t, textReport, "Type changed from 'integer' to 'string'")
}
func TestText6(t *testing.T) {
textReport := report.GetTextReportAsString(d(t, &diff.Config{}, 1, 5))
require.Contains(t, textReport, "Type changed from 'string' to 'object'")
}
func TestText_DerefUint64(t *testing.T) {
textReport := report.GetTextReportAsString(d(t, &diff.Config{}, 1, 3))
require.Contains(t, textReport, "MaxLength changed from 29 to 30")
}
func TestText_DerefUint64Nil(t *testing.T) {
textReport := report.GetTextReportAsString(d(t, &diff.Config{}, 1, 5))
require.Contains(t, textReport, "MaxLength changed from 29 to null")
}