-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathcheck_request_property_max_length_updated_test.go
151 lines (131 loc) · 6.86 KB
/
check_request_property_max_length_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
146
147
148
149
150
151
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: increasing max length of request body
func TestRequestBodyMaxLengthDecreasedCheck(t *testing.T) {
s1, err := open("../data/checker/request_body_max_length_decreased_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_body_max_length_decreased_base.yaml")
require.NoError(t, err)
maxLength := uint64(50)
newMaxLength := uint64(100)
s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &maxLength
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &newMaxLength
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestBodyMaxLengthIncreasedId,
Args: []any{maxLength, newMaxLength},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_body_max_length_decreased_base.yaml"),
OperationId: "addPet",
}, errs[0])
}
// CL: decreasing max length of request body
func TestRequestBodyMaxLengthIncreasedCheck(t *testing.T) {
s1, err := open("../data/checker/request_body_max_length_decreased_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_body_max_length_decreased_base.yaml")
require.NoError(t, err)
maxLength := uint64(100)
newMaxLength := uint64(50)
s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &maxLength
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &newMaxLength
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.ERR)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestBodyMaxLengthDecreasedId,
Args: []any{newMaxLength},
Level: checker.ERR,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_body_max_length_decreased_base.yaml"),
OperationId: "addPet",
}, errs[0])
}
// CL: decreasing max length of request property
func TestRequestPropertyMaxLengthDecreasedCheck(t *testing.T) {
s1, err := open("../data/checker/request_body_max_length_decreased_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_body_max_length_decreased_base.yaml")
require.NoError(t, err)
maxLength := uint64(100)
newMaxLength := uint64(50)
s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &maxLength
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &newMaxLength
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestPropertyMaxLengthDecreasedId,
Args: []any{"description", newMaxLength},
Level: checker.ERR,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_body_max_length_decreased_base.yaml"),
OperationId: "addPet",
}, errs[0])
require.Equal(t, "the 'description' request property's maxLength was decreased to '50'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}
// CL: decreasing max length of request read-only property
func TestRequestReadOnlyPropertyMaxLengthDecreasedCheck(t *testing.T) {
s1, err := open("../data/checker/request_body_max_length_decreased_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_body_max_length_decreased_base.yaml")
require.NoError(t, err)
maxLength := uint64(100)
newMaxLength := uint64(50)
s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &maxLength
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &newMaxLength
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.ReadOnly = true
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestReadOnlyPropertyMaxLengthDecreasedId,
Args: []any{"description", newMaxLength},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_body_max_length_decreased_base.yaml"),
OperationId: "addPet",
}, errs[0])
require.Equal(t, "the 'description' request read-only property's maxLength was decreased to '50'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}
// CL: increasing max length of request property
func TestRequestPropertyMaxLengthIncreasedCheck(t *testing.T) {
s1, err := open("../data/checker/request_body_max_length_decreased_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_body_max_length_decreased_base.yaml")
require.NoError(t, err)
maxLength := uint64(50)
newMaxLength := uint64(100)
s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &maxLength
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &newMaxLength
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestPropertyMaxLengthIncreasedId,
Args: []any{"description", maxLength, newMaxLength},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_body_max_length_decreased_base.yaml"),
OperationId: "addPet",
}, errs[0])
}