From 8fe3e6202135b88501764e8104e400f39f9801e6 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Mon, 4 Feb 2019 23:43:08 +0100
Subject: [PATCH] hostname parsing tests

---
 test/conftest.py           |  8 ++++++++
 test/test_junosspace_io.py | 15 ++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/test/conftest.py b/test/conftest.py
index 748d607f..40c6a518 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -158,3 +158,11 @@ def client_with_mocked_data(client, mocker):
         'inventory_provider.routes.common.redis.StrictRedis',
         MockedRedis)
     return client
+
+
+@pytest.fixture
+def mocked_redis(mocker):
+    mocker.patch(
+        'inventory_provider.routes.common.redis.StrictRedis',
+        MockedRedis)
+
diff --git a/test/test_junosspace_io.py b/test/test_junosspace_io.py
index 82c774ba..eb910fc4 100644
--- a/test/test_junosspace_io.py
+++ b/test/test_junosspace_io.py
@@ -1,9 +1,11 @@
 import os
+import re
 
 import responses
 
 import inventory_provider
 from inventory_provider import juniper
+from inventory_provider.tasks import worker
 
 TEST_DATA_FILENAME = os.path.realpath(os.path.join(
     inventory_provider.__path__[0],
@@ -29,4 +31,15 @@ def test_junosspace_devices_parsing(data_config):
     # test for .re\d+ greediness
     assert 'mx1.ams.nl.geant.net' in hostnames
     # test that 'qfx1.fra.de' is parsed
-    assert 'qfx1.fra.de.geant.net' in hostnames
\ No newline at end of file
+    assert 'qfx1.fra.de.geant.net' in hostnames
+
+
+def test_router_hostname_derivation(mocked_redis):
+    config = {
+        'redis': {
+            'hostname': None,
+            'port': None
+        }
+    }
+    for hostname in worker._derive_router_hostnames(config):
+        assert re.match('^mx[\d].+\.geant\.net$', hostname)
-- 
GitLab