|
15 | 15 | #ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY |
16 | 16 |
|
17 | 17 | #include "google/cloud/storage/internal/tracing_connection.h" |
| 18 | +#include "google/cloud/storage/object_read_stream.h" |
18 | 19 | #include "google/cloud/storage/testing/canonical_errors.h" |
19 | 20 | #include "google/cloud/storage/testing/mock_client.h" |
20 | 21 | #include "google/cloud/internal/opentelemetry.h" |
@@ -746,6 +747,35 @@ TEST(TracingClientTest, UploadFileResumable) { |
746 | 747 | "gl-cpp.status_code", code_str))))); |
747 | 748 | } |
748 | 749 |
|
| 750 | +TEST(TracingClientTest, DownloadStreamToFile) { |
| 751 | + auto span_catcher = InstallSpanCatcher(); |
| 752 | + auto mock = std::make_shared<MockClient>(); |
| 753 | + EXPECT_CALL(*mock, DownloadStreamToFile) |
| 754 | + .WillOnce([](auto&&, auto const&, auto const&) { |
| 755 | + EXPECT_TRUE(ThereIsAnActiveSpan()); |
| 756 | + return PermanentError(); |
| 757 | + }); |
| 758 | + auto under_test = TracingConnection(mock); |
| 759 | + storage::ObjectReadStream stream; |
| 760 | + storage::internal::ReadObjectRangeRequest request("test-bucket", |
| 761 | + "test-object"); |
| 762 | + auto actual = under_test.DownloadStreamToFile(std::move(stream), |
| 763 | + "test-file.txt", request); |
| 764 | + |
| 765 | + auto const code = PermanentError().code(); |
| 766 | + auto const code_str = StatusCodeToString(code); |
| 767 | + auto const msg = PermanentError().message(); |
| 768 | + EXPECT_THAT(actual, StatusIs(code, msg)); |
| 769 | + EXPECT_THAT( |
| 770 | + span_catcher->GetSpans(), |
| 771 | + ElementsAre(AllOf( |
| 772 | + SpanNamed("storage::Client::DownloadToFile/DownloadStreamToFile"), |
| 773 | + SpanHasInstrumentationScope(), SpanKindIsClient(), |
| 774 | + SpanWithStatus(opentelemetry::trace::StatusCode::kError, msg), |
| 775 | + SpanHasAttributes( |
| 776 | + OTelAttribute<std::string>("gl-cpp.status_code", code_str))))); |
| 777 | +} |
| 778 | + |
749 | 779 | TEST(TracingClientTest, ExecuteParallelUploadFile) { |
750 | 780 | auto span_catcher = InstallSpanCatcher(); |
751 | 781 | auto mock = std::make_shared<MockClient>(); |
|
0 commit comments