forked from oasdiff/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_request_property_max_updated_test.go
145 lines (123 loc) · 5.7 KB
/
check_request_property_max_updated_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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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: decreasing request property maximum value
func TestRequestPropertyMaxDecreasedCheck(t *testing.T) {
s1, err := open("../data/checker/request_property_max_decreased_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_max_decreased_base.yaml")
require.NoError(t, err)
max := float64(10)
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.Max = &max
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxDecreasedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestPropertyMaxDecreasedId,
Level: checker.ERR,
Args: []any{"name", 10.0},
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_max_decreased_base.yaml"),
OperationId: "addPet",
}, errs[0])
}
// CL: decreasing request read-only property maximum value
func TestRequestReadOnlyPropertyMaxDecreasedCheck(t *testing.T) {
s1, err := open("../data/checker/request_property_max_decreased_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_max_decreased_base.yaml")
require.NoError(t, err)
max := float64(10)
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.Max = &max
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.ReadOnly = true
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxDecreasedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestReadOnlyPropertyMaxDecreasedId,
Level: checker.INFO,
Args: []any{"name", 10.0},
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_max_decreased_base.yaml"),
OperationId: "addPet",
}, errs[0])
}
// CL: increasing request property maximum value
func TestRequestPropertyMaxIncreasingCheck(t *testing.T) {
s1, err := open("../data/checker/request_property_max_decreased_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_max_decreased_base.yaml")
require.NoError(t, err)
max := float64(20)
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.Max = &max
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxDecreasedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestPropertyMaxIncreasedId,
Level: checker.INFO,
Args: []any{"name", 15.0, 20.0},
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_max_decreased_base.yaml"),
OperationId: "addPet",
}, errs[0])
}
// CL: increasing request body maximum value
func TestRequestBodyMaxIncreasingCheck(t *testing.T) {
s1, err := open("../data/checker/request_property_max_decreased_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_max_decreased_base.yaml")
require.NoError(t, err)
max := float64(20)
newMax := float64(25)
s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &max
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &newMax
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxDecreasedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestBodyMaxIncreasedId,
Level: checker.INFO,
Args: []any{20.0, 25.0},
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_max_decreased_base.yaml"),
OperationId: "addPet",
}, errs[0])
}
// CL: decreasing request body maximum value
func TestRequestBodyMaxDecreasedCheck(t *testing.T) {
s1, err := open("../data/checker/request_property_max_decreased_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_max_decreased_base.yaml")
require.NoError(t, err)
max := float64(25)
newMax := float64(20)
s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &max
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &newMax
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxDecreasedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestBodyMaxDecreasedId,
Level: checker.ERR,
Args: []any{20.0},
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_max_decreased_base.yaml"),
OperationId: "addPet",
}, errs[0])
}