mirror of
https://github.com/logos-storage/nim-leveldb.git
synced 2026-01-05 23:23:12 +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 unittest, options, os, osproc, sequtils, strutils, sugar
|
||||||
import leveldb, leveldbpkg/raw
|
import leveldb, leveldbpkg/raw
|
||||||
|
|
||||||
|
const
|
||||||
|
tmpDir = "/tmp/testleveldb"
|
||||||
|
tmpNimbleDir = tmpDir / "nimble"
|
||||||
|
tmpDbDir = tmpDir / "testdb"
|
||||||
|
|
||||||
template cd*(dir: string, body: untyped) =
|
template cd*(dir: string, body: untyped) =
|
||||||
## Sets the current dir to ``dir``, executes ``body`` and restores the
|
## Sets the current dir to ``dir``, executes ``body`` and restores the
|
||||||
## previous working dir.
|
## previous working dir.
|
||||||
@ -11,7 +16,6 @@ template cd*(dir: string, body: untyped) =
|
|||||||
setCurrentDir(lastDir)
|
setCurrentDir(lastDir)
|
||||||
|
|
||||||
proc execNimble(args: varargs[string]): tuple[output: string, exitCode: int] =
|
proc execNimble(args: varargs[string]): tuple[output: string, exitCode: int] =
|
||||||
const tmpNimbleDir = "/tmp/testnimble"
|
|
||||||
var quotedArgs = @args
|
var quotedArgs = @args
|
||||||
quotedArgs.insert("-y")
|
quotedArgs.insert("-y")
|
||||||
quotedArgs.insert("--nimbleDir:" & tmpNimbleDir)
|
quotedArgs.insert("--nimbleDir:" & tmpNimbleDir)
|
||||||
@ -23,6 +27,21 @@ proc execNimble(args: varargs[string]): tuple[output: string, exitCode: int] =
|
|||||||
checkpoint(cmd)
|
checkpoint(cmd)
|
||||||
checkpoint(result.output)
|
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":
|
suite "leveldb":
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
@ -198,3 +217,38 @@ suite "package":
|
|||||||
checkpoint output
|
checkpoint output
|
||||||
check exitCode == QuitSuccess
|
check exitCode == QuitSuccess
|
||||||
check output.contains("leveldb works.")
|
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