Skip to content

Commit

Permalink
Merge pull request #1371 from dhermes/pubsub-emulator-host
Browse files Browse the repository at this point in the history
Changing use of PUBSUB_HOST env. var. to PUBSUB_EMULATOR_HOST.
  • Loading branch information
dhermes committed Jan 14, 2016
2 parents 592c8e8 + 03dfdf7 commit 3a2a1c5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gcloud/environment_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
GCD_HOST = 'DATASTORE_HOST'
"""Environment variable defining host for GCD dataset server."""

PUBSUB_EMULATOR = 'PUBSUB_HOST'
PUBSUB_EMULATOR = 'PUBSUB_EMULATOR_HOST'
"""Environment variable defining host for Pub/Sub emulator."""

TESTS_DATASET = 'GCLOUD_TESTS_DATASET_ID'
Expand Down
7 changes: 5 additions & 2 deletions gcloud/pubsub/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ class Connection(base_connection.JSONConnection):
def __init__(self, credentials=None, http=None, api_base_url=None):
super(Connection, self).__init__(credentials=credentials, http=http)
if api_base_url is None:
api_base_url = os.getenv(PUBSUB_EMULATOR,
self.__class__.API_BASE_URL)
emulator_host = os.getenv(PUBSUB_EMULATOR)
if emulator_host is None:
api_base_url = self.__class__.API_BASE_URL
else:
api_base_url = 'http://' + emulator_host
self.api_base_url = api_base_url

def build_api_url(self, path, query_params=None,
Expand Down
4 changes: 2 additions & 2 deletions gcloud/pubsub/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def test_custom_url_from_env(self):
from gcloud._testing import _Monkey
from gcloud.environment_vars import PUBSUB_EMULATOR

HOST = object()
HOST = 'localhost:8187'
fake_environ = {PUBSUB_EMULATOR: HOST}

with _Monkey(os, getenv=fake_environ.get):
conn = self._makeOne()

klass = self._getTargetClass()
self.assertNotEqual(conn.api_base_url, klass.API_BASE_URL)
self.assertEqual(conn.api_base_url, HOST)
self.assertEqual(conn.api_base_url, 'http://' + HOST)

def test_custom_url_from_constructor(self):
HOST = object()
Expand Down

0 comments on commit 3a2a1c5

Please sign in to comment.