(ns matross.test.helper
  "Helper functions for writing and running tests"
  (:require [me.raynes.conch :refer [with-programs]]
            [matross.connections.ssh :refer [translate-ssh-config ssh-connection]]
            [matross.connections.core :refer [connect disconnect]]))

(defn get-available-vms []
  (with-programs [vagrant grep cut]
    (cut "-f1" "-d "
         (vagrant "status" {:seq true})
         {:seq true})))

(def vagrant-test-connection
  (memoize (fn [] (translate-ssh-config (slurp (System/getenv "TEST_SSH_CONF"))))))

(defmacro task-tests
  "Evaluate the body against the test vm connection, exposed as conn"
  [conn & body]

  `(let [~conn (ssh-connection (vagrant-test-connection))]
     (connect ~conn)
     ~@body
     (disconnect ~conn)))

(ns matross.test.helper
  "Helper functions for writing and running tests"
  (:require [me.raynes.conch :refer [with-programs]]
            [matross.connections.ssh :refer [translate-ssh-config ssh-connection]]
            [matross.connections.debug :refer [debug-connection]]
            [matross.connections.core :refer [connect disconnect]]))

(defn get-available-vms []
  (with-programs [vagrant grep cut]
    (cut "-f1" "-d "
         (vagrant "status" {:seq true})
         {:seq true})))

(def vagrant-test-connection
  (memoize (fn [] (translate-ssh-config (slurp (System/getenv "TEST_SSH_CONF"))))))

(defn test-connection []
  (let [conn (ssh-connection (vagrant-test-connection))]
    (if-let [debug (System/getenv "TEST_DEBUG")]
      (debug-connection conn)
      conn)))

(defmacro task-tests
  "Evaluate the body against the test vm connection, exposed as conn"
  [conn & body]

  `(let [~conn (test-connection)]
     (connect ~conn)
     ~@body
     (disconnect ~conn)))

Allow debug output during tests.
Allow debug output during tests.

if the env var TEST_DEBUG is set, debug output will be enabled during
the test runs.

matross/matross,matross/matross