Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ftf_cli/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@
"required": ["primary"],
},
"metadata": Draft7Validator.META_SCHEMA,
"iac": {
"type": "object",
"properties": {
"validated_files": {
"type": "array",
"items": {"type": "string"}
}
},
"additionalProperties": True
},
},
"required": ["intent", "flavor", "version", "description", "spec", "clouds"],
}
Expand Down
69 changes: 69 additions & 0 deletions tests/test_utils_validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import pytest
import click
from ftf_cli.utils import check_no_array_or_invalid_pattern_in_spec, check_conflicting_ui_properties
import os
import tempfile
import yaml
from ftf_cli.utils import validate_yaml


def test_no_array_type_pass():
Expand Down Expand Up @@ -244,3 +248,68 @@ def test_pattern_properties_only_string_types_with_yaml_editor_pass():
}
# Should pass silently
check_conflicting_ui_properties(spec)


def test_facets_yaml_with_valid_iac_block():
data = {
"intent": "test",
"flavor": "default",
"version": "1.0",
"description": "desc",
"spec": {},
"clouds": ["aws"],
"iac": {
"validated_files": ["variables.tf", "tekton.tf"]
}
}
# Should pass validation
validate_yaml(data)


def test_facets_yaml_with_iac_not_object():
data = {
"intent": "test",
"flavor": "default",
"version": "1.0",
"description": "desc",
"spec": {},
"clouds": ["aws"],
"iac": "not-an-object"
}
with pytest.raises(click.UsageError) as excinfo:
validate_yaml(data)
assert "iac" in str(excinfo.value)


def test_facets_yaml_with_iac_validated_files_not_array():
data = {
"intent": "test",
"flavor": "default",
"version": "1.0",
"description": "desc",
"spec": {},
"clouds": ["aws"],
"iac": {
"validated_files": "not-an-array"
}
}
with pytest.raises(click.UsageError) as excinfo:
validate_yaml(data)
assert "validated_files" in str(excinfo.value)


def test_facets_yaml_with_iac_validated_files_array_of_non_strings():
data = {
"intent": "test",
"flavor": "default",
"version": "1.0",
"description": "desc",
"spec": {},
"clouds": ["aws"],
"iac": {
"validated_files": [1, 2, 3]
}
}
with pytest.raises(click.UsageError) as excinfo:
validate_yaml(data)
assert "validated_files" in str(excinfo.value)