Package: iac-test
iac-testA CLI tool to render and executeRobot Frameworktests usingJinjatemplating. Combining Robot's language agnostic syntax with the flexibility of Jinja templating allows dynamically rendering a set of test suites from the desired infrastructure state expressed in YAML syntax.$iac-test-h
Usage:iac-test[OPTIONS]ACLItooltorenderandexecuteRobotFrameworktestsusingJinjatemplating.

Options:--versionShowtheversionandexit.-v,--verbosityLVLEitherCRITICAL,ERROR,WARNING,INFOorDEBUG-d,--dataPATHPathtodataYAMLfiles.(env:IAC_TEST_DATA)[required]-t,--templatesDIRECTORYPathtotesttemplates.(env:IAC_TEST_TEMPLATES)[required]-f,--filtersDIRECTORYPathtoJinjafilters.(env:IAC_TEST_FILTERS)--testsDIRECTORYPathtoJinjatests.(env:IAC_TEST_TESTS)-o,--outputDIRECTORYPathtooutputdirectory.(env:IAC_TEST_OUTPUT)[required]-i,--includeTEXTSelectsthetestcasesbytag(include).(env:IAC_TEST_INCLUDE)-e,--excludeTEXTSelectsthetestcasesbytag(exclude).(env:IAC_TEST_EXCLUDE)--render-onlyOnlyrendertestswithoutexecutingthem.(env:IAC_TEST_RENDER_ONLY)--dry-runDryrunflag.Seerobotdryrunmode.(env:IAC_DRY_RUN)-h,--helpShowthismessageandexit.All data from the YAML files (--dataoption) will first be combined into a single data structure which is then provided as input to the templating process. Each template in the--templatespath will then be rendered and written to the--outputpath. If the--templatespath has subfolders, the folder structure will be retained when rendering the templates.After all templates have been renderedPabotwill execute all test suites in parallel and create a test report in the--outputpath. The--skiponfailure non-criticalargument will be used by default, meaning all failed tests with anon-criticaltag will show up as "skipped" instead of "failed" in the final test report.InstallationPython 3.7+ is required to installiac-test. Don't have Python 3.7 or later? SeePython 3 Installation & Setup Guide.iac-testcan be installed in a virtual environment usingpip:pipinstalliac-testThe following Robot libraries are installed withiac-test:RESTinstanceRequestsJSONLibraryAny other libraries can of course be added viapip.Ansible Vault SupportValues in YAML files can be encrypted usingAnsible Vault. This requires Ansible (ansible-vaultcommand) to be installed and the following two environment variables to be defined:export ANSIBLE_VAULT_ID=dev
export ANSIBLE_VAULT_PASSWORD=Password123ANSIBLE_VAULT_IDis optional, and if not defined will be omitted.Additional TagsReading Environment VariablesThe!envYAML tag can be used to read values from environment variables.root:name:!envVAR_NAMEExampledata.yamllocated in./datafolder:---root:children:-name:ABCparam:value-name:DEFparam:valuetest1.robotlocated in./templatesfolder:*** Settings ***
Documentation   Test1

*** Test Cases ***
{% for child in root.children | default([]) %}

Test {{ child.name }}
    Should Be Equal   {{ child.param }}   value
{% endfor %}After runningiac-testwith the following parameters:iac-test--data./data--templates./templates--output./testsThe following rendered Robot test suite can be found in the./testsfolder:*** Settings ***
Documentation   Test1

*** Test Cases ***

Test ABC
    Should Be Equal   value   value

Test DEF
    Should Be Equal   value   valueAs well as the test results and reports:$tree-L1tests
tests
├──log.html
├──output.xml
├──pabot_results
├──report.html
├──test1.robot
└──xunit.xmlCustom Jinja FiltersCustom Jinja filters can be used by providing a set of Python classes where each filter is implemented as a separateFilterclass in a.pyfile located in the--filterspath. The class must have a single attribute namedname, the filter name, and aclassmethod()namedfilterwhich has one or more arguments. A sample filter can be found below.classFilter:name="filter1"@classmethoddeffilter(cls,data):returnstr(data)+"_filtered"Custom Jinja TestsCustom Jinja tests can be used by providing a set of Python classes where each test is implemented as a separateTestclass in a.pyfile located in the--testspath. The class must have a single attribute namedname, the test name, and aclassmethod()namedtestwhich has one or more arguments. A sample test can be found below.classTest:name="test1"@classmethoddeftest(cls,data1,data2):returndata1==data2Rendering DirectivesSpecial rendering directives exist to render a single test suite per (YAML) list item. The directive can be added to the Robot template as a Jinja comment following this syntax:{# iterate_list <YAML_PATH_TO_LIST> <LIST_ITEM_ID> <JINJA_VARIABLE_NAME> #}After runningiac-testwith the data from the previousexampleand the following template:{# iterate_list root.children name child_name #}
*** Settings ***
Documentation   Test1

*** Test Cases ***
{% for child in root.children | default([]) %}
{% if child.name == child_name %}

Test {{ child.name }}
    Should Be Equal   {{ child.param }}   value
{% endif %}
{% endfor %}The following test suites will be rendered:$tree-L2tests
tests
├──ABC
│└──test1.robot
└──DEF└──test1.robotA similar directive exists to put the test suites in a common folder though with a unique filename.{# iterate_list_folder <YAML_PATH_TO_LIST> <LIST_ITEM_ID> <JINJA_VARIABLE_NAME> #}The following test suites will be rendered:$tree-L2tests
tests
└──test1├──ABC.robot└──DEF.robotSelect Test Cases By TagIt is possible to include and exclude test cases by tag names with the--includeand--excludeCLI options. These options are directly passed to the Pabot/Robot executor and are documentedhere.