Skip to content

Commit

Permalink
Merge pull request #1628 from tseaver/logging-system_test-sink_create
Browse files Browse the repository at this point in the history
Add system test for 'Sink.create', w/ Storage bucket destination
  • Loading branch information
tseaver committed Mar 22, 2016
2 parents 9f37a05 + 76a47d9 commit 0adbd70
Showing 1 changed file with 27 additions and 2 deletions.
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('cloud-logs@google.com')
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())

0 comments on commit 0adbd70

Please sign in to comment.