CAS basic test mock

This commit is contained in:
Oskar Thoren 2019-09-21 20:16:38 +08:00
parent f92903f15b
commit ec0b3a85bc
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
4 changed files with 51 additions and 7 deletions

View File

@ -9,5 +9,10 @@ nsserver: src/nsserver.nim src/ns_service_pb.nim src/ns_service_twirp.nim
node: src/node.nim
nim c -o:bin/node src/node.nim
castest: tests/castest.nim
nim c --r o:bin/castest tests/castest.nim
test: castest
%_pb.nim %_twirp.nim: %.proto
nimtwirp_build -I:. --out:. $^

View File

@ -14,18 +14,21 @@ import remote_log_pb
import strutils
import byteutils
# CAS
var content = newvac_cas_Content()
try:
content.data = hexToSeqByte("foo".toHex())
except:
echo("Unable to create Content data")
quit(QuitFailure)
# CAS util
proc createContent*(s: string): vac_cas_Content =
var content = newvac_cas_Content()
try:
content.data = hexToSeqByte(s.toHex())
except:
echo("Unable to create Content data")
quit(QuitFailure)
return content
let casClient = newCASClient("http://localhost:8001")
# XXX: resp is wrong here
try:
let content = createContent("foo")
let resp = Add(casClient, content)
let str = parseHexStr(toHex(resp.id))
echo(&"I got a new post: {str}")

View File

@ -0,0 +1,35 @@
import cas_service_pb
import cas_service_twirp
import strutils
import byteutils
import strformat
# XXX: Hacky tests
# Can retrieve and post node
# CAS util
proc createContent*(s: string): vac_cas_Content =
var content = newvac_cas_Content()
try:
content.data = hexToSeqByte(s.toHex())
except:
echo("Unable to create Content data")
quit(QuitFailure)
return content
var content = createContent("hello")
let casClient = newCASClient("http://localhost:8001")
# XXX: resp is wrong here
try:
let resp = Add(casClient, content)
let str = parseHexStr(toHex(resp.id))
echo(&"I got a new post: {str}")
except Exception as e:
echo(&"Exception: {e.msg}")
when isMainModule:
echo("Running CAS tests")
doAssert 1 == 1
# doAssert 1 == 2

View File

@ -0,0 +1 @@
--path:"../src"