-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.sh
More file actions
executable file
·43 lines (33 loc) · 1.68 KB
/
demo.sh
File metadata and controls
executable file
·43 lines (33 loc) · 1.68 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
#!/bin/bash
set -o errexit
set -o pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
WASMTIME=${WASMTIME:-wasmtime}
componentized_services() {
${WASMTIME} run -Sconfig -Sinherit-network \
-Sconfig-var=path=services \
-Sconfig-var=binding-id="${binding_id}" \
--dir "${SCRIPT_DIR:-.}/tests/testdata"::/ \
"${SCRIPT_DIR:-.}/lib/test/cli.wasm" \
"$@"
}
# create valkey service, capturing the instance_id from stdout
instance_id=$(componentized_services provision --type valkey)
# create read/write binding, capturing the binding_id from stdout
read_write_binding_id=$(componentized_services bind ${instance_id})
componentized_services credentials fetch ${read_write_binding_id}
# write and read a value
binding_id=${read_write_binding_id} componentized_services ops write greeting 'Hello World!'
binding_id=${read_write_binding_id} componentized_services ops read greeting
# create read-only binding, capturing the binding_id from stdout
read_only_binding_id=$(componentized_services bind ${instance_id} --scopes read)
componentized_services credentials fetch ${read_only_binding_id}
# can read previous values, but not write
binding_id=${read_only_binding_id} componentized_services ops read greeting
binding_id=${read_only_binding_id} componentized_services ops write greeting 'Uh oh!' || echo 'Previous command expected to fail'
# verify the key was not modified
binding_id=${read_only_binding_id} componentized_services ops read greeting
# cleanup
componentized_services unbind ${read_write_binding_id} ${instance_id}
componentized_services unbind ${read_only_binding_id} ${instance_id}
componentized_services destroy ${instance_id}