 
 (fact "that an exception while waiting for load balancer health is an error"
       (wait-for-load-balancers-to-be-healthy {:attempt 1
-                                              :parameters wait-for-load-balancers-to-be-healthy-params}) => (contains {:status :error})
+                                              :parameters wait-for-load-balancers-to-be-healthy-params})
+      => (contains {:status :error})
       (provided
        (aws/auto-scaling-group-instances "asg" "environment" "region") =throws=> (ex-info "Busted" {})))
 
 (fact "that waiting for load balancer health errors if too many unsuccessful attempts have been made"
       (wait-for-load-balancers-to-be-healthy {:attempt 50
-                                              :parameters wait-for-load-balancers-to-be-healthy-params}) => (contains {:status :error})
+                                              :parameters wait-for-load-balancers-to-be-healthy-params})
+      => (contains {:status :error})
       (provided
        (aws/auto-scaling-group-instances "asg" "environment" "region") => [{:instance-id "id-1"} {:instance-id "id-2"}]
        (aws/load-balancer-health "environment" "region" "lb-1") => [{:instance-id "id-1" :state "NotInService"}


(fact "that waiting for load balancer health of no load balancers skips it"
      (wait-for-load-balancers-to-be-healthy {:attempt 1
                                              :parameters (assoc-in wait-for-load-balancers-to-be-healthy-params [:new-state :tyranitar :deployment-params :selected-load-balancers] [])}) => (contains {:status :success}))

(fact "that waiting for load balancer health of auto scaling group with no instances is successful"
      (wait-for-load-balancers-to-be-healthy {:attempt 1
                                              :parameters wait-for-load-balancers-to-be-healthy-params}) => (contains {:status :success})
      (provided
       (aws/auto-scaling-group-instances "asg" "environment" "region") => []))

(fact "that waiting for load balancer health of auto scaling group with no healthy instances retries"
      (wait-for-load-balancers-to-be-healthy {:attempt 1
                                              :parameters wait-for-load-balancers-to-be-healthy-params}) => {:status :retry
                      :backoff-ms 10000}
      (provided
       (aws/auto-scaling-group-instances "asg" "environment" "region") => [{:instance-id "id-1"}]
       (aws/load-balancer-health "environment" "region" "lb-1") => [{:instance-id "id-1" :state "NotInService"}]

                           :deployment-params {:min 2}}}})

(fact "that healthchecks are skipped if told to"
      (wait-for-instances-to-be-healthy {:attempt 1 :parameters (assoc-in wait-for-instances-to-be-healthy-params [:new-state :tyranitar :application-properties :service.healthcheck.skip] true)})
      => (contains {:status :success}))

(fact "that checking the health when min is zero skips the process"
      (wait-for-instances-to-be-healthy {:attempt 1 :parameters (assoc-in wait-for-instances-to-be-healthy-params [:new-state :tyranitar :deployment-params :min] 0)})
      => (contains {:status :success}))

(fact "that getting no instances back when min is greater than zero retries"
      (wait-for-instances-to-be-healthy {:attempt 1 :parameters wait-for-instances-to-be-healthy-params})
      => {:status :retry
          :backoff-ms 10000}
      (provided
       (aws/auto-scaling-group-instances "asg" "environment" "region") => []))

(fact "that getting one healthy instance when the minimum is two retries"
      (wait-for-instances-to-be-healthy {:attempt 1 :parameters wait-for-instances-to-be-healthy-params})
      => {:status :retry
          :backoff-ms 10000}
      (provided
       (aws/auto-scaling-group-instances "asg" "environment" "region") => [{:instance-id "i-1"}
                                                                           {:instance-id "i-2"}]
