Skip to content

Commit

Permalink
Improve hostname test cases and fix domain regex
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco committed Jun 21, 2019
1 parent f568ef7 commit 84ca12c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kubeyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def parse_ref():
im = replace
elif len(segments) == 2:
domainComponent = '([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])'
domain = 'localhost|(%s([.]%s)+)(:[0-9]+)?' % (domainComponent, domainComponent)
domain = '(localhost|(%s([.]%s)+))(:[0-9]+)?' % (domainComponent, domainComponent)
if re.fullmatch(domain, segments[0]):
reg = segments[0]
im = segments[1]
Expand Down
12 changes: 5 additions & 7 deletions test_kubeyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def image_components(draw):
host_components = strats.from_regex(r"^[a-zA-Z0-9]([a-zA-Z0-9-]{0,125}[a-zA-Z0-9])?$").map(strip)
port_numbers = strats.integers(min_value=1, max_value=32767)

hostnames_without_port = strats.builds('.'.join,
strats.lists(elements=host_components, min_size=1, max_size=6))
hostnames_without_port = strats.just('localhost') | \
strats.builds('.'.join,
strats.lists(elements=host_components, min_size=2, max_size=6))

hostnames_with_port = strats.builds(
lambda h, p: str(h)+':'+str(p),
Expand All @@ -54,11 +55,8 @@ def image_components(draw):

host_segments = strats.just([]) | hostnames.map(lambda x: [x])

# This results in realistic image refs, we use a min_size of two for
# test cases that make use of a hostname as the Docker image ref spec
# has a limitation on images with a hostname that requires it to have
# at least two elements if the hostname is not localhost.
exact_image_names = strats.builds('/'.join, strats.lists(elements=image_components(), min_size=2, max_size=6))
# This results in realistic image refs
exact_image_names = strats.builds('/'.join, strats.lists(elements=image_components(), min_size=1, max_size=6))
# This is somewhat faster, if we don't care about having realistic
# image refs
sloppy_image_names = strats.text(string.ascii_letters + '-/_', min_size=1, max_size=255).map(strip)
Expand Down

0 comments on commit 84ca12c

Please sign in to comment.