forked from oasdiff/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_api_sunset_changed_test.go
112 lines (86 loc) · 4.65 KB
/
check_api_sunset_changed_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/diff"
)
// BC: deleting sunset header for a deprecated endpoint is breaking
func TestBreaking_SunsetDeletedForDeprecatedEndpoint(t *testing.T) {
s1, err := open(getDeprecationFile("deprecated-with-sunset.yaml"))
require.NoError(t, err)
s2, err := open(getDeprecationFile("deprecated-no-sunset.yaml"))
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APISunsetChangedCheck), d, osm)
require.NotEmpty(t, errs)
require.Len(t, errs, 1)
require.Equal(t, checker.APISunsetDeletedId, errs[0].GetId())
require.Equal(t, "api sunset date deleted, but deprecated=true kept", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}
// BC: changing sunset to an earlier date for a deprecated endpoint with a deprecation policy is breaking
func TestBreaking_SunsetModifiedForDeprecatedEndpoint(t *testing.T) {
s1, err := open(getDeprecationFile("deprecated-future.yaml"))
require.NoError(t, err)
s2, err := open(getDeprecationFile("deprecated-past.yaml"))
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APISunsetChangedCheck).WithDeprecation(31, 180), d, osm)
require.NotEmpty(t, errs)
require.Len(t, errs, 1)
require.Equal(t, checker.APISunsetDateChangedTooSmallId, errs[0].GetId())
require.Equal(t, "api sunset date changed to earlier date from '9999-08-10' to '2022-08-10', new sunset date must be not earlier than '9999-08-10' at least '180' days from now", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}
// BC: changing sunset to an invalid date for a deprecated endpoint is breaking
func TestBreaking_SunsetModifiedToInvalidForDeprecatedEndpoint(t *testing.T) {
s1, err := open(getDeprecationFile("deprecated-future.yaml"))
require.NoError(t, err)
s2, err := open(getDeprecationFile("deprecated-invalid.yaml"))
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APISunsetChangedCheck), d, osm)
require.NotEmpty(t, errs)
require.Len(t, errs, 1)
require.Equal(t, checker.APIPathSunsetParseId, errs[0].GetId())
require.Equal(t, "failed to parse sunset date: 'sunset date doesn't conform with RFC3339: invalid-date'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}
// BC: changing sunset from an invalid date for a deprecated endpoint is breaking
func TestBreaking_SunsetModifiedFromInvalidForDeprecatedEndpoint(t *testing.T) {
s1, err := open(getDeprecationFile("deprecated-invalid.yaml"))
require.NoError(t, err)
s2, err := open(getDeprecationFile("deprecated-future.yaml"))
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APISunsetChangedCheck), d, osm)
require.NotEmpty(t, errs)
require.Len(t, errs, 1)
require.Equal(t, checker.APIPathSunsetParseId, errs[0].GetId())
require.Equal(t, "failed to parse sunset date: 'sunset date doesn't conform with RFC3339: invalid-date'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "../data/deprecation/deprecated-invalid.yaml", errs[0].GetSource())
}
// BC: deleting other extension (not sunset) header for a deprecated endpoint is not breaking
func TestBreaking_NonSunsetDeletedForDeprecatedEndpoint(t *testing.T) {
s1, err := open(getDeprecationFile("deprecated-with-other-extension.yaml"))
require.NoError(t, err)
s2, err := open(getDeprecationFile("deprecated-no-sunset.yaml"))
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APISunsetChangedCheck), d, osm)
require.Empty(t, errs)
}
// BC: no change to headers for a deprecated endpoint is not breaking
func TestBreaking_NoChangeToSunsetDeprecatedEndpoint(t *testing.T) {
s1, err := open(getDeprecationFile("deprecated-future.yaml"))
require.NoError(t, err)
s2, err := open(getDeprecationFile("deprecated-future-2.yaml"))
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APISunsetChangedCheck), d, osm)
require.Empty(t, errs)
}