-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtester.py
42 lines (37 loc) · 960 Bytes
/
tester.py
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
from pyfaasm.core import (
read_state,
read_state_offset,
write_state,
write_state_offset,
push_state,
pull_state,
set_emulator_message,
)
import json
msg = {
"user": "demo",
"function": "echo",
}
set_emulator_message(json.dumps(msg))
# Write and push state
key = "pyStateTest"
valueLen = 10
fullValue = b"0123456789"
write_state(key, fullValue)
push_state(key)
# Read state back in
pull_state(key, valueLen)
actual = read_state(key, valueLen)
print("In = {} out = {}".format(fullValue, actual))
# Update a segment
segment = b"999"
offset = 2
segmentLen = 3
modifiedValue = b"0199956789"
write_state_offset(key, valueLen, offset, segment)
push_state(key)
pull_state(key, valueLen)
actual = read_state(key, valueLen)
actualSegment = read_state_offset(key, valueLen, offset, segmentLen)
print("Expected = {} actual = {}".format(modifiedValue, actual))
print("Expected = {} actual = {}".format(segment, actualSegment))