forked from Jonathan-Rosenberg/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-request-body-required-value-updated_test.go
59 lines (51 loc) · 2.09 KB
/
check-request-body-required-value-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
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/treeverse/oasdiff/checker"
"github.com/treeverse/oasdiff/diff"
)
// CL: changing request's body to required is breaking
func TestRequestBodyBecameRequired(t *testing.T) {
s1, err := open("../data/checker/request_body_became_required_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_body_became_required_base.yaml")
require.NoError(t, err)
s2.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Required = true
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.RequestBodyRequiredUpdatedCheck), d, osm)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "request-body-became-required",
Text: "request body became required",
Comment: "",
Level: checker.ERR,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: "../data/checker/request_body_became_required_base.yaml",
OperationId: "createOneGroup",
}, errs[0])
}
// CL: changing request's body to optional
func TestRequestBodyBecameOptional(t *testing.T) {
s1, err := open("../data/checker/request_body_became_optional_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_body_became_optional_base.yaml")
require.NoError(t, err)
s2.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Required = false
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig().WithCheckBreaking(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestBodyRequiredUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "request-body-became-optional",
Text: "request body became optional",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: "../data/checker/request_body_became_optional_base.yaml",
OperationId: "createOneGroup",
}, errs[0])
}