-
Notifications
You must be signed in to change notification settings - Fork 67
/
attributes_test.go
76 lines (58 loc) · 2.57 KB
/
attributes_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
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/diff"
)
func TestBreaking_Attributes(t *testing.T) {
s1, err := open("../data/attributes/base.yaml")
require.NoError(t, err)
s2, err := open("../data/attributes/revision.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(allChecksConfig().WithAttributes([]string{"x-test"}), d, osm)
require.NotEmpty(t, errs)
require.Len(t, errs, 2)
require.Equal(t, map[string]any{"x-test": []any{"xyz", float64(456)}}, errs[0].GetAttributes())
require.Equal(t, map[string]any{"x-test": "abc"}, errs[1].GetAttributes())
}
func TestBreaking_AttributesNone(t *testing.T) {
s1, err := open("../data/attributes/base.yaml")
require.NoError(t, err)
s2, err := open("../data/attributes/revision.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(allChecksConfig().WithAttributes([]string{"x-other"}), d, osm)
require.NotEmpty(t, errs)
require.Len(t, errs, 2)
require.Empty(t, errs[0].GetAttributes())
require.Empty(t, errs[1].GetAttributes())
}
func TestBreaking_AttributesReverse(t *testing.T) {
s1, err := open("../data/attributes/revision.yaml")
require.NoError(t, err)
s2, err := open("../data/attributes/base.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(allChecksConfig().WithAttributes([]string{"x-test"}), d, osm)
require.NotEmpty(t, errs)
require.Len(t, errs, 2)
require.Equal(t, map[string]any{"x-test": []any{float64(123), float64(456)}}, errs[0].GetAttributes())
require.Equal(t, map[string]any{"x-test": float64(123)}, errs[1].GetAttributes())
}
func TestBreaking_AttributesTwo(t *testing.T) {
s1, err := open("../data/attributes/base.yaml")
require.NoError(t, err)
s2, err := open("../data/attributes/revision.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(allChecksConfig().WithAttributes([]string{"x-test", "x-test2"}), d, osm)
require.Len(t, errs, 2)
require.Equal(t, map[string]any{"x-test": []any{"xyz", float64(456)}}, errs[0].GetAttributes())
require.Equal(t, map[string]any{"x-test": "abc", "x-test2": "def"}, errs[1].GetAttributes())
}