import logging
import os
+import re
import shutil
import glob2 # Switch to glob when Python < 3.5 support is dropped
log = logging.getLogger(__name__)
+def _format_url(url):
+ """Ensure url starts with http and trim trailing '/'s."""
+ start_pattern = re.compile('^(http|https)://')
+ if not start_pattern.match(url):
+ url = 'http://{}'.format(url)
+
+ if url.endswith('/'):
+ url = url.rstrip('/')
+
+ return url
+
+
def copy_archives(workspace, pattern=None):
"""Copy files matching PATTERN in a WORKSPACE to the current directory.
import pytest
from lftools import cli
+import lftools.deploy as deploy_sys
FIXTURE_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
)
+def test_format_url():
+ """Test url format."""
+ test_url=[["192.168.1.1", "http://192.168.1.1"],
+ ["192.168.1.1:8081", "http://192.168.1.1:8081"],
+ ["192.168.1.1:8081/nexus", "http://192.168.1.1:8081/nexus"],
+ ["192.168.1.1:8081/nexus/", "http://192.168.1.1:8081/nexus"],
+ ["http://192.168.1.1:8081/nexus", "http://192.168.1.1:8081/nexus"],
+ ["https://192.168.1.1:8081/nexus", "https://192.168.1.1:8081/nexus"],
+ ["https://192.168.1.1:8081/nexus/", "https://192.168.1.1:8081/nexus"],
+ ["www.goodnexussite.org:8081", "http://www.goodnexussite.org:8081"],
+ ["192.168.1.1:8081/nexus///", "http://192.168.1.1:8081/nexus"]]
+
+ for url in test_url:
+ assert deploy_sys._format_url(url[0]) == url[1]
+
+
@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, 'deploy'),
)