                           :port port
                           :query-base-url (assoc base-url :prefix "/pdb/query" :version :v4)
                           :command-base-url (assoc base-url :prefix "/pdb/cmd" :version :v1)
-                          :admin-base-url (assoc base-url :prefix "/pdb/admin" :version :v1)}
+                          :admin-base-url (assoc base-url :prefix "/pdb/admin" :version :v1)
+                          :app app}
                          app)))
 
 (defn pql-query [pdb-server query]

                  :version :v4}]
    (try
      (swap! dispatch/metrics svc-utils/clear-counters!)
      {:app (tkbs/parse-and-bootstrap bootstrap-config-file
                                      {:config tmp-puppetdb-conf})
       :base-url base-url}

      (catch java.net.BindException e

      "catalogs[certname, environment] {}" [{:certname "localhost", :environment "production"}]
      "factsets[certname, environment] {}" [{:certname "localhost", :environment "production"}]
      "reports[certname, environment] {}" [{:certname "localhost", :environment "production"}])))
(deftest ^:integration db-fallback
  (with-open [pg1 (setup-postgres)
              pg2 (setup-postgres)
              pdb1 (run-puppetdb pg1 {})
              pdb2 (run-puppetdb pg2 {})
              ps (run-puppet-server [pdb1 pdb2] {})]

    (testing "Agent run against pdb1"
      (run-puppet ps "notify { 'hello, world!': }")
      (is (= 1 (count (pql-query pdb1 "nodes {}")))))

    (testing "Fallback to pdb2"
      (tk-app/stop (:app pdb1))
      (is (= 0 (count (pql-query pdb2 "nodes {}"))))

      (run-puppet ps "notify { 'hello, world!': }")
      (is (= 1 (count (pql-query pdb2 "nodes {}")))))))

