Commit 6a19458f authored by Andrew Roetker's avatar Andrew Roetker

(PDB-1948) Use wire-v6 of reports in our testutils

This commit moves all of our testutils to use either the query-v4 format
of reports or the wire-v6 format of reports and tears down anything
thats stands in the way of this goal.
parent 2e0d990b
......@@ -160,8 +160,7 @@
"start_time" (time/minus stamp (time/seconds 10))
"end_time" (time/minus stamp (time/seconds 5))
"producer_timestamp" stamp)
clojure.walk/keywordize-keys
reports/sanitize-report))
clojure.walk/keywordize-keys))
(defn randomize-map-leaf
"Randomizes a fact leaf."
......
(ns puppetlabs.puppetdb.report.utils
"Report generation and manipulation
A suite of functions that aid in constructing random reports, or
randomly modifying existing reports"
(:require [puppetlabs.puppetdb.random :refer [random-string random-resource-event]]))
(defn add-random-event-to-report
"Add a randomly-generated event to an existing report."
[{:keys [resource_events] :as report}]
(let [new-event (random-resource-event)]
(assoc report :resource_events (conj resource_events new-event))))
(defn mod-event-in-report
"Randomly select a resource event in an existing report, and randomly modify
its metadata."
[{:keys [resource_events] :as report}]
(let [i (rand-int (count resource_events))
modified-event (-> (resource_events i)
(assoc :timestamp (random-string))
(assoc :status (random-string))
(assoc :old_value (random-string))
(assoc :new_value (random-string))
(assoc :message (random-string)))]
(assoc report :resource_events (assoc resource_events i modified-event))))
(defn remove-random-event-from-report
"Randomly select an event from an existing report and remove it."
[{:keys [resource_events] :as report}]
(let [len (count resource_events)
i (rand-int len)]
(assoc report :resource_events
(concat (subvec resource_events 0 i)
(subvec resource_events (inc i) len)))))
......@@ -209,25 +209,6 @@
(defn reports-query->wire-v6 [reports]
(map report-query->wire-v6 reports))
(pls/defn-validated sanitize-events :- [event-wireformat-schema]
[events]
(for [event events]
(pls/strip-unknown-keys event-wireformat-schema event)))
(pls/defn-validated sanitize-resources :- [resource-wireformat-schema]
[resources]
(for [resource resources]
(-> (pls/strip-unknown-keys resource-wireformat-schema resource)
(update :events sanitize-events))))
(pls/defn-validated sanitize-report :- report-wireformat-schema
"This function takes a report and sanitizes it, ensuring only valid data
is left over."
[payload]
(as-> payload $
(pls/strip-unknown-keys report-wireformat-schema $)
(update $ :resources sanitize-resources)))
(defn- resource->skipped-resource-events
"Fabricate a skipped resource-event"
[resource]
......
......@@ -25,13 +25,12 @@
(is (empty? (get-nodes)))
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace catalog" 6 example-catalog)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 5 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 6 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace facts" 4 example-facts)
(is (= (tuc/munge-catalog example-catalog)
(tuc/munge-catalog (get-catalogs example-certname))))
(is (= (tur/munge-report example-report)
(tur/munge-report (get-reports example-certname))))
(is (= [example-report] (get-reports example-certname)))
(is (= (tuf/munge-facts example-facts)
(tuf/munge-facts (get-factsets example-certname))))
......@@ -75,13 +74,12 @@
(is (empty? (get-nodes)))
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace catalog" 6 example-catalog)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 5 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 6 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace facts" 4 example-facts)
(is (= (tuc/munge-catalog example-catalog)
(tuc/munge-catalog (get-catalogs example-certname))))
(is (= (tur/munge-report example-report)
(tur/munge-report (get-reports example-certname))))
(is (= [example-report] (get-reports example-certname)))
(is (= (tuf/munge-facts example-facts)
(tuf/munge-facts (get-factsets example-certname))))
......@@ -125,13 +123,12 @@
(is (empty? (get-nodes)))
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace catalog" 6 example-catalog)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 5 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 6 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace facts" 4 example-facts)
(is (= (tuc/munge-catalog example-catalog)
(tuc/munge-catalog (get-catalogs example-certname))))
(is (= (tur/munge-report example-report)
(tur/munge-report (get-reports example-certname))))
(is (= [example-report] (get-reports example-certname)))
(is (= (tuf/munge-facts example-facts)
(tuf/munge-facts (get-factsets example-certname))))
......
......@@ -28,13 +28,12 @@
(is (empty? (get-nodes)))
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace catalog" 6 example-catalog)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 5 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 6 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace facts" 4 example-facts)
(is (= (tuc/munge-catalog example-catalog)
(tuc/munge-catalog (get-catalogs example-certname))))
(is (= (tur/munge-report example-report)
(tur/munge-report (get-reports example-certname))))
(is (= [example-report] (get-reports example-certname)))
(is (= (tuf/munge-facts example-facts)
(tuf/munge-facts (get-factsets example-certname))))
......@@ -58,8 +57,7 @@
(is (= (tuc/munge-catalog example-catalog)
(tuc/munge-catalog (get-catalogs example-certname))))
(is (= (tur/munge-report example-report)
(tur/munge-report (get-reports example-certname))))
(is (= [example-report] (get-reports example-certname)))
(is (= (tuf/munge-facts example-facts)
(tuf/munge-facts (get-factsets example-certname))))))))
......@@ -73,14 +71,13 @@
(is (empty? (get-nodes)))
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace catalog" 6 example-catalog)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 5 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 6 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace facts" 4 example-facts)
(is (= (tuc/munge-catalog example-catalog)
(tuc/munge-catalog (get-catalogs example-certname))))
(is (= (tur/munge-report example-report)
(tur/munge-report (get-reports example-certname))))
(is (= [example-report] (get-reports example-certname)))
(is (= (tuf/munge-facts example-facts)
(tuf/munge-facts (get-factsets example-certname))))
......
......@@ -24,13 +24,12 @@
(is (empty? (get-nodes)))
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace catalog" 6 example-catalog)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 5 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "store report" 6 example-report)
(svc-utils/sync-command-post (svc-utils/pdb-cmd-url) "replace facts" 4 example-facts)
(is (= (tuc/munge-catalog example-catalog)
(tuc/munge-catalog (get-catalogs example-certname))))
(is (= (tur/munge-report example-report)
(tur/munge-report (get-reports example-certname))))
(is (= [example-report] (get-reports example-certname)))
(is (= (tuf/munge-facts example-facts)
(tuf/munge-facts (get-factsets example-certname))))
......@@ -52,8 +51,7 @@
(is (= (tuc/munge-catalog example-catalog)
(tuc/munge-catalog (get-catalogs example-certname))))
(is (= (tur/munge-report example-report)
(tur/munge-report (get-reports example-certname))))
(is (= [example-report] (get-reports example-certname)))
(is (= (tuf/munge-facts example-facts)
(tuf/munge-facts (get-factsets example-certname))))))))
......
......@@ -18,7 +18,6 @@
[puppetlabs.puppetdb.fixtures :refer :all]
[puppetlabs.puppetdb.jdbc :refer [query-to-vec] :as jdbc]
[puppetlabs.puppetdb.examples :refer :all]
[puppetlabs.puppetdb.testutils.reports :refer [munge-example-report-for-storage]]
[puppetlabs.puppetdb.testutils.services :as svc-utils]
[puppetlabs.puppetdb.command.constants :refer [command-names]]
[clj-time.coerce
......@@ -1207,7 +1206,7 @@
(def v5-report
(-> (:basic report-examples/reports)
(assoc :environment "DEV")
munge-example-report-for-storage))
reports/report-query->wire-v5))
(def v4-report
(-> v5-report
......
......@@ -3,7 +3,7 @@
[puppetlabs.puppetdb.http :as http]
[puppetlabs.puppetdb.scf.storage :as scf-store]
[cheshire.core :as json]
[puppetlabs.puppetdb.testutils.events :refer [http-expected-resource-events]]
[puppetlabs.puppetdb.testutils.events :refer [expected-resource-events]]
[flatland.ordered.map :as omap]
[puppetlabs.puppetdb.examples :refer [catalogs]]
[clj-time.core :refer [ago now seconds]]
......@@ -71,7 +71,7 @@
(let [basic-report (:basic reports)
basic (store-example-report! basic-report (now))
basic-events (:resource_events basic-report)
basic-events (get-in basic-report [:resource_events :data])
basic-events-map (enumerated-resource-events-map basic-events)
report-hash (:hash basic)]
......@@ -80,7 +80,7 @@
(testing "should return the list of resource events for a given report hash"
(let [response (query-result method endpoint ["=" "report" report-hash]
{} munge-event-values)
expected (http-expected-resource-events version basic-events basic)]
expected (expected-resource-events basic-events basic)]
(is (= response expected))))
;; NOTE: more exhaustive testing for these queries can be found in
......@@ -92,8 +92,7 @@
(testing "should support single term timestamp queries"
(let [response (query-result method endpoint ["<" "timestamp" end_time]
{} munge-event-values)
expected (http-expected-resource-events
version
expected (expected-resource-events
(kitchensink/select-values basic-events-map [0 2])
basic)]
(is (= response expected))))
......@@ -102,8 +101,7 @@
(let [response (query-result method endpoint ["and" [">" "timestamp" start_time]
["<" "timestamp" end_time]]
{} munge-event-values)
expected (http-expected-resource-events
version
expected (expected-resource-events
(kitchensink/select-values basic-events-map [2])
basic)]
(is (= response expected))))))
......@@ -129,8 +127,7 @@
["=" "status" "skipped"]
["<" "timestamp" "2011-01-01T12:00:02-03:00"]] [0 2]]]]
(let [response (query-result method endpoint query {} munge-event-values)
expected (http-expected-resource-events
version
expected (expected-resource-events
(kitchensink/select-values basic-events-map matches)
basic)]
(is (= response expected)))))
......@@ -182,15 +179,14 @@
:include_total count?
:params {:order_by (json/generate-string [{"field" "status"}])}})]
(is (= (count basic-events) (count results)))
(is (= (http-expected-resource-events
version
(is (= (expected-resource-events
basic-events
basic)
(set (munge-event-values results)))))))
(testing "order_by field names"
(testing "should accept underscores"
(let [expected (http-expected-resource-events version basic-events basic)
(let [expected (expected-resource-events basic-events basic)
{:keys [status body]} (query-response
method endpoint [">" "timestamp" 0]
{:order_by (vector-param method [{:field "resource_title"}])})]
......@@ -210,10 +206,10 @@
method [:get :post]]
(let [basic (store-example-report! (:basic reports) (now))
basic-events (get-in reports [:basic :resource_events])
basic-events (get-in reports [:basic :resource_events :data])
basic3 (store-example-report! (:basic3 reports) (now))
basic3-events (get-in reports [:basic3 :resource_events])]
basic3-events (get-in reports [:basic3 :resource_events :data])]
(testing "should return an error if the caller passes :distinct_resources without timestamps"
(let [response (query-response method endpoint ["=" "certname" "foo.local"]
......@@ -247,7 +243,7 @@
body))))
(testing "should return only one event for a given resource"
(let [expected (http-expected-resource-events version basic3-events basic3)
(let [expected (expected-resource-events basic3-events basic3)
response (query-result method endpoint ["=" "certname" "foo.local"]
{:distinct_resources true
:distinct_start_time 0
......@@ -256,7 +252,7 @@
(is (= response expected))))
(testing "distinct params should work with include_total"
(let [expected (http-expected-resource-events version basic3-events basic3)
(let [expected (expected-resource-events basic3-events basic3)
response (query-result method endpoint ["=" "certname" "foo.local"]
{:distinct_resources true
:distinct_start_time 0
......@@ -266,7 +262,7 @@
(is (= response expected))))
(testing "events should be contained within distinct resource timestamps"
(let [expected (http-expected-resource-events version basic-events basic)
(let [expected (expected-resource-events basic-events basic)
response (query-result method endpoint ["=" "certname" "foo.local"]
{:distinct_resources true
:distinct_start_time 0
......@@ -290,28 +286,28 @@
method [:get :post]]
(let [basic (store-example-report! (:basic reports) (now))
basic-events (get-in reports [:basic :resource_events])
basic-events (get-in reports [:basic :resource_events :data])
basic3 (store-example-report! (:basic3 reports) (now))
basic3-events (get-in reports [:basic3 :resource_events])]
basic3-events (get-in reports [:basic3 :resource_events :data])]
(testing "query by report start time"
(let [expected (http-expected-resource-events version basic-events basic)
(let [expected (expected-resource-events basic-events basic)
response (query-result method endpoint
["<" "run_start_time" "2011-01-02T00:00:00-03:00"]
{} munge-event-values)]
(is (= response expected))))
(testing "query by report end time"
(let [expected (http-expected-resource-events version basic3-events basic3)
(let [expected (expected-resource-events basic3-events basic3)
response (query-result method endpoint
[">" "run_end_time" "2011-01-02T00:00:00-03:00"]
{} munge-event-values)]
(is (= response expected))))
(testing "query without a query parameter"
(let [expected (clj-set/union (http-expected-resource-events version basic3-events basic3)
(http-expected-resource-events version basic-events basic))
(let [expected (clj-set/union (expected-resource-events basic3-events basic3)
(expected-resource-events basic-events basic))
response (query-result method endpoint nil {} munge-event-values)]
(is (= response expected))))
......@@ -329,9 +325,9 @@
(let [test-start-time (-> 1 seconds ago)
basic (store-example-report! (:basic reports) (now))
basic-events (get-in reports [:basic :resource_events])]
basic-events (get-in reports [:basic :resource_events :data])]
(testing "query by report receive time"
(let [expected (http-expected-resource-events version basic-events basic)
(let [expected (expected-resource-events basic-events basic)
response (query-result method endpoint
[">" "report_receive_time" (to-string test-start-time)]
{} munge-event-values)]
......
......@@ -3,15 +3,13 @@
[puppetlabs.puppetdb.examples.reports :refer :all]
[puppetlabs.puppetdb.reports :refer :all]
[schema.core :as s]
[puppetlabs.puppetdb.testutils.reports :refer [munge-example-report-for-storage]]
[com.rpl.specter :as sp]
[puppetlabs.puppetdb.utils :as utils]
[clj-time.core :refer [now]]
[schema.core :as s]))
(let [report (-> (:basic reports)
munge-example-report-for-storage
wire-v5->wire-v6)]
report-query->wire-v6)]
(deftest test-validate
......@@ -28,11 +26,6 @@
RuntimeException #":timestamp \(not \(datetime\? \"foo\"\)\)"
(s/validate report-wireformat-schema (assoc-in report [:resources 0 :timestamp] "foo")))))))
(deftest test-sanitize-report
(testing "no action on valid reports"
(let [test-data (:basic reports)]
(= (sanitize-report (wire-v5->wire-v6 test-data)) test-data))))
(defn underscore->dash-report-keys [m]
(->> m
utils/underscore->dash-keys
......@@ -42,12 +35,12 @@
(def v4-example-report
(-> reports
:basic
munge-example-report-for-storage
report-query->wire-v5
underscore->dash-report-keys
(dissoc :logs :metrics :noop :producer-timestamp)))
(deftest test-v5-conversion
(let [v5-report (-> reports :basic munge-example-report-for-storage)
(let [v5-report (-> reports :basic report-query->wire-v5)
v6-report (wire-v5->wire-v6 v5-report)]
(is (s/validate report-v5-wireformat-schema v5-report))
......
(ns puppetlabs.puppetdb.scf.hash-test
(:require [clojure.test :refer :all]
[puppetlabs.puppetdb.scf.hash :refer :all]
[puppetlabs.puppetdb.scf.storage :refer [normalize-report]]
[puppetlabs.puppetdb.random :as random]
[clojure.math.combinatorics :refer (combinations subsets)]
[puppetlabs.puppetdb.examples :refer [catalogs]]
[puppetlabs.puppetdb.catalog.utils :as catutils]
[puppetlabs.puppetdb.examples.reports :refer [reports]]
[puppetlabs.puppetdb.report.utils :as reputils]))
[puppetlabs.puppetdb.reports :as reports]))
(deftest hash-computation
(testing "generic-identity-*"
......@@ -209,13 +210,19 @@
(str catalog "\n has hash: " hash "\n and \n" tweaked-catalog "\n has hash: " tweaked-hash))))))
(deftest report-dedupe
(let [report (:basic reports)
report-hash (report-identity-hash report)]
(let [report-query->hash (comp report-identity-hash
normalize-report
reports/report-query->wire-v6)
report (:basic reports)
report2-events (get-in reports [:basic4 :resource_events :data])
report2 (assoc-in report [:resource_events :data] report2-events)
report-hash (report-query->hash report)
report2-hash (report-query->hash report2)
report3-hash (report-query->hash
(update-in report [:resource_events :data] rest))]
(testing "Reports with the same metadata but different events should have different hashes"
(is (= report-hash (report-identity-hash report)))
(is (not= report-hash (report-identity-hash (reputils/add-random-event-to-report report))))
(is (not= report-hash (report-identity-hash (reputils/mod-event-in-report report))))
(is (not= report-hash (report-identity-hash (reputils/remove-random-event-from-report report)))))
(is (not= report-hash report2-hash))
(is (not= report-hash report3-hash)))
(testing "Reports with different metadata but the same events should have different hashes"
(let [mod-report-fns [#(assoc % :certname (str (:certname %) "foo"))
......
......@@ -1304,7 +1304,7 @@
(let [timestamp (now)
{:keys [certname] :as report} (:basic reports)
report-hash (-> report
report/wire-v5->wire-v6
report/report-query->wire-v6
normalize-report
shash/report-identity-hash)]
......@@ -1358,7 +1358,7 @@
(testing "should store reports"
(let [env-id (ensure-environment "DEV")]
(store-example-report! (assoc report :resource_events []) timestamp)
(store-example-report! (assoc-in report [:resource_events :data] []) timestamp)
(is (= (query-to-vec ["SELECT certname FROM reports"])
[{:certname (:certname report)}]))
......@@ -1391,33 +1391,32 @@
(deftest report-cleanup
(testing "should delete reports older than the specified age"
(let [report1 (assoc report
:end_time (to-string (-> 5 days ago))
:producer_timestamp (to-string (-> 5 days ago)))
report1-hash (:hash (store-example-report! report1 timestamp))
report2 (assoc report
:end_time (to-string (-> 2 days ago))
:producer_timestamp (to-string (-> 2 days ago)))
report2-hash (:hash (store-example-report! report2 timestamp))
certname (:certname report1)
_ (delete-reports-older-than! (-> 3 days ago))
expected (map #(dissoc % :resource_events :metrics :logs)
(expected-reports [(assoc report2 :hash report2-hash)]))
actual (->> (reports-query-result :v4 ["=" "certname" certname])
(map #(dissoc % :resource_events :metrics :logs)))]
(is (= expected actual)))))
(let [report1 (assoc report
:certname "foo"
:end_time (to-string (-> 5 days ago))
:producer_timestamp (to-string (-> 5 days ago)))
report2 (assoc report
:certname "bar"
:end_time (to-string (-> 2 days ago))
:producer_timestamp (to-string (-> 2 days ago)))]
(store-example-report! report1 timestamp)
(store-example-report! report2 timestamp)
(delete-reports-older-than! (-> 3 days ago))
(is (= (query-to-vec ["SELECT certname FROM reports"])
[{:certname "bar"}])))))
(deftest resource-events-cleanup
(testing "should delete all events for reports older than the specified age"
(let [report1 (assoc report :end_time (to-string (-> 5 days ago)))
report1-hash (:hash (store-example-report! report1 timestamp))
report2 (assoc report :end_time (to-string (-> 2 days ago)))
report2-hash (:hash (store-example-report! report2 timestamp))
certname (:certname report1)
_ (delete-reports-older-than! (-> 3 days ago))
expected #{}
actual (set (query-resource-events :latest ["=" "report" report1-hash] {}))]
(is (= expected actual))))))
(let [report1 (assoc report :end_time (to-string (-> 5 days ago)))
report1-hash (:hash (store-example-report! report1 timestamp))
report2 (assoc report :end_time (to-string (-> 2 days ago)))]
(store-example-report! report2 timestamp)
(delete-reports-older-than! (-> 3 days ago))
(is (= #{}
(set (query-resource-events :latest ["=" "report" report1-hash] {}))))))))
(defn with-db-version [db version f]
(with-redefs [sutils/db-metadata (delay {:database db
......
......@@ -2,6 +2,7 @@
(:require [clj-time.coerce :as time-coerce]
[clj-time.core :as time]
[clojure.string :as str]
[clojure.walk :refer [keywordize-keys stringify-keys]]
[puppetlabs.kitchensink.core :as kitchensink]
[puppetlabs.puppetdb.utils :as utils]
[puppetlabs.puppetdb.catalogs :as catalogs]
......@@ -12,7 +13,8 @@
[puppetlabs.puppetdb.testutils.reports :as tur]
[puppetlabs.puppetdb.testutils.catalogs :as tuc]
[puppetlabs.puppetdb.testutils.facts :as tuf]
[puppetlabs.puppetdb.testutils.services :as svc-utils]))
[puppetlabs.puppetdb.testutils.services :as svc-utils]
[clojure.walk :as walk]))
(defn get-child [href]
(svc-utils/get-json (svc-utils/pdb-query-url)
......@@ -39,7 +41,8 @@
(-> (svc-utils/pdb-query-url)
(svc-utils/get-reports certname)
(get-children [:metrics :logs :resource_events])
reports/reports-query->wire-v5
tur/munge-reports
reports/reports-query->wire-v6
vec))
(defn get-factsets [certname]
......@@ -70,12 +73,15 @@
(-> examples-reports/reports
:basic
(assoc :certname example-certname)
tur/munge-example-report-for-storage))
tur/munge-report
reports/report-query->wire-v6))
(defn munge-tar-map
[tar-map]
(-> tar-map
(dissoc "export-metadata.json")
(update "facts" tuf/munge-facts)
(update "reports" tur/munge-report)
(update "reports" (comp stringify-keys
tur/munge-report
keywordize-keys))
(update "catalogs" tuc/munge-catalog)))
......@@ -11,24 +11,10 @@
;; can be compared for testing
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn munge-example-event-for-storage
"Helper function to munge our example reports into a format suitable for submission
via the 'store report' command."
[example-event]
;; Because we want to compare 'certname' in the output of event queries, the
;; example data includes it... but it is not a legal key for an event during
;; report submission.
(dissoc example-event :certname :containing_class :environment))
(defn environment [resource-event report version]
(if (= :v4 version)
(assoc-when resource-event :environment (:environment report))
(dissoc resource-event :environment)))
(defn expected-resource-event
"Given a resource event from the example data, plus a report hash, coerce the
event into the format that we expect to be returned from a real query."
[version example-resource-event report]
[example-resource-event report]
(-> example-resource-event
;; the examples don't have the report-id or configuration-version,
;; but the results from the database do... so we need to munge those in.
......@@ -40,15 +26,15 @@
;; we need to convert the datetime fields from the examples to timestamp objects
;; in order to compare them.
(update :timestamp to-timestamp)
(environment report version)))
(assoc-when :environment (:environment report))))
(defn raw-expected-resource-events
"Given a sequence of resource events from the example data, plus a report,
coerce the events into the format that we expected to be returned from a real query.
Unlike the more typical `expected-resource-events`, this does not put the events
into a set, which makes this function useful for testing the order of results."
[version example-resource-events report]
(map #(expected-resource-event version % report) example-resource-events))
[example-resource-events report]
(map #(expected-resource-event % report) example-resource-events))
(defn timestamps->str
"Walks events and stringifies all timestamps"
......@@ -59,18 +45,14 @@
x))
events))
(defn http-expected-resource-events
"Returns an HTTPish version of resource events"
[version example-resource-events report]
(-> (raw-expected-resource-events version example-resource-events report)
timestamps->str
set))
(defn expected-resource-events
"Given a sequence of resource events from the example data, plus a report,
coerce the events into the format that we expect to be returned from a real query."
[version example-resource-events report]
(set (raw-expected-resource-events version example-resource-events report)))
[example-resource-events report]
(-> example-resource-events
(raw-expected-resource-events report)
timestamps->str
set))
(defn query-resource-events
([version query]
......
......@@ -3,7 +3,6 @@
[puppetlabs.puppetdb.examples.reports :refer [reports]]
[puppetlabs.puppetdb.examples :refer :all]
[puppetlabs.puppetdb.zip :as zip]
[puppetlabs.puppetdb.testutils.reports :as tur]
[puppetlabs.puppetdb.reports :as report]
[clj-time.core :refer [now plus seconds]]))
......@@ -21,9 +20,8 @@
[node-name]
(-> (:basic reports)
(change-certname node-name)
tur/munge-example-report-for-storage
(assoc :end_time (now))
report/wire-v5->wire-v6))
report/report-query->wire-v6))
(defn store-example-nodes
[]
......
(ns puppetlabs.puppetdb.testutils.reports
(:require [puppetlabs.puppetdb.scf.storage :as scf-store]
[puppetlabs.puppetdb.scf.hash :as shash]
[puppetlabs.puppetdb.reports :as report]
[puppetlabs.puppetdb.reports :as reports]
[puppetlabs.puppetdb.scf.storage-utils :as sutils]
[puppetlabs.kitchensink.core :as kitchensink]