mirror of
https://github.com/codex-storage/nim-leveldb.git
synced 2025-02-19 19:08:34 +00:00
test tool
This commit is contained in:
parent
713b036f98
commit
75ab9bbb47
@ -1,6 +1,11 @@
|
||||
import unittest, options, os, osproc, sequtils, strutils, sugar
|
||||
import leveldb, leveldbpkg/raw
|
||||
|
||||
const
|
||||
tmpDir = "/tmp/testleveldb"
|
||||
tmpNimbleDir = tmpDir / "nimble"
|
||||
tmpDbDir = tmpDir / "testdb"
|
||||
|
||||
template cd*(dir: string, body: untyped) =
|
||||
## Sets the current dir to ``dir``, executes ``body`` and restores the
|
||||
## previous working dir.
|
||||
@ -11,7 +16,6 @@ template cd*(dir: string, body: untyped) =
|
||||
setCurrentDir(lastDir)
|
||||
|
||||
proc execNimble(args: varargs[string]): tuple[output: string, exitCode: int] =
|
||||
const tmpNimbleDir = "/tmp/testnimble"
|
||||
var quotedArgs = @args
|
||||
quotedArgs.insert("-y")
|
||||
quotedArgs.insert("--nimbleDir:" & tmpNimbleDir)
|
||||
@ -23,6 +27,21 @@ proc execNimble(args: varargs[string]): tuple[output: string, exitCode: int] =
|
||||
checkpoint(cmd)
|
||||
checkpoint(result.output)
|
||||
|
||||
proc execTool(args: varargs[string]): tuple[output: string, exitCode: int] =
|
||||
var quotedArgs = @args
|
||||
quotedArgs.insert(tmpDbDir)
|
||||
quotedArgs.insert("--database")
|
||||
quotedArgs.insert(tmpNimbleDir / "bin" / "leveldb")
|
||||
quotedArgs = quotedArgs.map((x: string) => ("\"" & x & "\""))
|
||||
|
||||
if not existsDir(tmpDbDir):
|
||||
createDir(tmpDbDir)
|
||||
|
||||
let cmd = quotedArgs.join(" ")
|
||||
result = execCmdEx(cmd)
|
||||
checkpoint(cmd)
|
||||
checkpoint(result.output)
|
||||
|
||||
suite "leveldb":
|
||||
|
||||
setup:
|
||||
@ -198,3 +217,38 @@ suite "package":
|
||||
checkpoint output
|
||||
check exitCode == QuitSuccess
|
||||
check output.contains("leveldb works.")
|
||||
|
||||
suite "tool":
|
||||
|
||||
test "leveldb tool":
|
||||
var (output, exitCode) = execNimble("install")
|
||||
check exitCode == QuitSuccess
|
||||
check output.contains("Building")
|
||||
|
||||
check execTool("-v").exitCode == QuitSuccess
|
||||
check execTool("create").exitCode == QuitSuccess
|
||||
check execTool("list").exitCode == QuitSuccess
|
||||
|
||||
check execTool("put", "hello", "world").exitCode == QuitSuccess
|
||||
(output, exitCode) = execTool("get", "hello")
|
||||
check exitCode == QuitSuccess
|
||||
check output == "world\L"
|
||||
(output, exitCode) = execTool("list")
|
||||
check exitCode == QuitSuccess
|
||||
check output == "hello world\L"
|
||||
|
||||
check execTool("delete", "hello").exitCode == QuitSuccess
|
||||
(output, exitCode) = execTool("get", "hello")
|
||||
check exitCode == QuitSuccess
|
||||
check output == ""
|
||||
(output, exitCode) = execTool("list")
|
||||
check exitCode == QuitSuccess
|
||||
check output == ""
|
||||
|
||||
check execTool("put", "hello", "6130", "-x").exitCode == QuitSuccess
|
||||
check execTool("get", "hello", "-x").output == "6130\L"
|
||||
check execTool("get", "hello").output == "a0\L"
|
||||
check execTool("list", "-x").output == "hello 6130\L"
|
||||
check execTool("put", "hello", "0061", "-x").exitCode == QuitSuccess
|
||||
check execTool("get", "hello", "-x").output == "0061\L"
|
||||
check execTool("delete", "hello").exitCode == QuitSuccess
|
||||
|
Loading…
x
Reference in New Issue
Block a user