Refactor: tried to refactor code
- move scripts to assets/scripts (and updated build) - put most logic into HaproxyConfigGenerator - created DockerLabelHandler for all label handling from previous code - added unit tests and fixtures to cover HaproxyConfigGenerator and DockerLabelHandler - added a Makefile with build (for docker build) and test targets
This commit is contained in:
parent
5f9eac4b8a
commit
08de132450
21 changed files with 387 additions and 131 deletions
32
tests/test_labels.py
Normal file
32
tests/test_labels.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from .context import easymapping
|
||||
import json
|
||||
import pytest
|
||||
|
||||
def test_label_generation():
|
||||
label = easymapping.DockerLabelHandler("foo")
|
||||
|
||||
assert label.create("bar") == "foo.bar"
|
||||
assert label.create(["bar", "foobar"]) == "foo.bar.foobar"
|
||||
|
||||
|
||||
def test_label_data():
|
||||
label = easymapping.DockerLabelHandler("base")
|
||||
label.set_data(json.loads('{"base.definitions":"h2"}'))
|
||||
|
||||
label_name = label.create("definitions")
|
||||
assert label_name == "base.definitions"
|
||||
assert label.has_label(label_name)
|
||||
assert label.get(label_name) == "h2"
|
||||
|
||||
|
||||
def test_label_complex_key():
|
||||
label = easymapping.DockerLabelHandler("till")
|
||||
|
||||
data = dict()
|
||||
data["till.definitions"] = "h2"
|
||||
data["till.host.h2"] = "fqdn.example.org"
|
||||
data["till.mode.h2"] = "tcp"
|
||||
label.set_data(json.loads(json.dumps(data)))
|
||||
|
||||
assert label.get(label.create(["host", "h2"])) == "fqdn.example.org"
|
||||
assert label.get(label.create(["mode", "h2"])) == "tcp"
|
||||
Loading…
Add table
Add a link
Reference in a new issue