Google Cloud Spanner C++ Client
A C++ Client Library for Google Cloud Spanner
random_database_name.cc
Go to the documentation of this file.
1 // Copyright 2019 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 
16 
17 namespace google {
18 namespace cloud {
19 namespace spanner_testing {
20 inline namespace SPANNER_CLIENT_NS {
21 std::string RandomDatabaseName(
22  google::cloud::internal::DefaultPRNG& generator) {
23  // A database ID must be between 2 and 30 characters, fitting the regular
24  // expression `[a-z][a-z0-9_\-]*[a-z0-9]`
25  int max_size = 30;
26  std::string const prefix = "db-";
27  auto size = static_cast<int>(max_size - 1 - prefix.size());
28  return prefix +
29  google::cloud::internal::Sample(
30  generator, size, "abcdefghijlkmnopqrstuvwxyz012345689_-") +
31  google::cloud::internal::Sample(
32  generator, 1, "abcdefghijlkmnopqrstuvwxyz0123456789");
33 }
34 
35 } // namespace SPANNER_CLIENT_NS
36 } // namespace spanner_testing
37 } // namespace cloud
38 } // namespace google
std::string RandomDatabaseName(google::cloud::internal::DefaultPRNG &generator)
Create a random database name given a PRNG generator.
#define SPANNER_CLIENT_NS
Definition: version.h:22