 {exec}     = require "child_process"
 fs         = require "fs"
 {join}     = require "path"
+async      = require "async"
 {testCase} = require "nodeunit"
 
 Configuration = require "pow/configuration"

      mkdirp fixturePath("tmp"), ->
        proceed()

  "gatherApplicationRoots with non-existent root": (test) ->
    test.expect 2
    configuration = new Configuration root: fixturePath("tmp/pow")

        test.ok stat.isDirectory()
        test.done()

  "findApplicationRootForHost matches hostnames to application roots": (test) ->
    configuration   = new Configuration root: fixturePath("configuration")
    matchHostToRoot = (host, fixtureRoot) -> (proceed) ->
      configuration.findApplicationRootForHost host, (err, root) ->
        if fixtureRoot then test.same fixturePath(fixtureRoot), root
        else test.ok !root
        proceed()

    test.expect 8
    async.parallel [
      matchHostToRoot "directory.test",            "configuration/directory"
      matchHostToRoot "sub.directory.test",        "configuration/directory"
      matchHostToRoot "www.directory.test",        "configuration/www.directory"
      matchHostToRoot "asset0.www.directory.test", "configuration/www.directory"
      matchHostToRoot "symlink-to-directory.test", "apps/hello"
      matchHostToRoot "symlink-to-symlink.test",   "apps/hello"
      matchHostToRoot "directory"
      matchHostToRoot "nonexistent.test"
    ], test.done
