Make getContent tests pass

This commit is contained in:
Oskar Thoren 2019-09-25 16:25:15 +08:00
parent 737ab57294
commit 2712b3ed38
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
1 changed files with 23 additions and 0 deletions

View File

@ -17,6 +17,15 @@ proc createContent*(s: string): vac_cas_Content =
quit(QuitFailure)
return content
proc createAddress*(s: string): vac_cas_Address =
var address = newvac_cas_Address()
try:
setid(address, hexToSeqByte(s))
except:
echo("Unable to create Address data")
quit(QuitFailure)
return address
let casClient = newCASClient("http://localhost:8001")
proc postContent(s: string): string =
@ -29,9 +38,23 @@ proc postContent(s: string): string =
except Exception as e:
echo(&"Exception: {e.msg}")
proc getContent(s: string): string =
echo("getContent s: <", s, ">")
var address = createAddress(s)
echo("getContent address: <", toHex(address.id), ">")
try:
let resp = Get(casClient, address)
let str = parseHexStr(toHex(resp.data))
echo(&"I got a new post: {str}")
return str
except Exception as e:
echo(&"Exception: {e.msg}")
when isMainModule:
echo("Running CAS tests")
doAssert 1 == 1
let id = postContent("hello")
echo("ID:", id)
let res = getContent(id)
echo("getContent res:", res)
# TODO: Run retrieve test on this ID