From 19672715e09f90cd685a29cd5772a57fbac5ebbb Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Thu, 12 May 2011 01:41:48 +0200 Subject: [PATCH] Added example test for compound predicates with and macro --- .../test/clojure/org/jclouds/compute2_test.clj | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/compute/src/test/clojure/org/jclouds/compute2_test.clj b/compute/src/test/clojure/org/jclouds/compute2_test.clj index fae5dc73c4..d24cdf4bea 100644 --- a/compute/src/test/clojure/org/jclouds/compute2_test.clj +++ b/compute/src/test/clojure/org/jclouds/compute2_test.clj @@ -21,9 +21,9 @@ (:use [org.jclouds.compute2] :reload-all) (:use clojure.test) (:import - org.jclouds.compute.domain.OsFamily - clojure.contrib.condition.Condition)) - + org.jclouds.compute.domain.OsFamily + clojure.contrib.condition.Condition + java.net.InetAddress)) (defmacro with-private-vars [[ns fns] & tests] "Refers private fns from ns and runs tests in context. From users mailing @@ -75,6 +75,17 @@ list, Alan Dipert and MeikelBrandmeyer." (destroy-nodes-matching *compute* #(= (.getGroup %) "fred")) (is (terminated? (first (nodes-in-group *compute* "fred"))))) +(defn localhost? [node] + "Returns true if the localhost address is in the node's private ips" + (seq? (some #(= (InetAddress/getLocalHost) %) (private-ips node)))) + +(deftest compound-predicate-test + (is (create-node *compute* "my-group" (build-template *compute* {}))) + (is (= 0 (count (nodes-with-details-matching *compute* #(and (suspended? %) (not (localhost? %))))))) + (is (= 0 (count (nodes-with-details-matching *compute* #(and (suspended? %) (localhost? %)))))) + (is (= 0 (count (nodes-with-details-matching *compute* #(and (running? %) (localhost? %)))))) + (is (= 1 (count (nodes-with-details-matching *compute* #(and (running? %) (not (localhost? %)))))))) + (deftest build-template-test (let [service (compute-service "stub" "user" "password")] (testing "nullary"