Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple small tests #3477

Merged
merged 3 commits into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions blocks/bloom/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import (
"testing"
)

func TestBasicFilter(t *testing.T) {
f := BasicFilter().(*filter)

if len(f.filter) != 2048 {
t.Fatal("basic filter should have length 2048, has:", len(f.filter))
}
}

func TestFilter(t *testing.T) {
f := NewFilter(128)

Expand Down
20 changes: 20 additions & 0 deletions keystore/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ func TestKeystoreBasics(t *testing.T) {
}
}

func TestNonExistingKey(t *testing.T) {
tdir, err := ioutil.TempDir("", "keystore-test")
if err != nil {
t.Fatal(err)
}

ks, err := NewFSKeystore(tdir)
if err != nil {
t.Fatal(err)
}

k, err := ks.Get("does-it-exist")
if err != ErrNoSuchKey {
t.Fatalf("expected: %s, got %s", ErrNoSuchKey, err)
}
if k != nil {
t.Fatalf("Get on nonexistant key should give nil")
}
}

func TestMakeKeystoreNoDir(t *testing.T) {
_, err := NewFSKeystore("/this/is/not/a/real/dir")
if err == nil {
Expand Down
82 changes: 82 additions & 0 deletions keystore/memkeystore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package keystore

import (
"sort"
"testing"
)

func TestMemKeyStoreBasics(t *testing.T) {
ks := NewMemKeystore()

l, err := ks.List()
if err != nil {
t.Fatal(err)
}

if len(l) != 0 {
t.Fatal("expected no keys")
}

k1 := privKeyOrFatal(t)
k2 := privKeyOrFatal(t)
k3 := privKeyOrFatal(t)
k4 := privKeyOrFatal(t)

err = ks.Put("foo", k1)
if err != nil {
t.Fatal(err)
}

err = ks.Put("bar", k2)
if err != nil {
t.Fatal(err)
}

l, err = ks.List()
if err != nil {
t.Fatal(err)
}

sort.Strings(l)
if l[0] != "bar" || l[1] != "foo" {
t.Fatal("wrong entries listed")
}

err = ks.Put("foo", k3)
if err == nil {
t.Fatal("should not be able to overwrite key")
}
if err := ks.Delete("bar"); err != nil {
t.Fatal(err)
}
if err := ks.Put("beep", k3); err != nil {
t.Fatal(err)
}

if err := ks.Put("boop", k4); err != nil {
t.Fatal(err)
}
if err := assertGetKey(ks, "foo", k1); err != nil {
t.Fatal(err)
}

if err := assertGetKey(ks, "beep", k3); err != nil {
t.Fatal(err)
}

if err := assertGetKey(ks, "boop", k4); err != nil {
t.Fatal(err)
}

if err := ks.Put("..///foo/", k1); err == nil {
t.Fatal("shouldnt be able to put a poorly named key")
}

if err := ks.Put("", k1); err == nil {
t.Fatal("shouldnt be able to put a key with no name")
}

if err := ks.Put(".foo", k1); err == nil {
t.Fatal("shouldnt be able to put a key with a 'hidden' name")
}
}