-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathcheck_request_property_enum_value_updated_test.go
92 lines (75 loc) · 4 KB
/
check_request_property_enum_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
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
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: removing request property enum values
func TestRequestPropertyEnumValueRemovedCheck(t *testing.T) {
s1, err := open("../data/checker/request_property_enum_value_updated_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_enum_value_updated_base.yaml")
require.NoError(t, err)
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["category"].Value.Enum = []interface{}{"dog", "cat"}
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyEnumValueUpdatedCheck), d, osm, checker.ERR)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestPropertyEnumValueRemovedId,
Level: checker.ERR,
Args: []any{"bird", "category"},
Operation: "POST",
OperationId: "updatePet",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_enum_value_updated_base.yaml"),
}, errs[0])
require.Equal(t, "removed the enum value 'bird' of the request property 'category'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}
// CL: removing request read-only property enum values
func TestRequestReadOnlyPropertyEnumValueRemovedCheck(t *testing.T) {
s1, err := open("../data/checker/request_property_enum_value_updated_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_enum_value_updated_base.yaml")
require.NoError(t, err)
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["category"].Value.Enum = []interface{}{"dog", "cat"}
s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["category"].Value.ReadOnly = true
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyEnumValueUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestReadOnlyPropertyEnumValueRemovedId,
Level: checker.INFO,
Args: []any{"bird", "category"},
Operation: "POST",
OperationId: "updatePet",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_enum_value_updated_base.yaml"),
}, errs[0])
require.Equal(t, "removed the enum value 'bird' of the request read-only property 'category'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}
// CL: adding request property enum values
func TestRequestPropertyEnumValueAddedCheck(t *testing.T) {
s1, err := open("../data/checker/request_property_enum_value_updated_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_enum_value_updated_base.yaml")
require.NoError(t, err)
s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["category"].Value.Enum = []interface{}{"dog", "cat"}
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyEnumValueUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.RequestPropertyEnumValueAddedId,
Level: checker.INFO,
Args: []any{"bird", "category"},
Operation: "POST",
OperationId: "updatePet",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_enum_value_updated_base.yaml"),
}, errs[0])
require.Equal(t, "added the new 'bird' enum value to the request property 'category'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}