forked from Tufin/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker_request_parameter_required_value_updated_test.go
56 lines (48 loc) · 2.21 KB
/
checker_request_parameter_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
package checker_test
import (
"testing"
"github.com/getkin/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/diff"
)
// BC: changing an existing header param from optional to required is breaking
func TestBreaking_HeaderParamBecameRequired(t *testing.T) {
s1 := l(t, 1)
s2 := l(t, 1)
s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false
s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.RequestParameterRequiredValueUpdatedCheck), d, osm)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestParameterBecomeRequiredId,
Text: "the 'header' request parameter 'network-policies' became required",
Comment: "",
Level: checker.ERR,
Operation: "GET",
Path: "/api/{domain}/{project}/install-command",
Source: "../data/openapi-test1.yaml",
}, errs[0])
}
// CL: changing an existing header param from required to optional
func TestBreaking_HeaderParamBecameOptional(t *testing.T) {
s1 := l(t, 1)
s2 := l(t, 1)
s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true
s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterRequiredValueUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestParameterBecomeOptionalId,
Text: "the 'header' request parameter 'network-policies' became optional",
Comment: "",
Level: checker.INFO,
Operation: "GET",
Path: "/api/{domain}/{project}/install-command",
Source: "../data/openapi-test1.yaml",
}, errs[0])
}