Skip to content

Commit 0adbd70

Browse files
committed
Merge pull request #1628 from tseaver/logging-system_test-sink_create
Add system test for 'Sink.create', w/ Storage bucket destination
2 parents 9f37a05 + 76a47d9 commit 0adbd70

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

system_tests/logging_.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
from gcloud import logging
2222

2323

24-
DEFAULT_LOGGER_NAME = 'system-tests-logger-%d' % (1000 * time.time(),)
25-
DEFAULT_METRIC_NAME = 'system-tests-metric-%d' % (1000 * time.time(),)
24+
_MILLIS = 1000 * time.time()
25+
DEFAULT_LOGGER_NAME = 'system-tests-logger-%d' % (_MILLIS,)
26+
DEFAULT_METRIC_NAME = 'system-tests-metric-%d' % (_MILLIS,)
27+
DEFAULT_SINK_NAME = 'system-tests-sink-%d' % (_MILLIS,)
2628
DEFAULT_FILTER = 'logName:syslog AND severity>=INFO'
2729
DEFAULT_DESCRIPTION = 'System testing'
30+
BUCKET_NAME = 'gcloud-python-system-testing-%d' % (_MILLIS,)
2831

2932

3033
class Config(object):
@@ -123,3 +126,25 @@ def test_update_metric(self):
123126
after = after_info[DEFAULT_METRIC_NAME]
124127
self.assertEqual(after.filter_, NEW_FILTER)
125128
self.assertEqual(after.description, NEW_DESCRIPTION)
129+
130+
def test_create_sink_storage_bucket(self):
131+
from gcloud import storage
132+
BUCKET_URI = 'storage.googleapis.com/%s' % (BUCKET_NAME,)
133+
134+
# Create the destination bucket, and set up the ACL to allow
135+
# Cloud Logging to write into it.
136+
storage_client = storage.Client()
137+
bucket = storage_client.create_bucket(BUCKET_NAME)
138+
self.to_delete.append(bucket)
139+
bucket.acl.reload()
140+
logs_group = bucket.acl.group('cloud-logs@google.com')
141+
logs_group.grant_owner()
142+
bucket.acl.add_entity(logs_group)
143+
bucket.acl.save()
144+
145+
sink = Config.CLIENT.sink(
146+
DEFAULT_SINK_NAME, DEFAULT_FILTER, BUCKET_URI)
147+
self.assertFalse(sink.exists())
148+
sink.create()
149+
self.to_delete.append(sink)
150+
self.assertTrue(sink.exists())

0 commit comments

Comments
 (0)