DbArgs tests

This commit is contained in:
Taylor Gerring 2015-03-26 19:34:32 +01:00
parent 3ab9f26943
commit f68ca2b6e6
1 changed files with 79 additions and 0 deletions

View File

@ -737,6 +737,7 @@ func TestBlockFilterArgs(t *testing.T) {
}
func TestBlockFilterArgsWords(t *testing.T) {
t.Skip()
input := `[{
"fromBlock": "latest",
"toBlock": "pending"
@ -811,6 +812,84 @@ func TestDbArgs(t *testing.T) {
}
}
func TestDbArgsInvalid(t *testing.T) {
input := `{}`
args := new(DbArgs)
str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
if len(str) > 0 {
t.Error(str)
}
}
func TestDbArgsEmpty(t *testing.T) {
input := `[]`
args := new(DbArgs)
str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
if len(str) > 0 {
t.Error(str)
}
}
func TestDbArgsDatabaseType(t *testing.T) {
input := `[true, "keyval", "valval"]`
args := new(DbArgs)
str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
if len(str) > 0 {
t.Error(str)
}
}
func TestDbArgsKeyType(t *testing.T) {
input := `["dbval", 3, "valval"]`
args := new(DbArgs)
str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
if len(str) > 0 {
t.Error(str)
}
}
func TestDbArgsValType(t *testing.T) {
input := `["dbval", "keyval", {}]`
args := new(DbArgs)
str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
if len(str) > 0 {
t.Error(str)
}
}
func TestDbArgsDatabaseEmpty(t *testing.T) {
input := `["", "keyval", "valval"]`
args := new(DbArgs)
if err := json.Unmarshal([]byte(input), &args); err != nil {
t.Error(err.Error())
}
str := ExpectValidationError(args.requirements())
if len(str) > 0 {
t.Error(str)
}
}
func TestDbArgsKeyEmpty(t *testing.T) {
input := `["dbval", "", "valval"]`
args := new(DbArgs)
if err := json.Unmarshal([]byte(input), &args); err != nil {
t.Error(err.Error())
}
str := ExpectValidationError(args.requirements())
if len(str) > 0 {
t.Error(str)
}
}
func TestDbHexArgs(t *testing.T) {
input := `["testDB","myKey","0xbeef"]`
expected := new(DbHexArgs)