forked from Tufin/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-response-property-default-value-changed_test.go
128 lines (117 loc) · 5.83 KB
/
check-response-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
123
124
125
126
127
128
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 response body property default value
func TestResponsePropertyDefaultValueUpdatedCheck(t *testing.T) {
s1, err := open("../data/checker/response_property_default_value_changed_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_property_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.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{{
Id: checker.ResponsePropertyDefaultValueChangedId,
Args: []any{"created", "2020-01-01T00:00:00Z", "2020-02-01T00:00:00Z", "200"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_revision.yaml"),
OperationId: "createOneGroup",
}, {
Id: checker.ResponsePropertyDefaultValueChangedId,
Args: []any{"enabled", false, true, "200"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_revision.yaml"),
OperationId: "createOneGroup",
}}, errs)
}
// CL: changing response body default value
func TestResponseSchemaDefaultValueUpdatedCheck(t *testing.T) {
s1, err := open("../data/checker/response_property_default_value_changed_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_property_default_value_changed_base.yaml")
require.NoError(t, err)
s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("404").Value.Content["text/plain"].Schema.Value.Default = "new default value"
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.ResponseBodyDefaultValueChangedId,
Args: []any{"text/plain", "Error", "new default value", "404"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_base.yaml"),
OperationId: "createOneGroup",
}, errs[0])
}
// CL: adding response body default value or response body property default value
func TestResponsePropertyDefaultValueAddedCheck(t *testing.T) {
s1, err := open("../data/checker/response_property_default_value_changed_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_property_default_value_changed_base.yaml")
require.NoError(t, err)
s1.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("404").Value.Content["text/plain"].Schema.Value.Default = nil
s1.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["created"].Value.Default = nil
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{{
Id: checker.ResponseBodyDefaultValueAddedId,
Args: []any{"text/plain", "Error", "404"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_base.yaml"),
OperationId: "createOneGroup",
}, {
Id: checker.ResponsePropertyDefaultValueAddedId,
Args: []any{"created", "2020-01-01T00:00:00Z", "200"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_base.yaml"),
OperationId: "createOneGroup",
}}, errs)
}
// CL: removing response body default value or response body property default value
func TestResponsePropertyDefaultValueRemovedCheck(t *testing.T) {
s1, err := open("../data/checker/response_property_default_value_changed_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_property_default_value_changed_base.yaml")
require.NoError(t, err)
s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("404").Value.Content["text/plain"].Schema.Value.Default = nil
s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["created"].Value.Default = nil
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{{
Id: checker.ResponseBodyDefaultValueRemovedId,
Args: []any{"text/plain", "Error", "404"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_base.yaml"),
OperationId: "createOneGroup",
}, {
Id: checker.ResponsePropertyDefaultValueRemovedId,
Args: []any{"created", "2020-01-01T00:00:00Z", "200"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_base.yaml"),
OperationId: "createOneGroup",
}}, errs)
}