             (testing order
               (let [expected (raw-expected-resource-events (select-values expected-events) basic4)
                     actual   (:result (raw-resource-events-query-result
-                                        version
-                                        [">" "timestamp" 0]
-                                        {:order-by [[:timestamp order]]}))]
+                                       version
+                                       [">" "timestamp" 0]
+                                       {:order-by [[:timestamp order]]}))]
                 (is (= actual expected))))))
 
         (testing "multiple fields"

      (testing "filters (such as status) should be applied *after* the distinct list of most recent events has been built up"
        (let [expected  #{}
              actual    (resource-events-query-result
                          version
                          ["and" ["=" "certname" "foo.local"]
                                 ["=" "status" "success"]
                                 ["=" "resource-title" "notify, yar"]]
                          {} {:distinct-resources? true
                              :distinct-start-time (to-timestamp 0)
                              :distinct-end-time   (to-timestamp (now))})]
          (is (= (count expected) (count actual)))
          (is (= actual expected))))))

  (deftest paging-results
    (let [basic4        (store-example-report! (:basic4 reports) (now))
          events        (get-in reports [:basic4 :resource-events])
          event-count   (count events)
          select-values #(reverse (kitchensink/select-values (get-events-map (:basic4 reports)) %))]

      (testing "include total results count"
        (let [actual (:count (raw-resource-events-query-result version [">" "timestamp" 0] {:count? true}))]
          (is (= actual event-count))))

                :params  ["blah"]})))
      (testing "should fail with an invalid equality query"
        (is (thrown-with-msg?
             IllegalArgumentException #"foo is not a queryable object for resource events"
             (query/compile-term ops ["=" "foo" "foo"]))))
      (testing "should successfully compile valid inequality queries"
        (let [start-time  "2011-01-01T12:00:01-03:00"
              end-time    "2011-01-01T12:00:03-03:00"]
          (is (= (query/compile-term ops [">" "timestamp" start-time])
                 {:where   "resource_events.timestamp > ?"
                  :params  [(to-timestamp start-time)]}))
          (is (= (query/compile-term ops ["<" "timestamp" end-time])
                 {:where   "resource_events.timestamp < ?"
                  :params  [(to-timestamp end-time)]}))
          (is (= (query/compile-term ops
                                     ["and" [">=" "timestamp" start-time] ["<=" "timestamp" end-time]])
                 {:where   "(resource_events.timestamp >= ?) AND (resource_events.timestamp <= ?)"
                  :params  [(to-timestamp start-time) (to-timestamp end-time)]}))))
      (testing "should fail with invalid inequality queries"
        (is (thrown-with-msg?
             IllegalArgumentException #"> requires exactly two arguments"
             (query/compile-term ops [">" "timestamp"])))
        (is (thrown-with-msg?
             IllegalArgumentException #"'foo' is not a valid timestamp value"
             (query/compile-term ops [">" "timestamp" "foo"])))
        (is (thrown-with-msg?
             IllegalArgumentException #"> operator does not support object 'resource_type'"
             (query/compile-term ops [">" "resource_type" "foo"])))))))

(deftest resource-event-queries
  (let [basic             (store-example-report! (:basic reports) (now))
        report-hash       (:hash basic)
        basic-events      (get-in reports [:basic :resource-events])
        basic-events-map  (get-events-map (:basic reports))]
    (doseq [version [:v3 :v4]]
      (testing "resource event retrieval by report"
        (testing "should return the list of resource events for a given report hash"
          (let [expected  (expected-resource-events basic-events basic)
