Repository navigation
Expand file tree
/
Copy pathstore.echo
More file actions
74 lines (60 loc) · 1.52 KB
/
Copy pathstore.echo
File metadata and controls
74 lines (60 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
; Object store — memory or S3-compatible (R2 via endpoint + keys).
; Returns `{ status, body, etag }`.
/ runtime
/ std/test
/ std/str
/ std/bytes
$ memory = () {
^ runtime.store_memory_new()
}
$ s3 = () {
^ runtime.store_s3_new()
}
$ close = (s) {
runtime.store_close(s)
^
}
$ get = (s, key) {
^ runtime.store_get(s, key)
}
$ get_if_none_match = (s, key, etag) {
^ runtime.store_get_if_none_match(s, key, etag)
}
$ get_range = (s, key, start, end) {
^ runtime.store_get_range(s, key, start, end)
}
$ head = (s, key) {
^ runtime.store_head(s, key)
}
$ put = (s, key, data) {
^ runtime.store_put(s, key, data)
}
$ cas = (s, key, etag, data) {
^ runtime.store_cas(s, key, etag, data)
}
$ cas_create = (s, key, data) {
^ runtime.store_cas_create(s, key, data)
}
$ keys = (s) {
^ runtime.store_keys(s)
}
test.it("memory_put_get_cas", () {
$ s = memory()
$ miss = get(s, "k")
test.eq(miss.status, 404)
$ p = put(s, "k", bytes.from_str("v1"))
test.eq(p.status, 200)
$ got = get(s, "k")
test.eq(got.status, 200)
test.eq(str.from_bytes(got.body), "v1")
$ again = get_if_none_match(s, "k", p.etag)
test.eq(again.status, 304)
$ clash = cas_create(s, "k", bytes.from_str("x"))
test.eq(clash.status, 412)
$ ok = cas(s, "k", p.etag, bytes.from_str("v2"))
test.eq(ok.status, 200)
$ v2 = get(s, "k")
test.eq(str.from_bytes(v2.body), "v2")
close(s)
})
\ memory, s3, close, get, get_if_none_match, get_range, head, put, cas, cas_create, keys