[buildout]
extends = ${nxdtest-instance.cfg:rendered}
parts =
  runTestSuite
  publish

eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true

[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}

[create-directory]
recipe = slapos.cookbook:mkdirectory
bin = $${buildout:directory}/bin
etc = $${buildout:directory}/etc
services = $${:etc}/run
srv = $${buildout:directory}/srv
var = $${buildout:directory}/var
nxdtest-working-dir = $${:var}/nxdtest

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

[kedifa]
<= download-source
repository = ${kedifa-repository:location}

[caucase]
<= download-source
repository = ${caucase-repository:location}

[slapos.libnetworkcache]
<= download-source
repository = ${slapos.libnetworkcache-repository:location}

[erp5.util]
<= download-source
repository = ${erp5.util-repository:location}

[slapos.cookbook]
<= download-source
repository = ${slapos.cookbook-repository:location}

[slapos.core]
<= download-source
repository = ${slapos.core-repository:location}

[slapos.recipe.build]
<= download-source
repository = ${slapos.recipe.build-repository:location}

[slapos.recipe.cmmi]
<= download-source
repository = ${slapos.recipe.cmmi-repository:location}

[slapos.recipe.template]
<= download-source
repository = ${slapos.recipe.template-repository:location}

[slapos.toolbox]
<= download-source
repository = ${slapos.toolbox-repository:location}

[slapos.rebootstrap]
<= download-source
repository = ${slapos.rebootstrap-repository:location}

[rubygemsrecipe]
<= download-source
repository = ${rubygemsrecipe-repository:location}


[slapos-test-runner-nxdtest-environment.sh]
recipe = slapos.recipe.template:jinja2
rendered = $${create-directory:etc}/$${:_buildout_section_name_}
template = inline:
  export PATH=${coreutils:location}/bin:${curl:location}/bin:${openssl:location}/bin:${git:location}/bin:${libxslt:location}/bin:${socat:location}/bin:${lmsensors:location}/bin:${rsync:location}/bin/:${buildout:bin-directory}:$PATH
  export SLAPOS_TEST_IPV4=$${slap-configuration:ipv4-random}
  export SLAPOS_TEST_IPV6=$${slap-configuration:ipv6-random}


[slapos-test-runner-dot-nxdtest]
recipe = slapos.recipe.template:jinja2
rendered = $${:workdir}/.nxdtest
workdir = $${create-directory:nxdtest-working-dir}

template = inline:
  TestCase(
      "kedifa",
      ['python', '-m', 'unittest', 'discover', '-v'],
      cwd="""$${kedifa:location}""",
      summaryf=UnitTest.summary,
  )
  TestCase(
      "caucase",
      # XXX caucase uses 2to3 dynamically in setup.py, so it only supports
      # runnning tests with python setup.py test
      ['python', 'setup.py', 'test'],
      cwd="""$${caucase:location}""",
      summaryf=UnitTest.summary,
  )
  TestCase(
      "erp5.util",
      ['python', '-m', 'unittest', 'discover', '-v', '--start', 'erp5/tests/'],
      cwd="""$${erp5.util:location}""",
      summaryf=UnitTest.summary,
  )
  TestCase(
      "slapos.cookbook",
      # slapos/test contain both tests for recipes and tests for
      # json schemas, we only care about recipe tests here, json
      # schemas are tested in software/slapos-sr-testing
      ['python', '-m', 'unittest', 'discover', '-v', '--start', 'slapos/test/recipe'],
      cwd="""$${slapos.cookbook:location}""",
      summaryf=UnitTest.summary,
  )
  TestCase(
      "slapos.core",
      # ['python', '-m', 'unittest', 'discover', '-v'],
      # XXX some test fail when running with unittest (slapos*.cfg.example
      # files cannot be found with pkg_resources.resource_string), so we keep
      # using setup.py test for now.
      ['python', 'setup.py', 'test'],
      cwd="""$${slapos.core:location}""",
      summaryf=UnitTest.summary,
  )
  TestCase(
      "slapos.recipe.build",
      ['python', '-m', 'unittest', 'discover', '-v'],
      cwd="""$${slapos.recipe.build:location}""",
      summaryf=UnitTest.summary,
  )
  TestCase(
      "slapos.recipe.cmmi",
      ['python', '-m', 'unittest', 'discover', '-v'],
      cwd="""$${slapos.recipe.cmmi:location}""",
      summaryf=UnitTest.summary,
  )
  TestCase(
      "slapos.recipe.template",
      # ['python', '-m', 'unittest', 'slapos.recipe.template.tests.test_suite'],
      # XXX some test fail when running with unittest, so we keep using setup.py test
      ['python', 'setup.py', 'test'],
      cwd="""$${slapos.recipe.template:location}""",
      summaryf=UnitTest.summary,
  )
  TestCase(
      "slapos.toolbox",
      # ['python', '-m', 'unittest', 'discover', '-v'],
      # XXX We can not just run unittest discover here, since slapos/lamp
      # imports MySQLDb and we currently don't have installed
      # slapos.toolbox[lampconfigure] and on python3 discovery make a
      # failing test for this import error.
      # Currently slapos/lamp is not tested, but if it it is still used,
      # the TODO seem to also install slapos.toolbox[lampconfigure] here.
      ['python', '-m', 'unittest', 'discover', '-v', '--start', 'slapos/test', '--top-level-directory', '.'],
      cwd="""$${slapos.toolbox:location}""",
      summaryf=UnitTest.summary,
  )
  TestCase(
      "slapos.libnetworkcache",
      ['python', '-m', 'unittest', '-v', 'slapos.libnetworkcachetests'],
      cwd="""$${slapos.libnetworkcache:location}""",
      summaryf=UnitTest.summary,
  )
  TestCase(
      "slapos.rebootstrap",
      ['python', '-m', 'unittest', '-v', 'slapos.rebootstrap.tests.test_suite'],
      cwd="""$${slapos.rebootstrap:location}""",
      summaryf=UnitTest.summary,
  )
  TestCase(
      "rubygemsrecipe",
      ['python', '-m', 'unittest', 'discover', '-v'],
      cwd="""$${rubygemsrecipe:location}""",
      summaryf=UnitTest.summary,
  )

[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 = $${create-directory:etc}/$${:_buildout_section_name_}
template = inline:
  source $${slapos-test-runner-nxdtest-environment.sh:rendered}
  echo "Environment loaded."
  echo "To work on a test, execute:"
  echo "   $${runTestSuite:wrapper-path} -k test_name"
  echo "replacing test_name by the name of the test."
  echo

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