|
| 1 | +// Copyright 2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include "google/cloud/storage/internal/grpc/monitoring_project.h" |
| 16 | +#include "google/cloud/storage/internal/grpc/default_options.h" |
| 17 | +#include "google/cloud/storage/options.h" |
| 18 | +#include "google/cloud/options.h" |
| 19 | +#include "google/cloud/project.h" |
| 20 | +#include "google/cloud/testing_util/scoped_environment.h" |
| 21 | +#include "absl/types/optional.h" |
| 22 | +#include <gmock/gmock.h> |
| 23 | + |
| 24 | +namespace google { |
| 25 | +namespace cloud { |
| 26 | +namespace storage_internal { |
| 27 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN |
| 28 | +namespace { |
| 29 | + |
| 30 | +using ::google::cloud::testing_util::ScopedEnvironment; |
| 31 | +using ::testing::Optional; |
| 32 | + |
| 33 | +TEST(MonitoringProject, Default) { |
| 34 | + ScopedEnvironment pr("GOOGLE_CLOUD_PROJECT", absl::nullopt); |
| 35 | + auto storage_options = DefaultOptionsGrpc(Options{}); |
| 36 | + EXPECT_EQ(MonitoringProject(storage_options), |
| 37 | + absl::optional<Project>(absl::nullopt)); |
| 38 | +} |
| 39 | + |
| 40 | +TEST(MonitoringProject, WithExplicitProject) { |
| 41 | + // The cases where the project is set in the environment, or in both the |
| 42 | + // environment and the application-provided options are already tested. Here |
| 43 | + // we (un)set the environment only to prevent flakes. |
| 44 | + ScopedEnvironment pr("GOOGLE_CLOUD_PROJECT", absl::nullopt); |
| 45 | + auto storage_options = DefaultOptionsGrpc( |
| 46 | + Options{}.set<storage::ProjectIdOption>("test-only-project")); |
| 47 | + EXPECT_THAT(MonitoringProject(storage_options), |
| 48 | + Optional<Project>(Project("test-only-project"))); |
| 49 | +} |
| 50 | + |
| 51 | +} // namespace |
| 52 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END |
| 53 | +} // namespace storage_internal |
| 54 | +} // namespace cloud |
| 55 | +} // namespace google |
0 commit comments