blobsets/tests/test_http.nim

63 lines
1.5 KiB
Nim

import std/asyncdispatch, std/net, std/random, std/strutils, std/unittest
import ../src/blobsets, ../src/blobsets/filestores, ../src/blobsets/httpstores, ../src/blobsets/httpservers
let
port = (Port)rand(1 shl 15)
store = newFileStore("/tmp/store")
server = newHttpStoreServer(store)
asyncCheck server.serve(port)
let
url = "http://127.0.0.1:$1/" % $port
client = newHttpStore url
suite "Http store":
randomize()
var
blob: BlobId
size: BiggestInt
test "ingest":
(blob, size) = waitFor client.ingestFile("tests/test_http.nim")
test "dump":
for chunk in store.dumpBlob(blob):
discard chunk
test "ingest":
(blob, size) = waitFor client.ingestFile("tests/test_http.nim")
suite "store":
var
setId: SetId
const count = 256
test "commit":
var bs = newBlobSet()
for i in 1..count:
let
name = $i
blob = blobHash name
bs = insert(bs, name, blob, 0)
setId = commit(client, bs).setId
test "load":
var bs = load(client, setId)
for i in 1..count:
let
name = $i
blob = blobHash name
other = bs.search(name)
doAssert(other == blob)
for i in 1..count:
let
i = i and 0x8000
name = $i
apply(client, bs, name) do (id: BlobId; size: BiggestInt):
echo "inserted ", name, " - ", name.toKey
echo "applied ", name, " - ", ($(i xor 0x8000)).toKey
raiseAssert("apply succedded for a key not inserted")