Skip to content

Commit

Permalink
tests(storage): add universe domain integration test (#14728)
Browse files Browse the repository at this point in the history
* tests(storage): add universe domain integration test

add and modify builds

adding perms

checkers

skip tests if missing UD vars

cleanup

checkers

use tags to filter test not TEST_SKIP

fix testoptions

fix testoptions

checkers

skip test if environment variables missing

remove test from cmake build

remove module.bazel

remove storage specific universe domain build scripts

update copyright date

create ud:bazel_test to copy environment variables to test env

include common bazel args

utilize runfiles to read ud_sa_key_file

debug code

more debug code

symlink temp file

fix vars

remove runfiles

remove testing code

use run

debug

use test

add sandbox_add_mount_pair to bazel test

* temp printing to verify test

* more debug

* temporarily turn on all output

* remove debug code
  • Loading branch information
ddelgrosso1 authored Oct 1, 2024
1 parent 08acb50 commit 1360b76
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ci/cloudbuild/builds/lib/universe_domain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ if ((CI_CLOUDBUILD_BUILDS_LIB_UNIVERSE_DOMAIN_SH__++ != 0)); then
return 0
fi # include guard

source module ci/cloudbuild/builds/lib/bazel.sh

# Only create the SA key file if the secret is available.
if [[ -n "${UD_SERVICE_ACCOUNT}" ]]; then
ORIG_UMASK=$(umask)
Expand All @@ -33,3 +35,12 @@ function ud::bazel_run() {
io::log "Executing bazel run $1 with obscured arguments:"
bazel run --ui_event_filters=-info -- "$@"
}

function ud::bazel_test() {
mapfile -t args < <(bazel::common_args)
io::log "Executing bazel test $1 with obscured arguments:"
bazel test "${args[@]}" --sandbox_add_mount_pair=/tmp \
--test_env=UD_SA_KEY_FILE="${UD_SA_KEY_FILE}" \
--test_env=UD_REGION="${UD_REGION}" \
--test_env=UD_PROJECT="${UD_PROJECT}" -- "$@"
}
1 change: 1 addition & 0 deletions ci/cloudbuild/builds/universe-domain-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export CXX=clang++
if [[ -n "${UD_SA_KEY_FILE}" ]]; then
ud::bazel_run //google/cloud/universe_domain/demo:kms_demo \
"${UD_PROJECT}" "${UD_REGION}" "${UD_SA_KEY_FILE}"
ud::bazel_test //google/cloud/storage/tests:universe_domain_integration_test
else
source module ci/etc/integration-tests-config.sh
bazel run -- //google/cloud/universe_domain/demo:kms_demo \
Expand Down
28 changes: 28 additions & 0 deletions google/cloud/storage/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,31 @@ VARIATIONS = {
"@com_google_googletest//:gtest_main",
],
) for test in storage_client_integration_tests for v_label, v_env in VARIATIONS.items()]

[cc_test(
name = test.replace("/", "_").replace(".cc", ""),
timeout = "long",
srcs = [test],
linkopts = select({
"@platforms//os:windows": [],
"//conditions:default": [
"-lpthread",
"-ldl",
],
}),
tags = [
"integration-test",
],
deps = [
"//:common",
"//:experimental-universe_domain",
"//:storage",
"//google/cloud/storage:storage_client_testing",
"//google/cloud/testing_util:google_cloud_cpp_testing_grpc_private",
"//google/cloud/testing_util:google_cloud_cpp_testing_private",
"//protos:system_includes",
"//protos/google/cloud/storage/tests:storage_conformance_tests_cc_proto",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
],
) for test in ["universe_domain_integration_test.cc"]]
101 changes: 101 additions & 0 deletions google/cloud/storage/tests/universe_domain_integration_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 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.

#include "google/cloud/storage/client.h"
#include "google/cloud/storage/options.h"
#include "google/cloud/storage/testing/storage_integration_test.h"
#include "google/cloud/internal/filesystem.h"
#include "google/cloud/internal/getenv.h"
#include "google/cloud/testing_util/status_matchers.h"
#include "google/cloud/universe_domain.h"
#include "google/cloud/universe_domain_options.h"
#include "google/cloud/version.h"
#include <gmock/gmock.h>
#include <fstream>
#include <memory>
#include <string>
#include <utility>

namespace google {
namespace cloud {
namespace storage {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {

using ::google::cloud::internal::GetEnv;

class UniverseDomainIntegrationTest
: public google::cloud::storage::testing::StorageIntegrationTest {
protected:
void SetUp() override {
bucket_name_ = MakeRandomBucketName();
object_name_ = MakeRandomObjectName();
}

std::string const& bucket_name() const { return bucket_name_; }
std::string const& object_name() const { return object_name_; }

private:
std::string bucket_name_;
std::string object_name_;
};

auto TestOptions() {
auto sa_key_file = GetEnv("UD_SA_KEY_FILE").value_or("");
auto projectId = GetEnv("UD_PROJECT").value_or("");
Options options;

auto is = std::ifstream(sa_key_file);
is.exceptions(std::ios::badbit);
auto contents = std::string(std::istreambuf_iterator<char>(is.rdbuf()), {});
options.set<UnifiedCredentialsOption>(
MakeServiceAccountCredentials(contents));

auto ud_options = AddUniverseDomainOption(
ExperimentalTag{}, options.set<ProjectIdOption>(projectId));
if (!ud_options.ok()) throw std::move(ud_options).status();

return *ud_options;
}

TEST_F(UniverseDomainIntegrationTest, BucketAndObjectCRUD) {
auto region = GetEnv("UD_REGION").value_or("");
if (GetEnv("UD_SA_KEY_FILE").value_or("").empty() ||
GetEnv("UD_PROJECT").value_or("").empty() || region.empty())
GTEST_SKIP();

auto client = Client(TestOptions());
auto bucket =
client.CreateBucket(bucket_name(), BucketMetadata{}.set_location(region));
ASSERT_STATUS_OK(bucket);
ScheduleForDelete(*bucket);

auto insert = client.InsertObject(bucket_name(), object_name(), LoremIpsum());
ASSERT_STATUS_OK(insert);
ScheduleForDelete(*insert);

auto reader = client.ReadObject(bucket_name(), object_name());
ASSERT_TRUE(reader.good());
ASSERT_STATUS_OK(reader.status());

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

} // namespace
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace storage
} // namespace cloud
} // namespace google

0 comments on commit 1360b76

Please sign in to comment.