-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3477 from ipfs/test/multiple-different
Add multiple small tests
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |