Skip to content

Commit

Permalink
tests: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoVoges committed Sep 19, 2023
1 parent 41b3743 commit e11bd6e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 46 deletions.
49 changes: 26 additions & 23 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ gitdb = "^4.0.10"
packaging = "^23.0"
typing-extensions = "^4.0.0"
gojsonnet = { version = "^0.17.0", optional = true }
docker = { version = "^5.0.0", optional = true }
docker = { version = "^6.0.0", optional = true }
regex = "^2023.5.5"

[tool.poetry.extras]
Expand Down
31 changes: 17 additions & 14 deletions tests/test_omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import yaml

from kapitan.inventory import OmegaConfBackend
from kapitan.inventory.omegaconf import OmegaConfBackend


class OmegaConfMigrationTest(unittest.TestCase):
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_migration_complex_interpolation(self):

def test_migration_escaped_interpolation(self):
content = yaml.dump({"a": "\\${ref}"})
expected = yaml.dump({"a": "${tag:ref}"})
expected = yaml.dump({"a": "${escape:ref}"})

migrated = OmegaConfBackend.migrate(content)
self.assertEqual(migrated, expected)
Expand Down Expand Up @@ -109,6 +109,9 @@ def setUpClass(cls) -> None:
parameters:
target_name: target
kapitan:
vars:
target: target
# test value
value: test
Expand All @@ -122,7 +125,7 @@ def setUpClass(cls) -> None:
interpolation: ${.value}
# test custom resolvers
tag: ${tag:TAG}
tag: ${escape:TAG}
merge: ${merge:${merge1},${merge2}}
merge1:
- value1
Expand Down Expand Up @@ -181,31 +184,31 @@ def setUpClass(cls) -> None:
cls.params = inventory["nodes"]["target"]["parameters"]

def test_absolute_class(self):
self.assertTrue(self.params.get("absolute_class"))
self.assertTrue(self.params["absolute_class"])

def test_relative_class(self):
self.assertTrue(self.params.get("relative_class"))
self.assertTrue(self.params["relative_class"])

def test_value(self):
self.assertEqual(self.params.get("value"), "test")
self.assertEqual(self.params["value"], "test")

def test_absolute_interpolation(self):
self.assertEqual(self.params.get("absolute_interpolation"), "test")
self.assertEqual(self.params["absolute_interpolation"], "test")

def test_relative_interpolation(self):
self.assertEqual(self.params.get("relative").get("interpolation"), "test")
self.assertEqual(self.params["relative"]["interpolation"], "test")

def test_absolute_class(self):
self.assertEqual(self.params.get("value"), "test")
self.assertEqual(self.params["value"], "test")

def test_absolute_class(self):
self.assertEqual(self.params.get("tag"), "${TAG}")
self.assertEqual(self.params.get("merge"), ["value1", "value2"])
self.assertEqual(self.params.get("key"), "key")
self.assertEqual(self.params.get("full").get("key"), "full.key")
self.assertEqual(self.params["tag"], "${TAG}")
self.assertEqual(self.params["merge"], ["value1", "value2"])
self.assertEqual(self.params["key"], "key")
self.assertEqual(self.params["full"]["key"], "full.key")

def test_overwrite_prefix(self):
self.assertTrue(self.params.get("overwrite"))
self.assertTrue(self.params["overwrite"])

def test_meta_data(self):
meta = self.params["_meta_"]
Expand Down
16 changes: 8 additions & 8 deletions tests/test_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,12 @@ def test_reveal_embedded_subvars(self):
data = "message here: {}".format(ref_var_doesnt_exist.compile())
revealed_data = REVEALER_EMBEDDED.reveal_raw(data)

def test_ref_function_randomstr(self):
def test_ref_function_random_str(self):
"write randomstr to secret, confirm ref file exists, reveal and check"

tag = "?{base64:ref/randomstr||randomstr}"
tag = "?{base64:ref/randomstr||random:str}"
REF_CONTROLLER[tag] = RefParams()
self.assertTrue(os.path.isfile(os.path.join(REFS_HOME, "ref/base64")))
self.assertTrue(os.path.isfile(os.path.join(REFS_HOME, "ref/randomstr")))

file_with_tags = tempfile.mktemp()
with open(file_with_tags, "w") as fp:
Expand All @@ -383,7 +383,7 @@ def test_ref_function_randomstr(self):
self.assertTrue(get_entropy(revealed) > 4)

# Test with parameter nbytes=16, correlating with string length 16
tag = "?{base64:ref/randomstr||randomstr:16}"
tag = "?{base64:ref/randomstr||random:str:16}"
REF_CONTROLLER[tag] = RefParams()
REVEALER._reveal_tag_without_subvar.cache_clear()
revealed = REVEALER.reveal_raw_file(file_with_tags)
Expand Down Expand Up @@ -423,9 +423,9 @@ def test_ref_function_sha256(self):
# TODO write tests for RefController errors (lookups, etc..)

def test_ref_function_random_loweralphanum(self):
"write loweralphanum to secret, confirm ref file exists, reveal and check"
"write random:loweralphanum to secret, confirm ref file exists, reveal and check"

tag = "?{plain:ref/loweralphanum||loweralphanum}"
tag = "?{plain:ref/loweralphanum||random:loweralphanum}"
REF_CONTROLLER[tag] = RefParams()
self.assertTrue(os.path.isfile(os.path.join(REFS_HOME, "ref/loweralphanum")))

Expand All @@ -435,8 +435,8 @@ def test_ref_function_random_loweralphanum(self):
revealed = REVEALER.reveal_raw_file(file_with_tags)
self.assertEqual(len(revealed), 8) # default length of loweralphanum string is 8

# Test with parameter chars=16, correlating with string length 16
tag = "?{plain:ref/loweralphanum||loweralphanum:16}"
# Test with parameter nchars=16, correlating with string length 16
tag = "?{plain:ref/loweralphanum||random:loweralphanum:16}"
REF_CONTROLLER[tag] = RefParams()
REVEALER._reveal_tag_without_subvar.cache_clear()
revealed = REVEALER.reveal_raw_file(file_with_tags)
Expand Down

0 comments on commit e11bd6e

Please sign in to comment.