mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 19:28:27 +02:00
Replace internal storage impl with datoteka library.
This commit is contained in:
parent
4efe9ac5a9
commit
618ce12fd8
17 changed files with 33 additions and 726 deletions
|
@ -1,106 +0,0 @@
|
|||
(ns storages.tests
|
||||
(:require [clojure.test :as t]
|
||||
[storages.core :as st]
|
||||
[storages.backend.local :as local]
|
||||
[storages.backend.misc :as misc])
|
||||
(:import java.io.File
|
||||
org.apache.commons.io.FileUtils))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Test Fixtures
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn- clean-temp-directory
|
||||
[next]
|
||||
(next)
|
||||
(let [directory (File. "/tmp/catacumba/")]
|
||||
(FileUtils/deleteDirectory directory)))
|
||||
|
||||
(t/use-fixtures :each clean-temp-directory)
|
||||
|
||||
;; --- Tests: FileSystemStorage
|
||||
|
||||
(t/deftest test-localfs-store-and-lookup
|
||||
(let [storage (local/localfs {:basedir "/tmp/catacumba/test"
|
||||
:baseuri "http://localhost:5050/"})
|
||||
rpath @(st/save storage "test.txt" "my content")
|
||||
fpath @(st/lookup storage rpath)
|
||||
fdata (slurp fpath)]
|
||||
(t/is (= (str fpath) "/tmp/catacumba/test/test.txt"))
|
||||
(t/is (= "my content" fdata))))
|
||||
|
||||
(t/deftest test-localfs-store-and-get-public-url
|
||||
(let [storage (local/localfs {:basedir "/tmp/catacumba/test"
|
||||
:baseuri "http://localhost:5050/"})
|
||||
rpath @(st/save storage "test.txt" "my content")
|
||||
ruri (st/public-url storage rpath)]
|
||||
(t/is (= (str ruri) "http://localhost:5050/test.txt"))))
|
||||
|
||||
(t/deftest test-localfs-store-and-lookup-with-subdirs
|
||||
(let [storage (local/localfs {:basedir "/tmp/catacumba/test"
|
||||
:baseuri "http://localhost:5050/"})
|
||||
rpath @(st/save storage "somepath/test.txt" "my content")
|
||||
fpath @(st/lookup storage rpath)
|
||||
fdata (slurp fpath)]
|
||||
(t/is (= (str fpath) "/tmp/catacumba/test/somepath/test.txt"))
|
||||
(t/is (= "my content" fdata))))
|
||||
|
||||
(t/deftest test-localfs-store-and-delete-and-check
|
||||
(let [storage (local/localfs {:basedir "/tmp/catacumba/test"
|
||||
:baseuri "http://localhost:5050/"})
|
||||
rpath @(st/save storage "test.txt" "my content")]
|
||||
(t/is @(st/delete storage rpath))
|
||||
(t/is (not @(st/exists? storage rpath)))))
|
||||
|
||||
(t/deftest test-localfs-store-duplicate-file-raises-exception
|
||||
(let [storage (local/localfs {:basedir "/tmp/catacumba/test"
|
||||
:baseuri "http://localhost:5050/"})]
|
||||
(t/is @(st/save storage "test.txt" "my content"))
|
||||
(t/is (thrown? java.util.concurrent.ExecutionException
|
||||
@(st/save storage "test.txt" "my content")))))
|
||||
|
||||
(t/deftest test-localfs-access-unauthorized-path
|
||||
(let [storage (local/localfs {:basedir "/tmp/catacumba/test"
|
||||
:baseuri "http://localhost:5050/"})]
|
||||
(t/is (thrown? java.util.concurrent.ExecutionException
|
||||
@(st/lookup storage "../test.txt")))
|
||||
(t/is (thrown? java.util.concurrent.ExecutionException
|
||||
@(st/lookup storage "/test.txt")))))
|
||||
|
||||
;; --- Tests: ScopedPathStorage
|
||||
|
||||
(t/deftest test-localfs-scoped-store-and-lookup
|
||||
(let [storage (local/localfs {:basedir "/tmp/catacumba/test"
|
||||
:baseuri "http://localhost:5050/"})
|
||||
storage (misc/scoped storage "some/prefix")
|
||||
rpath @(st/save storage "test.txt" "my content")
|
||||
fpath @(st/lookup storage rpath)
|
||||
fdata (slurp fpath)]
|
||||
(t/is (= (str fpath) "/tmp/catacumba/test/some/prefix/test.txt"))
|
||||
(t/is (= "my content" fdata))))
|
||||
|
||||
(t/deftest test-localfs-scoped-store-and-delete-and-check
|
||||
(let [storage (local/localfs {:basedir "/tmp/catacumba/test"
|
||||
:baseuri "http://localhost:5050/"})
|
||||
storage (misc/scoped storage "some/prefix")
|
||||
rpath @(st/save storage "test.txt" "my content")]
|
||||
(t/is @(st/delete storage rpath))
|
||||
(t/is (not @(st/exists? storage rpath)))))
|
||||
|
||||
(t/deftest test-localfs-scoped-store-duplicate-file-raises-exception
|
||||
(let [storage (local/localfs {:basedir "/tmp/catacumba/test"
|
||||
:baseuri "http://localhost:5050/"})
|
||||
storage (misc/scoped storage "some/prefix")]
|
||||
(t/is @(st/save storage "test.txt" "my content"))
|
||||
(t/is (thrown? java.util.concurrent.ExecutionException
|
||||
@(st/save storage "test.txt" "my content")))))
|
||||
|
||||
(t/deftest test-localfs-scoped-access-unauthorized-path
|
||||
(let [storage (local/localfs {:basedir "/tmp/catacumba/test"
|
||||
:baseuri "http://localhost:5050/"})
|
||||
storage (misc/scoped storage "some/prefix")]
|
||||
(t/is (thrown? java.util.concurrent.ExecutionException
|
||||
@(st/lookup storage "../test.txt")))
|
||||
(t/is (thrown? java.util.concurrent.ExecutionException
|
||||
@(st/lookup storage "/test.txt")))))
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
[buddy.core.codecs :as codecs]
|
||||
[catacumba.serializers :as sz]
|
||||
[mount.core :as mount]
|
||||
[storages.core :as st]
|
||||
[datoteka.storages :as st]
|
||||
[suricatta.core :as sc]
|
||||
[uxbox.services.auth :as usa]
|
||||
[uxbox.services.users :as usu]
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
[suricatta.core :as sc]
|
||||
[clojure.java.io :as io]
|
||||
[catacumba.testing :refer (with-server)]
|
||||
[storages.core :as st]
|
||||
[datoteka.storages :as st]
|
||||
[uxbox.db :as db]
|
||||
[uxbox.sql :as sql]
|
||||
[uxbox.media :as media]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue