From 021623cf68ebfdbcf31b33585270f9331219f788 Mon Sep 17 00:00:00 2001 From: Bianca Date: Fri, 28 Jul 2023 14:32:17 +0100 Subject: [PATCH] Fix duplicated test --- BREAKING-CHANGES-EXAMPLES.md | 1 + checker/check-request-property-max-updated.go | 2 +- ...check-request-property-max-updated_test.go | 36 +++++++++++++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/BREAKING-CHANGES-EXAMPLES.md b/BREAKING-CHANGES-EXAMPLES.md index 4141662c..f0748f4a 100644 --- a/BREAKING-CHANGES-EXAMPLES.md +++ b/BREAKING-CHANGES-EXAMPLES.md @@ -219,6 +219,7 @@ These examples are automatically generated from unit tests. [decreasing minLength value of request parameter](checker/check-request-parameters-min-length-updated_test.go?plain=1#L34) [decreasing minimum value of request parameter](checker/check-request-parameters-min-updated_test.go?plain=1#L33) [decreasing minimum value of request property](checker/check-request-property-min-updated_test.go?plain=1#L34) +[decreasing request body maximum value](checker/check-request-property-max-updated_test.go?plain=1#L91) [decreasing request property maximum value](checker/check-request-property-max-updated_test.go?plain=1#L11) [deprecating an operation with sunset greater than min](checker/checker_not_breaking_test.go?plain=1#L199) [increasing max length of request body](checker/check-request-property-max-length-updated_test.go?plain=1#L11) diff --git a/checker/check-request-property-max-updated.go b/checker/check-request-property-max-updated.go index 39a23f95..98c99303 100644 --- a/checker/check-request-property-max-updated.go +++ b/checker/check-request-property-max-updated.go @@ -42,7 +42,7 @@ func RequestPropertyMaxDecreasedCheck(diffReport *diff.Diff, operationsSources * } else { result = append(result, ApiChange{ Id: "request-body-max-increased", - Level: ERR, + Level: INFO, Text: fmt.Sprintf(config.i18n("request-body-max-increased"), ColorizedValue(maxDiff.From), ColorizedValue(maxDiff.To)), Operation: operation, OperationId: operationItem.Revision.OperationID, diff --git a/checker/check-request-property-max-updated_test.go b/checker/check-request-property-max-updated_test.go index a301e68e..e16dc3b9 100644 --- a/checker/check-request-property-max-updated_test.go +++ b/checker/check-request-property-max-updated_test.go @@ -68,7 +68,9 @@ func TestRequestBodyMaxIncreasingCheck(t *testing.T) { require.NoError(t, err) max := float64(20) - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.Max = &max + newMax := float64(25) + s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &max + s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &newMax d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -76,9 +78,37 @@ func TestRequestBodyMaxIncreasingCheck(t *testing.T) { errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxDecreasedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) require.Equal(t, checker.ApiChange{ - Id: "request-property-max-increased", + Id: "request-body-max-increased", Level: checker.INFO, - Text: "the 'name' request property's max was increased from '15.00' to '20.00'", + Text: "the request's body max was increased from '20.00' to '25.00'", + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_max_decreased_base.yaml", + OperationId: "addPet", + }, errs[0]) +} + +// CL: decreasing request body maximum value +func TestRequestBodyMaxDecreasedCheck(t *testing.T) { + s1, err := open("../data/checker/request_property_max_decreased_base.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/request_property_max_decreased_base.yaml") + require.NoError(t, err) + + max := float64(25) + newMax := float64(20) + s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &max + s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &newMax + + d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + require.NoError(t, err) + + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxDecreasedCheck), d, osm, checker.INFO) + require.Len(t, errs, 1) + require.Equal(t, checker.ApiChange{ + Id: "request-body-max-decreased", + Level: checker.ERR, + Text: "the request's body max was decreased to '20.00'", Operation: "POST", Path: "/pets", Source: "../data/checker/request_property_max_decreased_base.yaml",