Skip to content

Commit

Permalink
Ensure that filter template does exist
Browse files Browse the repository at this point in the history
  • Loading branch information
cavokz committed May 16, 2022
1 parent 609a043 commit 2b0eb0c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
9 changes: 8 additions & 1 deletion esrally/track/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,19 @@ def __init__(self, track, params, templates, **kwargs):
elif templates:
filter_template = params.get("template")
settings = params.get("settings")
template_definitions = []
for template in templates:
if not filter_template or template.name == filter_template:
body = template.content
if body and "template" in body:
body = CreateComposableTemplateParamSource._create_or_merge(template.content, ["template", "settings"], settings)
self.template_definitions.append((template.name, body))
template_definitions.append((template.name, body))
if filter_template and not template_definitions:
template_names = ", ".join([template.name for template in templates])
raise exceptions.InvalidSyntax(
f"Unknown template: {filter_template}. Available templates: {template_names}."
)
self.template_definitions.extend(template_definitions)
else:
raise exceptions.InvalidSyntax(
"Please set the properties 'template' and 'body' for the "
Expand Down
44 changes: 44 additions & 0 deletions tests/track/params_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,29 @@ def test_create_composable_index_template_from_track(self):
"composed_of": ["ct1", "ct2"],
}

def test_create_composable_index_template_from_track_wrong_filter(self):
t1 = track.IndexTemplate(
name="t1",
content={},
pattern="",
)
t2 = track.IndexTemplate(
name="t2",
content={},
pattern="",
)

with pytest.raises(exceptions.InvalidSyntax) as exc:
source = params.CreateComposableTemplateParamSource(
track=track.Track(name="unit-test", composable_templates=[t1, t2]),
params={
"template": "t3",
},
)
assert exc.value.args[0] == (
"Unknown template: t3. Available templates: t1, t2."
)

def test_create_or_merge(self):
content = params.CreateComposableTemplateParamSource._create_or_merge(
{"parent": {}},
Expand Down Expand Up @@ -2270,6 +2293,27 @@ def test_create_component_index_template_from_track(self):
}
}

def test_create_component_index_template_from_track_wrong_filter(self):
t1 = track.ComponentTemplate(
name="t1",
content={},
)
t2 = track.ComponentTemplate(
name="t2",
content={},
)

with pytest.raises(exceptions.InvalidSyntax) as exc:
source = params.CreateComponentTemplateParamSource(
track=track.Track(name="unit-test", component_templates=[t1, t2]),
params={
"template": "t3",
},
)
assert exc.value.args[0] == (
"Unknown template: t3. Available templates: t1, t2."
)


class TestDeleteComponentTemplateParamSource:
def test_delete_component_template_by_name(self):
Expand Down

0 comments on commit 2b0eb0c

Please sign in to comment.