Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(spanner): use uuid for unique id #4198

Merged
merged 1 commit into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions spanner/cloud-client/backup_sample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
# 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.
import random
import string
import uuid

from google.cloud import spanner
import pytest
Expand All @@ -22,20 +21,17 @@

def unique_instance_id():
""" Creates a unique id for the database. """
return 'test-instance-{}'.format(''.join(random.choice(
string.ascii_lowercase + string.digits) for _ in range(5)))
return f'test-instance-{uuid.uuid4().hex[:10]}'


def unique_database_id():
""" Creates a unique id for the database. """
return 'test-db-{}'.format(''.join(random.choice(
string.ascii_lowercase + string.digits) for _ in range(5)))
return f'test-db-{uuid.uuid4().hex[:10]}'


def unique_backup_id():
""" Creates a unique id for the backup. """
return 'test-backup-{}'.format(''.join(random.choice(
string.ascii_lowercase + string.digits) for _ in range(5)))
return f'test-backup-{uuid.uuid4().hex[:10]}'


INSTANCE_ID = unique_instance_id()
Expand Down
6 changes: 2 additions & 4 deletions spanner/cloud-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
# limitations under the License.

import os
import random
import string
import time
import uuid

from google.cloud import spanner
import pytest
Expand All @@ -25,8 +24,7 @@

def unique_database_id():
""" Creates a unique id for the database. """
return 'test-db-{}'.format(''.join(random.choice(
string.ascii_lowercase + string.digits) for _ in range(5)))
return f'test-db-{uuid.uuid4().hex[:10]}'


INSTANCE_ID = os.environ['SPANNER_INSTANCE']
Expand Down