-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathchecker_test.go
97 lines (77 loc) · 3.9 KB
/
checker_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
93
94
95
96
97
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/diff"
)
// BC: decreasing stability level is breaking
func TestBreaking_StabilityLevelDecreased(t *testing.T) {
s1, err := open(getDeprecationFile("base-beta-stability.yaml"))
require.NoError(t, err)
s2, err := open(getDeprecationFile("base-alpha-stability.yaml"))
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(allChecksConfig(), d, osm)
require.Len(t, errs, 1)
require.IsType(t, checker.ApiChange{}, errs[0])
e0 := errs[0].(checker.ApiChange)
require.Equal(t, checker.APIStabilityDecreasedId, e0.Id)
require.Equal(t, "GET", e0.Operation)
require.Equal(t, "/api/test", e0.Path)
require.Equal(t, "endpoint stability level decreased from 'beta' to 'alpha'", e0.GetUncolorizedText(checker.NewDefaultLocalizer()))
}
// BC: increasing stability level is not breaking
func TestBreaking_StabilityLevelIncreased(t *testing.T) {
s1, err := open(getDeprecationFile("base-alpha-stability.yaml"))
require.NoError(t, err)
s2, err := open(getDeprecationFile("base-beta-stability.yaml"))
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(allChecksConfig(), d, osm)
require.Empty(t, errs)
}
// BC: specifying an invalid stability level in revision is breaking
func TestBreaking_InvalidStabilityLevelInRevision(t *testing.T) {
s1, err := open(getDeprecationFile("base.yaml"))
require.NoError(t, err)
s2, err := open(getDeprecationFile("base-invalid-stability.yaml"))
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(allChecksConfig(), d, osm)
require.Len(t, errs, 1)
require.Equal(t, checker.APIInvalidStabilityLevelId, errs[0].GetId())
require.Equal(t, "failed to parse stability level: 'value is not one of draft, alpha, beta or stable: \"invalid\"'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "../data/deprecation/base-invalid-stability.yaml", errs[0].GetSource())
}
// BC: specifying an invalid stability level in base is breaking
func TestBreaking_InvalidStabilityLevelInBase(t *testing.T) {
s1, err := open(getDeprecationFile("base-invalid-stability.yaml"))
require.NoError(t, err)
s2, err := open(getDeprecationFile("base.yaml"))
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(allChecksConfig(), d, osm)
require.Len(t, errs, 1)
require.Equal(t, checker.APIInvalidStabilityLevelId, errs[0].GetId())
require.Equal(t, "failed to parse stability level: 'value is not one of draft, alpha, beta or stable: \"invalid\"'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "../data/deprecation/base-invalid-stability.yaml", errs[0].GetSource())
}
// BC: specifying a non-text, not-json stability level in base is breaking
func TestBreaking_InvalidNonJsonStabilityLevel(t *testing.T) {
s1, err := open(getDeprecationFile("base.yaml"))
require.NoError(t, err)
s2, err := open(getDeprecationFile("base-invalid-stability-2.yaml"))
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(allChecksConfig(), d, osm)
require.Len(t, errs, 1)
require.Equal(t, checker.APIInvalidStabilityLevelId, errs[0].GetId())
require.Equal(t, "failed to parse stability level: 'x-stability-level isn't a string nor valid json'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "../data/deprecation/base-invalid-stability-2.yaml", errs[0].GetSource())
}