Skip to content

Commit

Permalink
more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison committed Feb 4, 2025
1 parent b0cec65 commit a0523f6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion checker/check_api_removed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/tufin/oasdiff/diff"
)

// BC: deleting a path is breaking
// BC: deleting a path without deprecation is breaking
func TestBreaking_DeletedPath(t *testing.T) {
errs := d(t, diff.NewConfig(), 1, 701)
require.Len(t, errs, 1)
Expand Down
33 changes: 24 additions & 9 deletions checker/check_request_parameter_removed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func TestBreaking_ParameterDeprecationFuture(t *testing.T) {
require.Equal(t, "deleted the 'query' request parameter 'id' before the sunset date '9999-08-10'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// BC: removing a deprecated parameter with an invalid date is breaking
func TestBreaking_RemoveParameterWithInvalidSunset(t *testing.T) {
// BC: deleting a deprecated parameter without sunset date is not breaking
func TestBreaking_ParameterDeprecationNoSunset(t *testing.T) {

s1, err := open(getParameterDeprecationFile("deprecated-invalid.yaml"))
s1, err := open(getParameterDeprecationFile("deprecated-no-sunset.yaml"))
require.NoError(t, err)

s2, err := open(getParameterDeprecationFile("sunset.yaml"))
Expand All @@ -70,14 +70,10 @@ func TestBreaking_RemoveParameterWithInvalidSunset(t *testing.T) {
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.RequestParameterRemovedCheck), d, osm)
require.NotEmpty(t, errs)
require.Len(t, errs, 1)
require.Equal(t, checker.RequestParameterSunsetParseId, errs[0].GetId())
require.Equal(t, "failed to parse sunset date for the 'query' request parameter 'id': 'sunset date doesn't conform with RFC3339: invalid-date'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "../data/param-deprecation/sunset.yaml", errs[0].GetSource())
require.Empty(t, errs)
}

// BC: removing the parameter without a deprecation policy and without specifying sunset date is not breaking for alpha level
// BC: removing a parameter without a deprecation policy and without specifying sunset date is not breaking for alpha level
func TestBreaking_RemovedParameterForAlpha(t *testing.T) {
s1, err := open(getParameterDeprecationFile("base-alpha-stability.yaml"))
require.NoError(t, err)
Expand All @@ -90,3 +86,22 @@ func TestBreaking_RemovedParameterForAlpha(t *testing.T) {
errs := checker.CheckBackwardCompatibility(allChecksConfig(), d, osm)
require.Empty(t, errs)
}

// BC: removing a deprecated parameter with an invalid date is breaking
func TestBreaking_RemoveParameterWithInvalidSunset(t *testing.T) {

s1, err := open(getParameterDeprecationFile("deprecated-invalid.yaml"))
require.NoError(t, err)

s2, err := open(getParameterDeprecationFile("sunset.yaml"))
require.NoError(t, err)

d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.RequestParameterRemovedCheck), d, osm)
require.NotEmpty(t, errs)
require.Len(t, errs, 1)
require.Equal(t, checker.RequestParameterSunsetParseId, errs[0].GetId())
require.Equal(t, "failed to parse sunset date for the 'query' request parameter 'id': 'sunset date doesn't conform with RFC3339: invalid-date'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "../data/param-deprecation/sunset.yaml", errs[0].GetSource())
}
2 changes: 1 addition & 1 deletion checker/localizations/localizations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions docs/BREAKING-CHANGES-EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ These examples are automatically generated from unit tests.
[deleting a non-required non-write-only property in response body is breaking with warning](../checker/check_breaking_property_test.go?plain=1#L512)
[deleting a parameter before sunset date is breaking](../checker/check_request_parameter_removed_test.go?plain=1#L43)
[deleting a parameter without deprecation is breaking](../checker/check_request_parameter_removed_test.go?plain=1#L11)
[deleting a path is breaking](../checker/check_api_removed_test.go?plain=1#L12)
[deleting a path with some operations having sunset date in the future is breaking](../checker/check_api_removed_test.go?plain=1#L172)
[deleting a path without deprecation is breaking](../checker/check_api_removed_test.go?plain=1#L12)
[deleting a required property in request is breaking with warn](../checker/check_breaking_property_test.go?plain=1#L369)
[deleting a required property in response body is breaking](../checker/check_breaking_property_test.go?plain=1#L421)
[deleting a required property under AllOf in response body is breaking](../checker/check_breaking_property_test.go?plain=1#L451)
Expand Down Expand Up @@ -91,7 +91,7 @@ These examples are automatically generated from unit tests.
[removing 'anyOf' schema from the request body or request body property is breaking](../checker/check_breaking_test.go?plain=1#L660)
[removing 'oneOf' schema from the request body or request body property is breaking](../checker/check_breaking_test.go?plain=1#L682)
[removing a deprecated enpoint with an invalid date is breaking](../checker/check_api_removed_test.go?plain=1#L213)
[removing a deprecated parameter with an invalid date is breaking](../checker/check_request_parameter_removed_test.go?plain=1#L61)
[removing a deprecated parameter with an invalid date is breaking](../checker/check_request_parameter_removed_test.go?plain=1#L90)
[removing a media type from request body is breaking](../checker/check_breaking_test.go?plain=1#L644)
[removing a success status is breaking](../checker/check_response_status_updated_test.go?plain=1#L87)
[removing an existing optional response header is breaking as warn](../checker/check_breaking_test.go?plain=1#L398)
Expand Down Expand Up @@ -144,6 +144,7 @@ These examples are automatically generated from unit tests.
[changing servers is not breaking](../checker/check_not_breaking_test.go?plain=1#L252)
[decreasing maxItems of common request parameters without --flatten-params is not breaking](../checker/check_request_parameters_max_items_updated_test.go?plain=1#L57)
[deleting a deprecated operation without sunset date is not breaking](../checker/check_api_removed_test.go?plain=1#L69)
[deleting a deprecated parameter without sunset date is not breaking](../checker/check_request_parameter_removed_test.go?plain=1#L61)
[deleting a parameter after sunset date is not breaking](../checker/check_request_parameter_removed_test.go?plain=1#L28)
[deleting a path after sunset date of all contained operations is not breaking](../checker/check_api_removed_test.go?plain=1#L157)
[deleting a path with deprecated operations without sunset date is not breaking](../checker/check_api_removed_test.go?plain=1#L190)
Expand Down Expand Up @@ -181,9 +182,9 @@ These examples are automatically generated from unit tests.
[reducing max length in response is not breaking](../checker/check_breaking_min_max_test.go?plain=1#L31)
[reducing min items in request is not breaking](../checker/check_breaking_min_max_test.go?plain=1#L206)
[reducing min length in request is not breaking](../checker/check_breaking_min_max_test.go?plain=1#L48)
[removing a parameter without a deprecation policy and without specifying sunset date is not breaking for alpha level](../checker/check_request_parameter_removed_test.go?plain=1#L76)
[removing an existing response with error status is not breaking](../checker/check_breaking_test.go?plain=1#L382)
[removing an existing response with unparseable status is not breaking](../checker/check_breaking_test.go?plain=1#L366)
[removing the parameter without a deprecation policy and without specifying sunset date is not breaking for alpha level](../checker/check_request_parameter_removed_test.go?plain=1#L80)
[removing the path without a deprecation policy and without specifying sunset date is not breaking for alpha level](../checker/check_api_removed_test.go?plain=1#L87)
[removing the path without a deprecation policy and without specifying sunset date is not breaking for draft level](../checker/check_api_removed_test.go?plain=1#L106)
[renaming a path parameter is not breaking](../checker/check_breaking_test.go?plain=1#L112)
Expand Down

0 comments on commit a0523f6

Please sign in to comment.