Created
April 9, 2014 22:02
-
-
Save senior/10322804 to your computer and use it in GitHub Desktop.
PuppetDB Full Stack CLJ test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns com.puppetlabs.puppetdb.test.cli.import-export-roundtrip | |
(:require [com.puppetlabs.puppetdb.cli.export :as export] | |
[com.puppetlabs.puppetdb.cli.import :as import] | |
[puppetlabs.trapperkeeper.services.webserver.jetty9-service :refer [jetty9-service]] | |
[com.puppetlabs.puppetdb.cli.services :refer [puppetdb-service]] | |
[puppetlabs.trapperkeeper.core :as tk] | |
[clojure.test :refer :all] | |
[com.puppetlabs.puppetdb.testutils :as testutils] | |
[fs.core :as fs] | |
[puppetlabs.kitchensink.core :as kitchensink] | |
[com.puppetlabs.puppetdb.fixtures :as fixt] | |
[puppetlabs.trapperkeeper.app :as tka] | |
[clj-http.client :as client] | |
[com.puppetlabs.cheshire :as json] | |
[com.puppetlabs.puppetdb.command.constants :refer [command-names]] | |
[com.puppetlabs.puppetdb.examples :refer [wire-catalogs]] | |
[puppetlabs.trapperkeeper.testutils.bootstrap :as tkbs] | |
[com.puppetlabs.puppetdb.testutils.catalogs :as tuc])) | |
(def ^:dynamic *port* nil) | |
(defn current-port [server] | |
(-> @(tka/app-context server) | |
(get-in [:WebserverService :jetty9-server :server]) | |
.getConnectors | |
first | |
.getLocalPort)) | |
(defn convert-config [config] | |
(let [new-config-file (testutils/temp-file "config" ".ini") | |
config-path (fs/absolute-path new-config-file)] | |
(kitchensink/spit-ini new-config-file (merge-with merge (kitchensink/ini-to-map config) {:global {:vardir (testutils/temp-dir)} | |
:database (fixt/create-db-map) | |
:jetty {:port 0}})) | |
config-path)) | |
(defn current-url [] | |
(format "http://localhost:%s/v4/" *port*)) | |
(defn puppetdb-instance [f] | |
(tkbs/with-app-with-cli-data server | |
[jetty9-service puppetdb-service] | |
{:config (convert-config "config.sample.ini")} | |
(binding [*port* (current-port server)] | |
(f)))) | |
(defn current-queue-depth [] | |
(-> (format "%smetrics/mbean/org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=com.puppetlabs.puppetdb.commands" (current-url)) | |
(client/get {:as :json}) | |
(get-in [:body :QueueSize]))) | |
(defn block-until-queue-empty [] | |
(loop [depth (current-queue-depth)] | |
(when (< 0 depth) | |
(Thread/sleep 10) | |
(recur (current-queue-depth))))) | |
(deftest test-basic-roundtrip | |
(puppetdb-instance | |
(fn [] | |
(client/post (str (current-url) "commands") | |
{:headers {"content-type" "application/json"} | |
:body (json/generate-string {:command (command-names :replace-catalog) | |
:version 4 | |
:payload (get-in wire-catalogs [4 :empty])})}) | |
(block-until-queue-empty) | |
(is (= (tuc/munge-catalog-for-comparison :v4 (get-in wire-catalogs [4 :empty])) | |
(tuc/munge-catalog-for-comparison :v4 (:body (client/get (format "%scatalogs/%s" (current-url) (get-in wire-catalogs [4 :empty :name])) {:as :json})))))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment