forked from Jonathan-Rosenberg/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-response-required-property-write-only-read-only_test.go
114 lines (95 loc) · 4.95 KB
/
check-response-required-property-write-only-read-only_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
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/treeverse/oasdiff/checker"
"github.com/treeverse/oasdiff/diff"
)
// CL: changing required response property to write-only
func TestResponseRequiredPropertyBecameWriteOnly(t *testing.T) {
s1, err := open("../data/checker/response_required_property_write_only_read_only_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_required_property_write_only_read_only_base.yaml")
require.NoError(t, err)
s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["name"].Value.WriteOnly = true
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "response-required-property-became-write-only",
Text: "the response required property 'data/name' became write-only for the status '200'",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: "../data/checker/response_required_property_write_only_read_only_base.yaml",
OperationId: "createOneGroup",
}, errs[0])
}
// CL: changing required response property to not write-only
func TestResponseRequiredPropertyBecameNotWriteOnly(t *testing.T) {
s1, err := open("../data/checker/response_required_property_write_only_read_only_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_required_property_write_only_read_only_base.yaml")
require.NoError(t, err)
s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["writeOnlyName"].Value.WriteOnly = false
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "response-required-property-became-not-write-only",
Text: "the response required property 'data/writeOnlyName' became not write-only for the status '200'",
Comment: "It is valid only if the property was always returned before the specification has been changed",
Level: checker.WARN,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: "../data/checker/response_required_property_write_only_read_only_base.yaml",
OperationId: "createOneGroup",
}, errs[0])
}
// CL: changing required response property to read-only
func TestResponseRequiredPropertyBecameReadOnly(t *testing.T) {
s1, err := open("../data/checker/response_required_property_write_only_read_only_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_required_property_write_only_read_only_base.yaml")
require.NoError(t, err)
s1.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["id"].Value.ReadOnly = false
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "response-required-property-became-read-only",
Text: "the response required property 'data/id' became read-only for the status '200'",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: "../data/checker/response_required_property_write_only_read_only_base.yaml",
OperationId: "createOneGroup",
}, errs[0])
}
// CL: changing required response property to not read-only
func TestResponseRequiredPropertyBecameNonReadOnly(t *testing.T) {
s1, err := open("../data/checker/response_required_property_write_only_read_only_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_required_property_write_only_read_only_base.yaml")
require.NoError(t, err)
s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["id"].Value.ReadOnly = false
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "response-required-property-became-not-read-only",
Text: "the response required property 'data/id' became not read-only for the status '200'",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: "../data/checker/response_required_property_write_only_read_only_base.yaml",
OperationId: "createOneGroup",
}, errs[0])
}