Skip to content
Snippets Groups Projects
Commit f49f96b5 authored by Tom Robinson's avatar Tom Robinson
Browse files

db/parse-connection-string unit tests

parent ffb3472b
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@
(defn parse-connection-string
"Parse a DB connection URI like `postgres://cam@localhost.com:5432/cams_cool_db?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory` and return a broken-out map."
[uri]
(when-let [[_ protocol user pass host port db query] (re-matches #"^([^:/@]+)://([^:/@]+)(?::([^:@]+))?@([^:@]+)(?::(\d+))?/([^/?]+)(?:\?(.*))?$" uri)]
(when-let [[_ protocol user pass host port db query] (re-matches #"^([^:/@]+)://(?:([^:/@]+)(?::([^:@]+))?@)?([^:@]+)(?::(\d+))?/([^/?]+)(?:\?(.*))?$" uri)]
(merge {:type (keyword protocol)
:user user
:password pass
......
(ns metabase.db-test
(:require [expectations :refer :all]
[metabase.db :as db]))
;; parse minimal connection string
(expect {:type :postgres :user nil :password nil :host "localhost" :port nil :dbname "toms_cool_db" }
(db/parse-connection-string "postgres://localhost/toms_cool_db"))
;; parse all fields and query string arguments
(expect {:type :postgres :user "tom" :password "1234" :host "localhost" :port "5432" :dbname "toms_cool_db" :ssl "true" :sslfactory "org.postgresql.ssl.NonValidatingFactory"}
(db/parse-connection-string "postgres://tom:1234@localhost:5432/toms_cool_db?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment