Skip to content

Commit

Permalink
was removed -> removed
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison committed Aug 29, 2024
1 parent a5a3bba commit 967a3cc
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 86 deletions.
8 changes: 4 additions & 4 deletions checker/check_api_security_updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestAPIGlobalSecurityyDeleted(t *testing.T) {
Args: []any{"petstore_auth"},
Level: checker.INFO,
}, errs[0])
require.Equal(t, "security scheme 'petstore_auth' was removed", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed security scheme 'petstore_auth'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: removing a security scope from an API global security
Expand All @@ -64,7 +64,7 @@ func TestAPIGlobalSecurityScopeRemoved(t *testing.T) {
Args: []any{"read:pets", "petstore_auth"},
Level: checker.INFO,
}, errs[0])
require.Equal(t, "security scope 'read:pets' was removed from global security scheme 'petstore_auth'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed security scope 'read:pets' from global security scheme 'petstore_auth'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: adding a security scope from an API global security
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestAPISecurityDeleted(t *testing.T) {
Path: "/subscribe",
Source: load.NewSource("../data/checker/api_security_added_base.yaml"),
}, errs[0])
require.Equal(t, "endpoint scheme security 'petstore_auth' was removed", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed endpoint scheme security 'petstore_auth'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: removing a security scope from an API endpoint security
Expand All @@ -150,7 +150,7 @@ func TestAPISecurityScopeRemoved(t *testing.T) {
Path: "/subscribe",
Source: load.NewSource("../data/checker/api_security_updated_revision.yaml"),
}, errs[0])
require.Equal(t, "security scope 'read:pets' was removed from endpoint security scheme 'petstore_auth'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed security scope 'read:pets' from endpoint security scheme 'petstore_auth'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: adding a security scope to an API endpoint security
Expand Down
4 changes: 2 additions & 2 deletions checker/check_api_tag_updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestTagAdded(t *testing.T) {
Source: load.NewSource("../data/checker/tag_added_base.yaml"),
OperationId: "createOneGroup",
}, errs[0])
require.Equal(t, "api tag 'newTag' added", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "added api tag 'newTag'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: removing an existing tag
Expand All @@ -57,7 +57,7 @@ func TestTagRemoved(t *testing.T) {
Source: load.NewSource("../data/checker/tag_removed_base.yaml"),
OperationId: "createOneGroup",
}, errs[0])
require.Equal(t, "api tag 'Test' removed", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed api tag 'Test'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))

}

Expand Down
6 changes: 3 additions & 3 deletions checker/check_breaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestBreaking_ResponseHeaderRemoved(t *testing.T) {
require.NotEmpty(t, errs)
require.Len(t, errs, 1)
require.Equal(t, checker.RequiredResponseHeaderRemovedId, errs[0].GetId())
require.Equal(t, "mandatory header 'X-RateLimit-Limit' was removed for response status 'default'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed mandatory header 'X-RateLimit-Limit' for response status 'default'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// BC: removing an existing response with successful status is breaking
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestBreaking_TagRemoved(t *testing.T) {
require.NotEmpty(t, errs)
require.Len(t, errs, 1)
require.Equal(t, checker.APITagRemovedId, errs[0].GetId())
require.Equal(t, "api tag 'security' removed", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed api tag 'security'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// BC: removing/updating a media type enum in response (optional)
Expand Down Expand Up @@ -436,7 +436,7 @@ func TestBreaking_OptionalResponseHeaderRemoved(t *testing.T) {
require.NotEmpty(t, errs)
require.Len(t, errs, 1)
require.Equal(t, checker.OptionalResponseHeaderRemovedId, errs[0].GetId())
require.Equal(t, "optional header 'X-RateLimit-Limit' was removed for response status 'default'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed optional header 'X-RateLimit-Limit' for response status 'default'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// BC: deleting a media-type from response is breaking
Expand Down
8 changes: 4 additions & 4 deletions checker/check_components_security_updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestComponentSecurityRemoved(t *testing.T) {
Level: checker.INFO,
Component: checker.ComponentSecuritySchemes,
}, errs[0])
require.Equal(t, "component security scheme 'BasicAuth' was removed", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed component security scheme 'BasicAuth'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: adding a new oauth security scope
Expand Down Expand Up @@ -151,12 +151,12 @@ func TestComponentSecurityOauthScopeRemoved(t *testing.T) {
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIComponentsSecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ComponentChange{
Id: "api-security-component-oauth-scope-removed",
Id: checker.APIComponentSecurityOauthScopeRemovedId,
Args: []any{"petstore_auth", "admin:pets"},
Level: checker.INFO,
Component: checker.ComponentSecuritySchemes,
}, errs[0])
require.Equal(t, "component security scheme 'petstore_auth' oauth scope 'admin:pets' was removed", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed component security scheme 'petstore_auth' oauth scope 'admin:pets'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: removing a new oauth security scope
Expand All @@ -173,7 +173,7 @@ func TestComponentSecurityOauthScopeUpdated(t *testing.T) {
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIComponentsSecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ComponentChange{
Id: "api-security-component-oauth-scope-changed",
Id: checker.APIComponentSecurityOauthScopeUpdatedId,
Args: []any{"petstore_auth", "read:pets", "read your pets", "grants access to pets (deprecated)"},
Level: checker.INFO,
Component: checker.ComponentSecuritySchemes,
Expand Down
6 changes: 3 additions & 3 deletions checker/check_response_pattern_added_or_changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ func ResponsePatternAddedOrChangedCheck(diffReport *diff.Diff, operationsSources
propName := propertyFullName(propertyPath, propertyName)

id := ResponsePropertyPatternChangedId
args := []any{propName, patternDiff.From, patternDiff.To, responseStatus}
args := []any{patternDiff.From, patternDiff.To, propName, responseStatus}
if patternDiff.To == "" || patternDiff.To == nil {
id = ResponsePropertyPatternRemovedId
args = []any{propName, patternDiff.From, responseStatus}
args = []any{patternDiff.From, propName, responseStatus}
} else if patternDiff.From == "" || patternDiff.From == nil {
id = ResponsePropertyPatternAddedId
args = []any{propName, patternDiff.To, responseStatus}
args = []any{patternDiff.To, propName, responseStatus}
}

result = append(result, NewApiChange(
Expand Down
12 changes: 6 additions & 6 deletions checker/check_response_pattern_added_or_changed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func TestResponsePropertyPatternChanged(t *testing.T) {
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.ResponsePropertyPatternChangedId,
Args: []any{"data/created", "^[a-z]+$", "^(?:([a-z]+-)*([a-z]+)?)$", "200"},
Args: []any{"^[a-z]+$", "^(?:([a-z]+-)*([a-z]+)?)$", "data/created", "200"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_pattern_added_or_changed_revision.yaml"),
OperationId: "createOneGroup",
}, errs[0])
require.Equal(t, "'data/created' response property pattern was changed from '^[a-z]+$' to '^(?:([a-z]+-)*([a-z]+)?)$' for status '200'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "changed pattern from '^[a-z]+$' to '^(?:([a-z]+-)*([a-z]+)?)$' in property 'data/created' for response status '200'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: adding response property pattern
Expand All @@ -49,14 +49,14 @@ func TestResponsePropertyPatternAdded(t *testing.T) {
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.ResponsePropertyPatternAddedId,
Args: []any{"data/created", "^[a-z]+$", "200"},
Args: []any{"^[a-z]+$", "data/created", "200"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_pattern_added_or_changed_base.yaml"),
OperationId: "createOneGroup",
}, errs[0])
require.Equal(t, "'data/created' response property pattern '^[a-z]+$' was added for status '200'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "added pattern '^[a-z]+$' to property 'data/created' for response status '200'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: removing response property pattern
Expand All @@ -74,12 +74,12 @@ func TestResponsePropertyPatternRemoved(t *testing.T) {
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.ResponsePropertyPatternRemovedId,
Args: []any{"data/created", "^[a-z]+$", "200"},
Args: []any{"^[a-z]+$", "data/created", "200"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_pattern_added_or_changed_base.yaml"),
OperationId: "createOneGroup",
}, errs[0])
require.Equal(t, "'data/created' response property pattern '^[a-z]+$' was removed for status '200'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed pattern '^[a-z]+$' from property 'data/created' for response status '200'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}
6 changes: 3 additions & 3 deletions checker/check_response_property_default_value_changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ func ResponsePropertyDefaultValueChangedCheck(diffReport *diff.Diff, operationsS

defaultValueDiff := propertyDiff.DefaultDiff
if defaultValueDiff.From == nil {
appendResultItem(ResponsePropertyDefaultValueAddedId, propertyName, defaultValueDiff.To, responseStatus)
appendResultItem(ResponsePropertyDefaultValueAddedId, defaultValueDiff.To, propertyName, responseStatus)
} else if defaultValueDiff.To == nil {
appendResultItem(ResponsePropertyDefaultValueRemovedId, propertyName, defaultValueDiff.From, responseStatus)
appendResultItem(ResponsePropertyDefaultValueRemovedId, defaultValueDiff.From, propertyName, responseStatus)
} else {
appendResultItem(ResponsePropertyDefaultValueChangedId, propertyName, defaultValueDiff.From, defaultValueDiff.To, responseStatus)
appendResultItem(ResponsePropertyDefaultValueChangedId, defaultValueDiff.From, defaultValueDiff.To, propertyName, responseStatus)
}
})
}
Expand Down
42 changes: 29 additions & 13 deletions checker/check_response_property_default_value_changed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,28 @@ func TestResponsePropertyDefaultValueUpdatedCheck(t *testing.T) {
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{{

require.Equal(t, checker.ApiChange{
Id: checker.ResponsePropertyDefaultValueChangedId,
Args: []any{"created", "2020-01-01T00:00:00Z", "2020-02-01T00:00:00Z", "200"},
Args: []any{"2020-01-01T00:00:00Z", "2020-02-01T00:00:00Z", "created", "200"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_revision.yaml"),
OperationId: "createOneGroup",
}, {
}, errs[0])
require.Equal(t, "changed default value from '2020-01-01T00:00:00Z' to '2020-02-01T00:00:00Z' for property 'created' for response status '200'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))

require.Equal(t, checker.ApiChange{
Id: checker.ResponsePropertyDefaultValueChangedId,
Args: []any{"enabled", false, true, "200"},
Args: []any{false, true, "enabled", "200"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_revision.yaml"),
OperationId: "createOneGroup",
}}, errs)
}, errs[1])
require.Equal(t, "changed default value from 'false' to 'true' for property 'enabled' for response status '200'", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: changing response body default value
Expand All @@ -59,6 +64,7 @@ func TestResponseSchemaDefaultValueUpdatedCheck(t *testing.T) {
Source: load.NewSource("../data/checker/response_property_default_value_changed_base.yaml"),
OperationId: "createOneGroup",
}, errs[0])
require.Equal(t, "response body 'text/plain' default value changed from 'Error' to 'new default value' for status '404'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: adding response body default value or response body property default value
Expand All @@ -75,23 +81,28 @@ func TestResponsePropertyDefaultValueAddedCheck(t *testing.T) {
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{{

require.Equal(t, checker.ApiChange{
Id: checker.ResponseBodyDefaultValueAddedId,
Args: []any{"text/plain", "Error", "404"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_base.yaml"),
OperationId: "createOneGroup",
}, {
}, errs[0])
require.Equal(t, "response body 'text/plain' default value 'Error' was added for status '404'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))

require.Equal(t, checker.ApiChange{
Id: checker.ResponsePropertyDefaultValueAddedId,
Args: []any{"created", "2020-01-01T00:00:00Z", "200"},
Args: []any{"2020-01-01T00:00:00Z", "created", "200"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_base.yaml"),
OperationId: "createOneGroup",
}}, errs)
}, errs[1])
require.Equal(t, "added default value '2020-01-01T00:00:00Z' to response property 'created' for response status '200'", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// CL: removing response body default value or response body property default value
Expand All @@ -108,21 +119,26 @@ func TestResponsePropertyDefaultValueRemovedCheck(t *testing.T) {
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{{

require.Equal(t, checker.ApiChange{
Id: checker.ResponseBodyDefaultValueRemovedId,
Args: []any{"text/plain", "Error", "404"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_base.yaml"),
OperationId: "createOneGroup",
}, {
}, errs[0])
require.Equal(t, "response body 'text/plain' default value 'Error' was removed for status '404'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))

require.Equal(t, checker.ApiChange{
Id: checker.ResponsePropertyDefaultValueRemovedId,
Args: []any{"created", "2020-01-01T00:00:00Z", "200"},
Args: []any{"2020-01-01T00:00:00Z", "created", "200"},
Level: checker.INFO,
Operation: "POST",
Path: "/api/v1.0/groups",
Source: load.NewSource("../data/checker/response_property_default_value_changed_base.yaml"),
OperationId: "createOneGroup",
}}, errs)
}, errs[1])
require.Equal(t, "removed default value '2020-01-01T00:00:00Z' of property 'created' for response status '200'", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
}
Loading

0 comments on commit 967a3cc

Please sign in to comment.