|
3 | 3 | [clojars.admin :as admin] |
4 | 4 | [clojars.config :refer [config]] |
5 | 5 | [clojars.db :as db] |
| 6 | + [clojars.s3 :as s3] |
6 | 7 | [clojars.search :as search] |
7 | 8 | [clojars.storage :as storage] |
8 | 9 | [clojars.test-helper :as help] |
|
12 | 13 |
|
13 | 14 | (def ^:dynamic *search-removals* nil) |
14 | 15 |
|
15 | | -(defn with-repo-setup2 |
| 16 | +(def ^:dynamic *s3-client* nil) |
| 17 | + |
| 18 | +;; Note: these tests exercise the s3 client end-to-end, and require minio to |
| 19 | +;; running. See docker-compose.yml |
| 20 | + |
| 21 | +(defn with-repo-setup |
16 | 22 | [f] |
17 | | - (let [jar (io/file (io/resource "fake.jar"))] |
| 23 | + (let [config (config) |
| 24 | + jar (io/file (io/resource "fake.jar")) |
| 25 | + s3-client (help/real-s3-client (get-in config [:s3 :repo-bucket]))] |
18 | 26 | (binding [*search-removals* (atom #{}) |
| 27 | + *s3-client* s3-client |
19 | 28 | admin/*db* help/*db* |
20 | 29 | admin/*search* (reify search/Search |
21 | 30 | (delete! [_ group#] |
22 | 31 | (swap! *search-removals* conj group#)) |
23 | 32 | (delete! [_ group# artifact#] |
24 | 33 | (swap! *search-removals* conj (format "%s/%s" group# artifact#)))) |
25 | | - admin/*storage* (storage/fs-storage (:repo (config)))] |
| 34 | + admin/*storage* (storage/multi-storage |
| 35 | + (storage/fs-storage (:repo config)) |
| 36 | + (storage/s3-storage s3-client))] |
26 | 37 | (db/add-user admin/*db* "testuser@example.com" "testuser" "password") |
27 | 38 | (help/add-verified-group "testuser" "org.ham") |
28 | 39 | (db/add-jar admin/*db* "testuser" {:group "org.ham" :name "biscuit" :version "1" :description "delete me"}) |
|
41 | 52 | (use-fixtures :each |
42 | 53 | help/default-fixture |
43 | 54 | help/with-clean-database |
44 | | - with-repo-setup2) |
| 55 | + with-repo-setup) |
45 | 56 |
|
46 | 57 | (deftest segments->path-should-work |
47 | 58 | (are [exp given] (= exp (admin/segments->path given)) |
48 | | - "a/b" ["a" "b"] |
49 | | - "a/b/c" ["a.b" "c"] |
50 | | - "a/b/c" ["a.b.c"] |
51 | | - "a/b/c" ["a.b" nil "c" nil])) |
| 59 | + "a/b/" ["a" "b"] |
| 60 | + "a/b/c/" ["a.b" "c"] |
| 61 | + "a/b/c/" ["a.b.c"] |
| 62 | + "a/b/c/" ["a.b" nil "c" nil])) |
52 | 63 |
|
53 | 64 | (deftest backup-dir-should-work |
54 | 65 | (with-redefs [admin/current-date-str (constantly "20160827")] |
|
71 | 82 | (is (backup-exists? "org/ham" "sandwich/1/sandwich-1.jar")) |
72 | 83 | (is (backup-exists? "org/ham" "sandwich/1/sandwich-1.pom")) |
73 | 84 |
|
| 85 | + (is (not (s3/object-exists? *s3-client* "org/ham/biscuit/1/biscuit-1.jar"))) |
| 86 | + (is (not (s3/object-exists? *s3-client* "org/ham/biscuit/1/biscuit-1.pom"))) |
| 87 | + (is (not (s3/object-exists? *s3-client* "org/ham/biscuit/2/biscuit-2.jar"))) |
| 88 | + (is (not (s3/object-exists? *s3-client* "org/ham/biscuit/2/biscuit-2.pom"))) |
| 89 | + (is (not (s3/object-exists? *s3-client* "org/ham/sandwich/1/sandwich-1.jar"))) |
| 90 | + (is (not (s3/object-exists? *s3-client* "org/ham/sandwich/1/sandwich-1.pom"))) |
| 91 | + |
74 | 92 | (is (not (.exists (io/file (:repo (config)) "org/ham")))) |
75 | 93 |
|
76 | 94 | (is (not (db/find-jar admin/*db* "org.ham" "biscuit"))) |
|
96 | 114 | (is (.exists (io/file (:repo (config)) "org/ham/sandwich/1/sandwich-1.jar"))) |
97 | 115 | (is (.exists (io/file (:repo (config)) "org/ham/sandwich/1/sandwich-1.pom"))) |
98 | 116 |
|
| 117 | + (is (not (s3/object-exists? *s3-client* "org/ham/biscuit/1/biscuit-1.jar"))) |
| 118 | + (is (not (s3/object-exists? *s3-client* "org/ham/biscuit/1/biscuit-1.pom"))) |
| 119 | + (is (not (s3/object-exists? *s3-client* "org/ham/biscuit/2/biscuit-2.jar"))) |
| 120 | + (is (not (s3/object-exists? *s3-client* "org/ham/biscuit/2/biscuit-2.pom"))) |
| 121 | + (is (s3/object-exists? *s3-client* "org/ham/sandwich/1/sandwich-1.jar")) |
| 122 | + (is (s3/object-exists? *s3-client* "org/ham/sandwich/1/sandwich-1.pom")) |
| 123 | + |
99 | 124 | (is (not (db/find-jar admin/*db* "org.ham" "biscuit"))) |
100 | 125 | (is (db/find-jar admin/*db* "org.ham" "sandwich")) |
101 | 126 | (is (seq (db/group-activenames admin/*db* "org.ham"))) |
|
119 | 144 | (is (.exists (io/file (:repo (config)) "org/ham/sandwich/1/sandwich-1.jar"))) |
120 | 145 | (is (.exists (io/file (:repo (config)) "org/ham/sandwich/1/sandwich-1.pom"))) |
121 | 146 |
|
| 147 | + (is (not (s3/object-exists? *s3-client* "org/ham/biscuit/1/biscuit-1.jar"))) |
| 148 | + (is (not (s3/object-exists? *s3-client* "org/ham/biscuit/1/biscuit-1.pom"))) |
| 149 | + (is (s3/object-exists? *s3-client* "org/ham/biscuit/2/biscuit-2.jar")) |
| 150 | + (is (s3/object-exists? *s3-client* "org/ham/biscuit/2/biscuit-2.pom")) |
| 151 | + (is (s3/object-exists? *s3-client* "org/ham/sandwich/1/sandwich-1.jar")) |
| 152 | + (is (s3/object-exists? *s3-client* "org/ham/sandwich/1/sandwich-1.pom")) |
| 153 | + |
122 | 154 | (is (not (db/find-jar admin/*db* "org.ham" "biscuit" "1"))) |
123 | 155 | (is (db/find-jar admin/*db* "org.ham" "biscuit" "2")) |
124 | 156 | (is (db/find-jar admin/*db* "org.ham" "sandwich")) |
|
0 commit comments