AtlatestRepositorysigil-cloudflare
sigil-cloudflare / tree / testtest-network.sgl
1
(import (sigil test)2
(sigil process)3
(sigil crypto)4
(cloudflare r2))6
;; test/http.mjs supplies a loopback-only fake service and independently checks7
;; signatures, raw bodies and methods. No real credentials or Cloudflare calls.8
(when (getenv "R2_TEST_PORT")9
(test-group "R2 HTTP boundary"10
(test "binary PUT/GET/HEAD/DELETE and provider failures"11
(let* ((client (r2-client "0123456789abcdef0123456789abcdef" "TESTACCESS" "test-secret"12
"test-assets" test-port: (string->number (getenv "R2_TEST_PORT")) timeout: 2))13
(key "logos/é +%雪.png")14
(bytes (make-bytevector 65536)))15
(let loop ((i 0))16
(when (< i 65536)17
(bytevector-u8-set! bytes i (modulo i 256))18
(loop (+ i 1))))19
(assert-equal (dict-ref (r2-put-object client key bytes content-type: "image/png" cache-control: "public, max-age=3600") status:) 200)20
(let ((got (r2-get-object client key)))21
(assert-equal (dict-ref got status:) 200)22
(assert-equal (sha256 (dict-ref got body:)) (sha256 bytes)))23
(let ((head (r2-head-object client key)))24
(assert-equal (dict-ref head status:) 200)25
(assert-equal (bytevector-length (dict-ref head body:)) 0))26
(assert-equal (dict-ref (r2-delete-object client key) status:) 204)27
(assert-equal (dict-ref (r2-get-object client key) status:) 404)28
(assert-equal (dict-ref (r2-get-object client "redirect") status:) 307)29
(assert-equal (dict-ref (r2-get-object client "denied") status:) 403)30
(assert-false (r2-get-object client "truncated"))))))