forked from Jonathan-Rosenberg/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-response-property-became-required_test.go
56 lines (50 loc) · 2.27 KB
/
check-response-property-became-required_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
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/treeverse/oasdiff/checker"
"github.com/treeverse/oasdiff/diff"
)
// CL: changing optional response property to required
func TestResponsePropertyBecameRequiredlCheck(t *testing.T) {
s1, err := open("../data/checker/response_property_became_optional_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_property_became_optional_base.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyBecameRequiredCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "response-property-became-required",
Text: "the response property 'data/name' became required for the status '200'",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: "../data/checker/response_property_became_optional_base.yaml",
OperationId: "createOneGroup",
}, errs[0])
}
// CL: changing optional response write-only property to required
func TestResponseWriteOnlyPropertyBecameRequiredCheck(t *testing.T) {
s1, err := open("../data/checker/response_property_became_optional_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_property_became_optional_base.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
s1.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["name"].Value.WriteOnly = true
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyBecameRequiredCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "response-write-only-property-became-required",
Text: "the response write-only property 'data/name' became required for the status '200'",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: "../data/checker/response_property_became_optional_base.yaml",
OperationId: "createOneGroup",
}, errs[0])
}