-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathcheck_request_property_default_value_changed_test.go
122 lines (109 loc) · 5.21 KB
/
check_request_property_default_value_changed_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)
// CL: changing request body default value
func TestRequestBodyDefaultValueChanged(t *testing.T) {
s1, err := open("../data/checker/request_body_default_value_changed_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_body_default_value_changed_revision.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyDefaultValueChangedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestBodyDefaultValueChangedId,
Args: []any{"text/plain", "Default", "NewDefault"},
Level: checker.INFO,
Operation: "POST",
Path: "/products",
Source: load.NewSource("../data/checker/request_body_default_value_changed_revision.yaml"),
OperationId: "createProduct",
}, errs[0])
}
// CL: changing request property default value
func TestRequestPropertyDefaultValueChanged(t *testing.T) {
s1, err := open("../data/checker/request_property_default_value_changed_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_default_value_changed_base.yaml")
require.NoError(t, err)
s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["price"].Value.Default = 20.0
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyDefaultValueChangedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestPropertyDefaultValueChangedId,
Args: []any{"price", 10.0, 20.0},
Level: checker.INFO,
Operation: "POST",
Path: "/products",
Source: load.NewSource("../data/checker/request_property_default_value_changed_base.yaml"),
OperationId: "createProduct",
}, errs[0])
}
// CL: adding request body default value or request property default value
func TestRequestBodyDefaultValueAdded(t *testing.T) {
s1, err := open("../data/checker/request_body_default_value_changed_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_body_default_value_changed_base.yaml")
require.NoError(t, err)
s1.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["text/plain"].Schema.Value.Default = nil
s1.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["price"].Value.Default = nil
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyDefaultValueChangedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{{
Id: checker.RequestBodyDefaultValueAddedId,
Args: []any{"text/plain", "Default"},
Level: checker.INFO,
Operation: "POST",
Path: "/products",
Source: load.NewSource("../data/checker/request_body_default_value_changed_base.yaml"),
OperationId: "createProduct",
}, {
Id: checker.RequestPropertyDefaultValueAddedId,
Args: []any{"price", 10.0},
Level: checker.INFO,
Operation: "POST",
Path: "/products",
Source: load.NewSource("../data/checker/request_body_default_value_changed_base.yaml"),
OperationId: "createProduct",
}}, errs)
}
// CL: removing request body default value or request property default value
func TestRequestBodyDefaultValueRemoving(t *testing.T) {
s1, err := open("../data/checker/request_body_default_value_changed_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_body_default_value_changed_base.yaml")
require.NoError(t, err)
s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["text/plain"].Schema.Value.Default = nil
s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["price"].Value.Default = nil
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyDefaultValueChangedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{{
Id: checker.RequestBodyDefaultValueRemovedId,
Args: []any{"text/plain", "Default"},
Level: checker.INFO,
Operation: "POST",
Path: "/products",
Source: load.NewSource("../data/checker/request_body_default_value_changed_base.yaml"),
OperationId: "createProduct",
}, {
Id: checker.RequestPropertyDefaultValueRemovedId,
Args: []any{"price", 10.0},
Level: checker.INFO,
Operation: "POST",
Path: "/products",
Source: load.NewSource("../data/checker/request_body_default_value_changed_base.yaml"),
OperationId: "createProduct",
}}, errs)
}