-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests for rest error wrapping (#27388)
- Loading branch information
1 parent
407dd87
commit b0b4c08
Showing
4 changed files
with
240 additions
and
31 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
google-cloud-errors/test/google/cloud/errors/gapic_rest_errors_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "helper" | ||
require "google/cloud/errors" | ||
require "grpc/errors" | ||
require "google/gax/errors" | ||
require "google/rpc/status_pb" | ||
|
||
# These test confirm that REST exceptions corresponding to various HTTP status codes | ||
# are correctly wrapped | ||
describe Google::Cloud::Error, :rest_errors do | ||
it "identifies CanceledError" do | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 499) | ||
_(mapped_error).must_be_kind_of Google::Cloud::CanceledError | ||
end | ||
|
||
it "identifies InvalidArgumentError" do | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 400) | ||
_(mapped_error).must_be_kind_of Google::Cloud::InvalidArgumentError | ||
end | ||
|
||
it "identifies DeadlineExceededError" do | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 504) | ||
_(mapped_error).must_be_kind_of Google::Cloud::DeadlineExceededError | ||
end | ||
|
||
it "identifies NotFoundError" do | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 404) | ||
_(mapped_error).must_be_kind_of Google::Cloud::NotFoundError | ||
end | ||
|
||
it "identifies AlreadyExistsError" do | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 409) | ||
_(mapped_error).must_be_kind_of Google::Cloud::AlreadyExistsError | ||
end | ||
|
||
it "identifies PermissionDeniedError" do | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 403) | ||
_(mapped_error).must_be_kind_of Google::Cloud::PermissionDeniedError | ||
end | ||
|
||
it "identifies ResourceExhaustedError" do | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 429) | ||
_(mapped_error).must_be_kind_of Google::Cloud::ResourceExhaustedError | ||
end | ||
|
||
it "identifies FailedPreconditionError" do | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 412) | ||
_(mapped_error).must_be_kind_of Google::Cloud::FailedPreconditionError | ||
end | ||
|
||
it "identifies UnimplementedError" do | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 501) | ||
_(mapped_error).must_be_kind_of Google::Cloud::UnimplementedError | ||
end | ||
|
||
it "identifies InternalError" do | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 500) | ||
_(mapped_error).must_be_kind_of Google::Cloud::InternalError | ||
end | ||
|
||
it "identifies UnavailableError" do | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 503) | ||
_(mapped_error).must_be_kind_of Google::Cloud::UnavailableError | ||
end | ||
|
||
it "identifies unknown error" do | ||
# We don't know what to map this error case to | ||
mapped_error = wrapped_rest_error gapic_rest_error(status_code: 0) | ||
_(mapped_error).must_be_kind_of Google::Cloud::Error | ||
end | ||
end |
37 changes: 37 additions & 0 deletions
37
google-cloud-errors/test/google/cloud/errors/wrapped_gapic_rest_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 the "License"; | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "helper" | ||
require "google/cloud/errors" | ||
require "grpc/errors" | ||
require "google/gax/errors" | ||
require "google/rpc/status_pb" | ||
|
||
describe Google::Cloud::Error, :wrapped_rest_error do | ||
# This test confirms that a whole array of any-wrapped detail messages | ||
# containing various messages from the `google/rpc/error_details.proto` | ||
# will be correctly deserialized and surfaced to the end-user | ||
# in the `status_details` field when wrapping the rest error | ||
it "contains multiple detail messages" do | ||
error = wrapped_rest_error gapic_rest_error(status_code: 404, extended_details: true) | ||
|
||
di = error.status_details.find {|entry| entry.is_a?(Google::Rpc::DebugInfo)} | ||
_(di).must_equal debug_info | ||
|
||
lm = error.status_details.find {|entry| entry.is_a?(Google::Rpc::LocalizedMessage)} | ||
_(lm).must_equal localized_message | ||
|
||
help_detail = error.status_details.find {|entry| entry.is_a?(Google::Rpc::Help)} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters