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

Add system test for 'logger.log_text' and 'logger.log_struct'. #1609

Merged
merged 1 commit into from
Mar 17, 2016
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
71 changes: 71 additions & 0 deletions system_tests/logging_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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 time

import unittest2

from gcloud import _helpers
from gcloud.environment_vars import TESTS_PROJECT
from gcloud import logging


DEFAULT_LOGGER_NAME = 'system-tests-%d' % (1000 * time.time(),)


class Config(object):
"""Run-time configuration to be modified at set-up.

This is a mutable stand-in to allow test set-up to modify
global state.
"""
CLIENT = None


def setUpModule():
_helpers.PROJECT = TESTS_PROJECT

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Config.CLIENT = logging.Client()


class TestLogging(unittest2.TestCase):

def setUp(self):
self.to_delete = []

def tearDown(self):
for doomed in self.to_delete:
doomed.delete()

def test_log_text(self):
TEXT_PAYLOAD = 'System test: test_log_text'
logger = Config.CLIENT.logger(DEFAULT_LOGGER_NAME)
self.to_delete.append(logger)
logger.log_text(TEXT_PAYLOAD)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

time.sleep(2)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

entries, _ = logger.list_entries()
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0].payload, TEXT_PAYLOAD)

def test_log_struct(self):
JSON_PAYLOAD = {
'message': 'System test: test_log_struct',
'weather': 'partly cloudy',
}
logger = Config.CLIENT.logger(DEFAULT_LOGGER_NAME)
self.to_delete.append(logger)
logger.log_struct(JSON_PAYLOAD)
time.sleep(2)
entries, _ = logger.list_entries()
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0].payload, JSON_PAYLOAD)
3 changes: 3 additions & 0 deletions system_tests/run_system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bigtable
import bigtable_happybase
import datastore
import logging_

This comment was marked as spam.

This comment was marked as spam.

import pubsub
import storage
import system_test_utils
Expand All @@ -34,6 +35,7 @@
'bigquery': ['project', 'credentials'],
'bigtable': ['project', 'credentials'],
'bigtable-happybase': ['project', 'credentials'],
'logging': ['project', 'credentials'],

This comment was marked as spam.

}
TEST_MODULES = {
'datastore': datastore,
Expand All @@ -42,6 +44,7 @@
'bigquery': bigquery,
'bigtable': bigtable,
'bigtable-happybase': bigtable_happybase,
'logging': logging_,
}


Expand Down