;; This is the default test configuration file.  If you would like to override
;; some of the settings herein, simply make a copy of this file and name it
;; `local.clj`.  It will be loaded instead of this one.  (`local.clj` is
;; included in the `.gitignore` file, so you don't have to worry about
;; accidentally committing your local changes.)

(defn test-db-config
  "Return a map of connection attrs for the test database"
  []
  {:classname   "org.hsqldb.jdbcDriver"
   :subprotocol "hsqldb"
   :subname     (str "mem:"
                  (java.util.UUID/randomUUID)
                  ";shutdown=true;hsqldb.tx=mvcc;sql.syntax_pgs=true")})

;; here is a sample test-db-config function for use with postgres
;(defn test-db-config
;  "Return a map of connection attrs for the test database"
;  []
;  {:classname   "org.postgresql.Driver"
;   :subprotocol "postgresql"
;   :subname     "//localhost:5432/puppetdb_test"
;   :user        "puppetdb"
;   :password    "puppet"
;   })


;; This is the default test configuration file.  If you would like to override
;; some of the settings herein, simply make a copy of this file and name it
;; `local.clj`.  It will be loaded instead of this one.  (`local.clj` is
;; included in the `.gitignore` file, so you don't have to worry about
;; accidentally committing your local changes.)

(defn test-db-config
  "Return a map of connection attrs for the test database"
  []
  (let [dbtype     (System/getenv "PUPPETDB_DBTYPE")
        dbsubname  (System/getenv "PUPPETDB_DBSUBNAME")
        dbuser     (System/getenv "PUPPETDB_DBUSER")
        dbpassword (System/getenv "PUPPETDB_DBPASSWORD")]
    (if (= dbtype "postgres")
      (if (some nil? [dbsubname dbuser dbpassword])
        (do
          (println "Ensure environment variables PUPPETDB_DBSUBNAME, PUPPETDB_DBUSER and PUPPETDB_DBPASSWORD are set")
          (System/exit 1))
        {:classname   "org.postgresql.Driver"
         :subprotocol "postgresql"
         :subname     dbsubname
         :user        dbuser
         :password    dbpassword})
      {:classname   "org.hsqldb.jdbcDriver"
       :subprotocol "hsqldb"
       :subname     (str "mem:"
                      (java.util.UUID/randomUUID)
                      ";shutdown=true;hsqldb.tx=mvcc;sql.syntax_pgs=true")})))

;; here is a sample test-db-config function for use with postgres
;(defn test-db-config
;  "Return a map of connection attrs for the test database"
;  []
;  {:classname   "org.postgresql.Driver"
;   :subprotocol "postgresql"
;   :subname     "//localhost:5432/puppetdb_test"
;   :user        "puppetdb"
;   :password    "puppet"
;   })


Define postgres settings using environment vars
Define postgres settings using environment vars

In the past we were copying a magic from from tb-driver: local.clj that
contained all the information needed to connect to our test Postgres
database. tb-driver is being decommissioned, and its felt we need a better
way to manage this going forward.

This patch allows us to parameterize database tests, in particular the postgres
specific settings using environment variables. This way we can pass the
settings in from Jenkins using its special 'passwords as environment vars'
feature.

The default HSQLDB behaviour is kept if DBTEST_TYPE is not set, and local.clj
support is kept.

Signed-off-by: Ken Barber <470bc578162732ac7f9d387d34c4af4ca6e1b6f7@bob.sh>

puppetlabs/puppetdb,mullr/puppetdb,shrug/puppetdb,waynr/puppetdb,johnduarte/puppetdb,mullr/puppetdb,cprice404/puppetdb,shrug/puppetdb,ajroetker/puppetdb,waynr/puppetdb,puppetlabs/puppetdb,puppetlabs/puppetdb,jantman/puppetdb,mullr/puppetdb,grimradical/puppetdb,rbrw/puppetdb,cprice404/puppetdb,waynr/puppetdb,shrug/puppetdb,wkalt/puppetdb,melissa/puppetdb,kbrezina/puppetdb,kbrezina/puppetdb,jantman/puppetdb,mullr/puppetdb,johnduarte/puppetdb,highb/puppetdb,mullr/puppetdb,senior/puppetdb,highb/puppetdb,rbrw/puppetdb,waynr/puppetdb,kbarber/puppetdb,kbarber/puppetdb,johnduarte/puppetdb,grimradical/puppetdb,shrug/puppetdb,grimradical/puppetdb,kbarber/puppetdb,rbrw/puppetdb,melissa/puppetdb,cprice404/puppetdb,senior/puppetdb,melissa/puppetdb,senior/puppetdb,rbrw/puppetdb,ajroetker/puppetdb,kbrezina/puppetdb,highb/puppetdb,ajroetker/puppetdb,kbrezina/puppetdb,grimradical/puppetdb,wkalt/puppetdb,wkalt/puppetdb,rbrw/puppetdb,ajroetker/puppetdb,puppetlabs/puppetdb,kbarber/puppetdb,wkalt/puppetdb,senior/puppetdb,puppetlabs/puppetdb,johnduarte/puppetdb,highb/puppetdb,jantman/puppetdb