|
11 | 11 | [malli.core :as m]
|
12 | 12 | [matcher-combinators.standalone :refer [match?]]
|
13 | 13 | [matcher-combinators.test]
|
14 |
| - [ring.mock.request :as mock])) |
| 14 | + [ring.mock.request :as mock]) |
| 15 | + (:import (java.util Arrays))) |
15 | 16 |
|
16 | 17 | (defn org-repos-path [org-name]
|
17 | 18 | (str "/orgs/" org-name "/repos"))
|
|
282 | 283 | (= {:status 200
|
283 | 284 | :body {:type "file"
|
284 | 285 | :path (:path file)
|
| 286 | + :encoding "base64" |
285 | 287 | :content (base64/encode-str->str (:content file))}}
|
286 | 288 | (handler (get-content-request (:org/name org0) (:repo/name repo0) (:path file) (-> branch :commit :sha))))))
|
287 | 289 |
|
| 290 | +(defn create-binary-blob-request [org repo contents] |
| 291 | + (let [path (str "/repos/" org "/" repo "/git/blobs") |
| 292 | + req (mock/request :post path) |
| 293 | + body {:content (base64/encode-bytes->str contents) |
| 294 | + :encoding "base64"}] |
| 295 | + (assoc req :body body))) |
| 296 | + |
| 297 | +(defn create-string-blob-request [org repo contents] |
| 298 | + (let [path (str "/repos/" org "/" repo "/git/blobs") |
| 299 | + req (mock/request :post path) |
| 300 | + body {:content contents}] |
| 301 | + (assoc req :body body))) |
| 302 | + |
| 303 | +(defn get-blob-request [org repo sha] |
| 304 | + (let [path (str "/repos/" org "/" repo "/git/blobs/" sha) |
| 305 | + req (mock/request :get path)] |
| 306 | + req)) |
| 307 | + |
| 308 | +(defspec create-and-get-binary-blob |
| 309 | + (prop/for-all |
| 310 | + [{:keys [handler org0 repo0]} (mock-gen/database {:repo [[1]]}) |
| 311 | + ^bytes contents gen/bytes] |
| 312 | + (let [{create-blob-status :status |
| 313 | + {blob-sha :sha} :body} (handler (create-binary-blob-request (:org/name org0) (:repo/name repo0) contents)) |
| 314 | + {get-blob-status :status |
| 315 | + get-blob-body :body} (handler (get-blob-request (:org/name org0) (:repo/name repo0) blob-sha))] |
| 316 | + (and (= 201 create-blob-status) |
| 317 | + (= 200 get-blob-status) |
| 318 | + (= "base64" (:encoding get-blob-body)) |
| 319 | + (Arrays/equals contents (base64/decode-str->bytes (:content get-blob-body))))))) |
| 320 | + |
| 321 | +(defspec create-and-get-string-blob |
| 322 | + (prop/for-all |
| 323 | + [{:keys [handler org0 repo0]} (mock-gen/database {:repo [[1]]}) |
| 324 | + contents gen/string] |
| 325 | + (let [{create-blob-status :status |
| 326 | + {blob-sha :sha} :body} (handler (create-string-blob-request (:org/name org0) (:repo/name repo0) contents)) |
| 327 | + {get-blob-status :status |
| 328 | + get-blob-body :body} (handler (get-blob-request (:org/name org0) (:repo/name repo0) blob-sha))] |
| 329 | + (and (= 201 create-blob-status) |
| 330 | + (= 200 get-blob-status) |
| 331 | + (= "base64" (:encoding get-blob-body)) |
| 332 | + (= contents (base64/decode-str->str (:content get-blob-body))))))) |
| 333 | + |
288 | 334 | (defspec get-content-supports-refs
|
289 | 335 | (prop/for-all
|
290 | 336 | [{:keys [handler org0 repo0 file branch]} (gen/let [{:keys [repo0] :as database} (mock-gen/database {:repo [[1]]})
|
|
294 | 340 | (= {:status 200
|
295 | 341 | :body {:type "file"
|
296 | 342 | :path (:path file)
|
| 343 | + :encoding "base64" |
297 | 344 | :content (base64/encode-str->str (:content file))}}
|
298 | 345 | (handler (get-content-request (:org/name org0) (:repo/name repo0) (:path file) (:name branch))))))
|
299 | 346 |
|
|
307 | 354 | (= {:status 200
|
308 | 355 | :body {:type "file"
|
309 | 356 | :path (:path file)
|
| 357 | + :encoding "base64" |
310 | 358 | :content (base64/encode-str->str (:content file))}}
|
311 | 359 | (handler (get-content-request (:org/name org0) (:repo/name repo0) (:path file))))))
|
0 commit comments