Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added test scope dependency on MySQL connector. Added stub test again…

…st local MySQL database, but with test-mysql set false to prevent it running (it passes locally with it set true).
  • Loading branch information...
commit 177a59be82b8119977580741a069de46380737e9 1 parent 956da8b
@seancorfield seancorfield authored
Showing with 40 additions and 0 deletions.
  1. +8 −0 pom.xml
  2. +32 −0 src/test/clojure/clojure/java/test_jdbc.clj
View
8 pom.xml
@@ -21,4 +21,12 @@
<developerConnection>scm:git:git@github.com:clojure/java.jdbc.git</developerConnection>
<url>git@github.com:clojure/java.jdbc.git</url>
</scm>
+ <dependencies>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.6</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
View
32 src/test/clojure/clojure/java/test_jdbc.clj
@@ -24,6 +24,18 @@
(:use clojure.test)
(:require [clojure.java.jdbc :as sql]))
+;; set these true/false depending on whether you have the local database available:
+
+(def test-mysql false)
+
+;; database connections used for testing:
+
+(def mysql-db {:classname "com.mysql.jdbc.Driver"
+ :subprotocol "mysql"
+ :subname "//127.0.0.1:3306/clojure_test"
+ :user "clojure_test"
+ :password "clojure_test"})
+
;; basic tests for keyword / entity conversion
(deftest test-as-identifier
@@ -93,6 +105,26 @@
(is (= "CREATE TABLE table (col1 int, col2 int) ENGINE=MyISAM"
(sql/create-table-ddl :table [:col1 "int"] ["col2" :int] :table-spec "ENGINE=MyISAM"))))
+(deftest test-create-drop-table
+ (when test-mysql
+ (sql/with-connection mysql-db
+ (try
+ (sql/create-table :fruit
+ [:name "VARCHAR(32)" "PRIMARY KEY"]
+ [:appearance "VARCHAR(32)"]
+ [:cost :int]
+ [:grade :real]
+ :table-spec "ENGINE=MyISAM")
+ (is (= 0 (sql/with-connection
+ mysql-db
+ (sql/with-query-results res ["SELECT * FROM fruit"] (count res)))))
+ (catch Exception _
+ (println "Unable to create/read :fruit")))
+ (try
+ (sql/drop-table :fruit)
+ (catch Exception _
+ (println "Unable to drop :fruit"))))))
+
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; old example code below here - will eventually be removed once proper tests are written!
Please sign in to comment.
Something went wrong with that request. Please try again.