Run clojure blobstore tests inside with-blobstore.

This commit is contained in:
Jim 2010-03-09 16:16:43 -06:00
parent 1da7c5a6b6
commit 5311b05192
1 changed files with 26 additions and 47 deletions

View File

@ -8,9 +8,10 @@
(def stub-blobstore (.getBlobStore stub-context)) (def stub-blobstore (.getBlobStore stub-context))
(defn clean-stub-fixture [f] (defn clean-stub-fixture [f]
(doseq [container (containers)] (with-blobstore [stub-blobstore]
(delete-container (.getName container))) (doseq [container (containers)]
(f)) (delete-container (.getName container)))
(f)))
(use-fixtures :each clean-stub-fixture) (use-fixtures :each clean-stub-fixture)
@ -34,19 +35,13 @@
(deftest create-existing-container-test (deftest create-existing-container-test
(is (not (container-exists? stub-blobstore ""))) (is (not (container-exists? stub-blobstore "")))
(with-blobstore [stub-blobstore] (is (not (container-exists? "")))
(is (not (container-exists? ""))))
(is (create-container stub-blobstore "fred")) (is (create-container stub-blobstore "fred"))
(is (container-exists? stub-blobstore "fred")) (is (container-exists? stub-blobstore "fred")))
(with-blobstore [stub-blobstore]
(is (container-exists? "fred"))))
(deftest create-container-test (deftest create-container-test
(is (create-container stub-blobstore "fred")) (is (create-container stub-blobstore "fred"))
(is (container-exists? stub-blobstore "fred")) (is (container-exists? stub-blobstore "fred")))
(with-blobstore [stub-blobstore]
(is (create-container "fred"))
(is (container-exists? "fred"))))
(deftest containers-test (deftest containers-test
(is (empty? (containers stub-blobstore))) (is (empty? (containers stub-blobstore)))
@ -54,43 +49,27 @@
(is (= 1 (count (containers stub-blobstore))))) (is (= 1 (count (containers stub-blobstore)))))
(deftest list-container-test (deftest list-container-test
(is (create-container stub-blobstore "container")) (is (create-container "container"))
(is (empty? (list-container stub-blobstore "container"))) (is (empty? (list-container "container")))
(is (create-blob stub-blobstore "container" "blob1" "blob1")) (is (create-blob "container" "blob1" "blob1"))
(is (create-blob stub-blobstore "container" "blob2" "blob2")) (is (create-blob "container" "blob2" "blob2"))
(is (= 2 (count (list-container stub-blobstore "container")))) (is (= 2 (count (list-container "container"))))
(is (= 1 (count (list-container stub-blobstore "container" :max-results 1)))) (is (= 1 (count (list-container "container" :max-results 1))))
(create-directory stub-blobstore "container" "dir") (create-directory "container" "dir")
(is (create-blob stub-blobstore "container" "dir/blob2" "blob2")) (is (create-blob "container" "dir/blob2" "blob2"))
(is (= 3 (count (list-container stub-blobstore "container")))) (is (= 3 (count (list-container "container"))))
(is (= 4 (count (list-container stub-blobstore "container" :recursive)))) (is (= 4 (count (list-container "container" :recursive))))
(is (= 1 (count (list-container stub-blobstore "container" (is (= 1 (count (list-container "container" :in-directory "dir")))))
:in-directory "dir")))))
(deftest list-container-with-blobstore-test
(with-blobstore [stub-blobstore]
(is (create-container "container"))
(is (empty? (list-container "container")))
(is (create-blob "container" "blob1" "blob1"))
(is (create-blob "container" "blob2" "blob2"))
(is (= 2 (count (list-container "container"))))
(is (= 1 (count (list-container "container" :max-results 1))))
(create-directory "container" "dir")
(is (create-blob "container" "dir/blob2" "blob2"))
(is (= 3 (count (list-container "container"))))
(is (= 4 (count (list-container "container" :recursive))))
(is (= 1 (count (list-container "container" :in-directory "dir"))))))
(deftest download-blob-test (deftest download-blob-test
(with-blobstore [stub-blobstore] (let [name "test"
(let [name "test" container-name "test-container"
container-name "test-container" data "test content"
data "test content" baos (ByteArrayOutputStream.)]
baos (ByteArrayOutputStream.)] (create-container container-name)
(create-container container-name) (create-blob container-name name data)
(create-blob container-name name data) (download-blob container-name name baos)
(download-blob container-name name baos) (is (= data (.toString baos)))))
(is (= data (.toString baos))))))
;; TODO: more tests involving blob-specific functions ;; TODO: more tests involving blob-specific functions