Skip to content
Merged
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
29 changes: 27 additions & 2 deletions system_tests/logging_.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
from gcloud import logging


DEFAULT_LOGGER_NAME = 'system-tests-logger-%d' % (1000 * time.time(),)
DEFAULT_METRIC_NAME = 'system-tests-metric-%d' % (1000 * time.time(),)
_MILLIS = 1000 * time.time()
DEFAULT_LOGGER_NAME = 'system-tests-logger-%d' % (_MILLIS,)
DEFAULT_METRIC_NAME = 'system-tests-metric-%d' % (_MILLIS,)
DEFAULT_SINK_NAME = 'system-tests-sink-%d' % (_MILLIS,)
DEFAULT_FILTER = 'logName:syslog AND severity>=INFO'
DEFAULT_DESCRIPTION = 'System testing'
BUCKET_NAME = 'gcloud-python-system-testing-%d' % (_MILLIS,)


class Config(object):
Expand Down Expand Up @@ -123,3 +126,25 @@ def test_update_metric(self):
after = after_info[DEFAULT_METRIC_NAME]
self.assertEqual(after.filter_, NEW_FILTER)
self.assertEqual(after.description, NEW_DESCRIPTION)

def test_create_sink_storage_bucket(self):
from gcloud import storage
BUCKET_URI = 'storage.googleapis.com/%s' % (BUCKET_NAME,)

# Create the destination bucket, and set up the ACL to allow
# Cloud Logging to write into it.
storage_client = storage.Client()
bucket = storage_client.create_bucket(BUCKET_NAME)
self.to_delete.append(bucket)
bucket.acl.reload()
logs_group = bucket.acl.group('[email protected]')
logs_group.grant_owner()
bucket.acl.add_entity(logs_group)
bucket.acl.save()

sink = Config.CLIENT.sink(
DEFAULT_SINK_NAME, DEFAULT_FILTER, BUCKET_URI)
self.assertFalse(sink.exists())
sink.create()
self.to_delete.append(sink)
self.assertTrue(sink.exists())