[buildout]
extends = {{ nxdtest_instance }}
parts +=
  publish

[slap-configuration]
recipe = slapos.cookbook:slapconfiguration
computer = ${slap-connection:computer-id}
partition = ${slap-connection:partition-id}
url = ${slap-connection:server-url}
key = ${slap-connection:key-file}
cert = ${slap-connection:cert-file}

[download-source]
recipe = slapos.recipe.build:gitclone
git-executable = {{ git_location }}/bin/git

[slapos]
<= download-source
repository = {{ slapos_location }}

[directory]
recipe = slapos.cookbook:mkdirectory
bin = ${buildout:directory}/bin
etc = ${buildout:directory}/etc
var = ${buildout:directory}/var
test-working-dir = ${buildout:directory}/tmp
nxdtest-working-dir = ${:var}/nxdtest

[slapos-test-runner-nxdtest-environment.sh]
recipe = slapos.recipe.template:jinja2
rendered = ${directory:etc}/${:_buildout_section_name_}
template = inline:
  export PATH={{ buildout['bin-directory'] }}:{{ curl_location }}/bin:{{ faketime_location }}/bin:{{ openssl_location }}/bin:/usr/bin:/bin
  export SLAPOS_TEST_IPV4=${slap-configuration:ipv4-random}
  export SLAPOS_TEST_IPV6=${slap-configuration:ipv6-random}
  export SLAPOS_TEST_WORKING_DIR=${directory:test-working-dir}

[slapos-test-runner-dot-nxdtest]
recipe = slapos.recipe.template:jinja2
rendered = ${:workdir}/.nxdtest
workdir = ${directory:nxdtest-working-dir}
template = inline:
  {% for test in tests.splitlines() %}
    TestCase(
      {{ repr(test.split()[0]) }},
      [ {{ repr(interpreter) }}, '-m', 'unittest', 'discover', '-v'],
      cwd={{ repr(test.split()[1]) }},
      summaryf=UnitTest.summary,
    )
  {% endfor %}

[runTestSuite]
env.sh = ${slapos-test-runner-nxdtest-environment.sh:rendered}
workdir = ${slapos-test-runner-dot-nxdtest:workdir}

[slapos-local-development-environment.sh]
recipe = slapos.recipe.template:jinja2
rendered = ${directory:etc}/${:_buildout_section_name_}
template = inline:
  source ${slapos-test-runner-nxdtest-environment.sh:rendered}
  {% set shared_part_list = [] %}
  {% for shared_part in buildout['shared-part-list'].splitlines() -%}
    {% do shared_part_list.append(shared_part) %}
  {%- endfor %}
  export SLAPOS_TEST_SHARED_PART_LIST={{ os.pathsep.join(shared_part_list) }}
  echo "Environment loaded."
  echo "The embedded SlapOS is in $SLAPOS_TEST_WORKING_DIR"
  echo "To work on a test, execute:"
  echo "   SLAPOS_TEST_DEBUG=1 {{ interpreter }} -m unittest discover -v"
  echo "from a folder containing software release test."
  echo

[publish]
recipe = slapos.cookbook:publish
environment-script = ${slapos-local-development-environment.sh:rendered}
