Skip to content

Commit

Permalink
utilize runfiles to read ud_sa_key_file
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelgrosso1 committed Sep 26, 2024
1 parent 61aa78b commit e1dfe15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions google/cloud/storage/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ VARIATIONS = {
"//google/cloud/testing_util:google_cloud_cpp_testing_private",
"//protos:system_includes",
"//protos/google/cloud/storage/tests:storage_conformance_tests_cc_proto",
"@bazel_tools//tools/cpp/runfiles",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
],
Expand Down
21 changes: 15 additions & 6 deletions google/cloud/storage/tests/universe_domain_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#include "google/cloud/universe_domain.h"
#include "google/cloud/universe_domain_options.h"
#include "google/cloud/version.h"
#include "tools/cpp/runfiles/runfiles.h"
#include <gmock/gmock.h>
#include <fstream>
#include <memory>
#include <string>
#include <utility>

Expand All @@ -31,6 +33,7 @@ namespace storage {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {

using bazel::tools::cpp::runfiles::Runfiles;
using ::google::cloud::internal::GetEnv;

class UniverseDomainIntegrationTest
Expand All @@ -54,7 +57,12 @@ auto TestOptions() {
auto projectId = GetEnv("UD_PROJECT").value_or("");
Options options;

auto is = std::ifstream(sa_key_file);
std::string error;
std::unique_ptr<Runfiles> runfiles(Runfiles::CreateForTest(&error));
if (runfiles == nullptr) throw error;
auto sa_key_file_path = runfiles->Rlocation(sa_key_file);

auto is = std::ifstream(sa_key_file_path);
is.exceptions(std::ios::badbit);
auto contents = std::string(std::istreambuf_iterator<char>(is.rdbuf()), {});
options.set<UnifiedCredentialsOption>(
Expand Down Expand Up @@ -83,12 +91,13 @@ TEST_F(UniverseDomainIntegrationTest, BucketAndObjectCRUD) {
ASSERT_STATUS_OK(insert);
ScheduleForDelete(*insert);

auto read = client.ReadObject(bucket_name(), object_name());
std::string buffer{std::istream_iterator<char>(read),
std::istream_iterator<char>()};
auto reader = client.ReadObject(bucket_name(), object_name());
ASSERT_TRUE(reader.good());
ASSERT_STATUS_OK(reader.status());

ASSERT_FALSE(read.bad());
ASSERT_EQ(buffer, LoremIpsum());
auto const actual =
std::string{std::istreambuf_iterator<char>{reader.rdbuf()}, {}};
EXPECT_EQ(LoremIpsum(), actual);
}

} // namespace
Expand Down

0 comments on commit e1dfe15

Please sign in to comment.