| 66 | class GcsTestbench : public ::testing::Environment { |
| 67 | public: |
| 68 | GcsTestbench() { |
| 69 | port_ = std::to_string(GetListenPort()); |
| 70 | auto error = std::string("Could not start GCS emulator 'storage-testbench'"); |
| 71 | auto server_process = std::make_unique<util::Process>(); |
| 72 | auto status = server_process->SetExecutable("storage-testbench"); |
| 73 | if (!status.ok()) { |
| 74 | error += ": " + status.ToString(); |
| 75 | error_ = std::move(error); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | server_process->SetArgs({"--port", port_}); |
| 80 | server_process->IgnoreStderr(); |
| 81 | status = server_process->Execute(); |
| 82 | if (!status.ok()) { |
| 83 | error += ": " + status.ToString(); |
| 84 | error_ = std::move(error); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | auto testbench_is_running = [&server_process, this]() { |
| 89 | auto ready_timeout = std::chrono::seconds(10); |
| 90 | std::chrono::time_point<std::chrono::steady_clock> end = |
| 91 | std::chrono::steady_clock::now() + ready_timeout; |
| 92 | while (server_process->IsRunning() && std::chrono::steady_clock::now() < end) { |
| 93 | auto client = gcs::Client( |
| 94 | google::cloud::Options{} |
| 95 | .set<gcs::RestEndpointOption>("http://127.0.0.1:" + port_) |
| 96 | .set<gc::UnifiedCredentialsOption>(gc::MakeInsecureCredentials()) |
| 97 | .set<gcs::RetryPolicyOption>( |
| 98 | gcs::LimitedTimeRetryPolicy(ready_timeout).clone())); |
| 99 | auto metadata = client.GetBucketMetadata("nonexistent"); |
| 100 | if (metadata.status().code() == google::cloud::StatusCode::kNotFound) { |
| 101 | return true; |
| 102 | } |
| 103 | } |
| 104 | return false; |
| 105 | }; |
| 106 | |
| 107 | if (!testbench_is_running()) { |
| 108 | error += " (failed to listen)"; |
| 109 | error_ = std::move(error); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | server_process_ = std::move(server_process); |
| 114 | } |
| 115 | |
| 116 | bool running() { return server_process_ && server_process_->IsRunning(); } |
| 117 |
nothing calls this directly
no test coverage detected