diff --git a/test/next/jdbc/test_fixtures.clj b/test/next/jdbc/test_fixtures.clj index 9e8d0b2..deffe12 100644 --- a/test/next/jdbc/test_fixtures.clj +++ b/test/next/jdbc/test_fixtures.clj @@ -36,6 +36,11 @@ (def ^:private test-datasource (atom nil)) +(defn db + "Tests should call this to get the db-spec to use inside a fixture." + [] + @test-db-spec) + (defn ds "Tests should call this to get the DataSource to use inside a fixture." [] diff --git a/test/next/jdbc_test.clj b/test/next/jdbc_test.clj index 63fa905..a6eac84 100644 --- a/test/next/jdbc_test.clj +++ b/test/next/jdbc_test.clj @@ -2,9 +2,12 @@ (ns next.jdbc-test "Not exactly a test suite -- more a series of examples." - (:require [clojure.test :refer [deftest is testing use-fixtures]] + (:require [clojure.string :as str] + [clojure.test :refer [deftest is testing use-fixtures]] [next.jdbc :as jdbc] - [next.jdbc.test-fixtures :refer [with-test-db ds postgres?]] + [next.jdbc.connection :as c] + [next.jdbc.test-fixtures :refer [with-test-db db ds + derby? postgres?]] [next.jdbc.prepare :as prep] [next.jdbc.result-set :as rs] [next.jdbc.specs :as specs]) @@ -177,6 +180,21 @@ VALUES ('Pear', 'green', 49, 47) result)))) (is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"])))))) +(deftest connection-tests + (testing "datasource via jdbcUrl" + (when-not (postgres?) + (let [[url etc] (#'c/spec->url+etc (db)) + ds (jdbc/get-datasource (assoc etc :jdbcUrl url))] + (if (derby?) + (is {:create true} etc) + (is {} etc)) + (is (instance? javax.sql.DataSource ds)) + (is (str/index-of (pr-str ds) (str "jdbc:" (:dbtype (db))))) + ;; checks get-datasource on a DataSource is identity + (is (identical? ds (jdbc/get-datasource ds))) + (with-open [con (jdbc/get-connection ds {})] + (is (instance? java.sql.Connection con))))))) + (deftest plan-misuse (let [s (pr-str (jdbc/plan (ds) ["select * from fruit"]))] (is (re-find #"missing reduction" s)))