forked from Tufin/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-request-property-became-not-nuallable_test.go
108 lines (93 loc) · 4.06 KB
/
check-request-property-became-not-nuallable_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/diff"
)
// CL: changing request property to not nullable
func TestRequestPropertyBecameNotNullable(t *testing.T) {
s1, err := open("../data/checker/request_property_became_nullable_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_became_nullable_base.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestPropertyBecomeNotNullableId,
Text: "the request property 'name' became not nullable",
Comment: "",
Level: checker.ERR,
Operation: "POST",
Path: "/products",
Source: "../data/checker/request_property_became_nullable_base.yaml",
OperationId: "addProduct",
}, errs[0])
}
// CL: changing request property to nullable
func TestRequestPropertyBecameNullable(t *testing.T) {
s1, err := open("../data/checker/request_property_became_nullable_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_became_nullable_revision.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestPropertyBecomeNullableId,
Text: "the request property 'name' became nullable",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/products",
Source: "../data/checker/request_property_became_nullable_revision.yaml",
OperationId: "addProduct",
}, errs[0])
}
// CL: changing request body to nullable
func TestRequestBodyBecameNullable(t *testing.T) {
s1, err := open("../data/checker/request_property_became_nullable_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_became_nullable_base.yaml")
require.NoError(t, err)
s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Nullable = true
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestBodyBecomeNullableId,
Text: "the request's body became nullable",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/products",
Source: "../data/checker/request_property_became_nullable_base.yaml",
OperationId: "addProduct",
}, errs[0])
}
// CL: changing request body to not nullable
func TestRequestBodyBecameNotNullable(t *testing.T) {
s1, err := open("../data/checker/request_property_became_nullable_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_became_nullable_base.yaml")
require.NoError(t, err)
s1.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Nullable = true
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.ERR)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestBodyBecomeNotNullableId,
Text: "the request's body became not nullable",
Comment: "",
Level: checker.ERR,
Operation: "POST",
Path: "/products",
Source: "../data/checker/request_property_became_nullable_base.yaml",
OperationId: "addProduct",
}, errs[0])
}