Skip to content

Commit cfa1084

Browse files
authored
Refactor storage class well-know values. (#929)
I will need the well-known values separated from the BucketMetadata. Part of the changes for #537.
1 parent a5dacb7 commit cfa1084

File tree

8 files changed

+114
-15
lines changed

8 files changed

+114
-15
lines changed

google/cloud/storage/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ add_library(storage_client
183183
well_known_parameters.h
184184
retry_policy.h
185185
status.h
186+
storage_class.h
186187
version.h
187188
version.cc)
188189
target_link_libraries(storage_client
@@ -260,6 +261,7 @@ set(storage_client_unit_tests
260261
object_metadata_test.cc
261262
object_test.cc
262263
retry_policy_test.cc
264+
storage_class_test.cc
263265
storage_client_options_test.cc
264266
link_test.cc)
265267

google/cloud/storage/bucket_metadata.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,6 @@ std::ostream& operator<<(std::ostream& os, BucketMetadata const& rhs) {
214214
return os;
215215
}
216216

217-
constexpr char BucketMetadata::STORAGE_CLASS_STANDARD[];
218-
constexpr char BucketMetadata::STORAGE_CLASS_MULTI_REGIONAL[];
219-
constexpr char BucketMetadata::STORAGE_CLASS_REGIONAL[];
220-
constexpr char BucketMetadata::STORAGE_CLASS_NEARLINE[];
221-
constexpr char BucketMetadata::STORAGE_CLASS_COLDLINE[];
222-
constexpr char BucketMetadata::STORAGE_CLASS_DURABLE_REDUCED_AVAILABILITY[];
223217
} // namespace STORAGE_CLIENT_NS
224218
} // namespace storage
225219
} // namespace cloud

google/cloud/storage/bucket_metadata.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,6 @@ class BucketMetadata : private internal::CommonMetadata<BucketMetadata> {
393393
bool operator==(BucketMetadata const& rhs) const;
394394
bool operator!=(BucketMetadata const& rhs) const { return not(*this == rhs); }
395395

396-
constexpr static char STORAGE_CLASS_STANDARD[] = "STANDARD";
397-
constexpr static char STORAGE_CLASS_MULTI_REGIONAL[] = "MULTI_REGIONAL";
398-
constexpr static char STORAGE_CLASS_REGIONAL[] = "REGIONAL";
399-
constexpr static char STORAGE_CLASS_NEARLINE[] = "NEARLINE";
400-
constexpr static char STORAGE_CLASS_COLDLINE[] = "COLDLINE";
401-
constexpr static char STORAGE_CLASS_DURABLE_REDUCED_AVAILABILITY[] =
402-
"DURABLE_REDUCED_AVAILABILITY";
403-
404396
private:
405397
friend std::ostream& operator<<(std::ostream& os, BucketMetadata const& rhs);
406398
// Keep the fields in alphabetical order.

google/cloud/storage/bucket_metadata_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/storage/bucket_metadata.h"
16+
#include "google/cloud/storage/storage_class.h"
1617
#include <gmock/gmock.h>
1718

1819
namespace google {
@@ -174,7 +175,7 @@ TEST(BucketMetadataTest, Parse) {
174175
EXPECT_EQ(123456789, actual.project_number());
175176
EXPECT_EQ("https://www.googleapis.com/storage/v1/b/test-bucket",
176177
actual.self_link());
177-
EXPECT_EQ(BucketMetadata::STORAGE_CLASS_STANDARD, actual.storage_class());
178+
EXPECT_EQ(storage_class::Standard(), actual.storage_class());
178179
// Use `date -u +%s --date='2018-05-19T19:31:14Z'` to get the magic number:
179180
auto magic_timestamp = 1526758274L;
180181
using std::chrono::duration_cast;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2018 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+
// http://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+
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_STORAGE_CLASS_H_
16+
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_STORAGE_CLASS_H_
17+
18+
#include "google/cloud/storage/version.h"
19+
20+
namespace google {
21+
namespace cloud {
22+
namespace storage {
23+
inline namespace STORAGE_CLIENT_NS {
24+
/**
25+
* Define functions with the well-know storage classes.
26+
*
27+
* These functions are provided to avoid typos when setting or comparing storage
28+
* classes.
29+
*/
30+
namespace storage_class {
31+
char const* Standard() {
32+
static constexpr char kStorageClass[] = "STANDARD";
33+
return kStorageClass;
34+
}
35+
36+
char const* MultiRegional() {
37+
static constexpr char kStorageClass[] = "MULTI_REGIONAL";
38+
return kStorageClass;
39+
}
40+
41+
char const* Regional() {
42+
static constexpr char kStorageClass[] = "REGIONAL";
43+
return kStorageClass;
44+
}
45+
46+
char const* Nearline() {
47+
static constexpr char kStorageClass[] = "NEARLINE";
48+
return kStorageClass;
49+
}
50+
51+
char const* Coldline() {
52+
static constexpr char kStorageClass[] = "COLDLINE";
53+
return kStorageClass;
54+
}
55+
56+
char const* DurableReducedAvailability() {
57+
static constexpr char kStorageClass[] = "DURABLE_REDUCED_AVAILABILITY";
58+
return kStorageClass;
59+
}
60+
61+
} // namespace storage_class
62+
} // namespace STORAGE_CLIENT_NS
63+
} // namespace storage
64+
} // namespace cloud
65+
} // namespace google
66+
67+
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_STORAGE_CLASS_H_
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2018 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+
// http://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/storage_class.h"
16+
#include <gmock/gmock.h>
17+
18+
namespace google {
19+
namespace cloud {
20+
namespace storage {
21+
inline namespace STORAGE_CLIENT_NS {
22+
namespace storage_class {
23+
namespace {
24+
25+
/// @test Verify the values for the storage class functions.
26+
TEST(StorageClassTest, Values) {
27+
EXPECT_EQ(std::string("STANDARD"), Standard());
28+
EXPECT_EQ(std::string("MULTI_REGIONAL"), MultiRegional());
29+
EXPECT_EQ(std::string("REGIONAL"), Regional());
30+
EXPECT_EQ(std::string("NEARLINE"), Nearline());
31+
EXPECT_EQ(std::string("COLDLINE"), Coldline());
32+
EXPECT_EQ(std::string("DURABLE_REDUCED_AVAILABILITY"),
33+
DurableReducedAvailability());
34+
}
35+
36+
} // namespace
37+
} // namespace storage_class
38+
} // namespace STORAGE_CLIENT_NS
39+
} // namespace storage
40+
} // namespace cloud
41+
} // namespace google

google/cloud/storage/storage_client.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ storage_client_HDRS = [
5151
"well_known_parameters.h",
5252
"retry_policy.h",
5353
"status.h",
54+
"storage_class.h",
5455
"version.h",
5556
]
5657

google/cloud/storage/storage_client_unit_tests.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ storage_client_unit_tests = [
3333
"object_metadata_test.cc",
3434
"object_test.cc",
3535
"retry_policy_test.cc",
36+
"storage_class_test.cc",
3637
"storage_client_options_test.cc",
3738
"link_test.cc",
3839
]

0 commit comments

Comments
 (0)