Add tests for query path routing

This commit is contained in:
Ethan Frey 2018-01-30 15:30:25 +01:00 committed by Ethan Buchman
parent bc325c4d1c
commit 512c601adc
2 changed files with 30 additions and 1 deletions

View File

@ -230,7 +230,7 @@ func parsePath(path string) (storeName string, subpath string, err sdk.Error) {
paths := strings.SplitN(path[1:], "/", 2)
storeName = paths[0]
if len(paths) == 2 {
subpath = paths[1]
subpath = "/" + paths[1]
}
return
}

View File

@ -20,6 +20,14 @@ func TestMultistoreCommitLoad(t *testing.T) {
commitID := CommitID{}
checkStore(t, store, commitID, commitID)
// make sure we can get stores by name
s1 := store.GetStoreByName("store1")
assert.NotNil(t, s1)
s3 := store.GetStoreByName("store3")
assert.NotNil(t, s3)
s77 := store.GetStoreByName("store77")
assert.Nil(t, s77)
// make a few commits and check them
nCommits := int64(3)
for i := int64(0); i < nCommits; i++ {
@ -62,6 +70,27 @@ func TestMultistoreCommitLoad(t *testing.T) {
checkStore(t, store, commitID, commitID)
}
func TestParsePath(t *testing.T) {
_, _, err := parsePath("foo")
assert.Error(t, err)
store, subpath, err := parsePath("/foo")
assert.NoError(t, err)
assert.Equal(t, store, "foo")
assert.Equal(t, subpath, "")
store, subpath, err = parsePath("/fizz/bang/baz")
assert.NoError(t, err)
assert.Equal(t, store, "fizz")
assert.Equal(t, subpath, "/bang/baz")
substore, subsubpath, err := parsePath(subpath)
assert.NoError(t, err)
assert.Equal(t, substore, "bang")
assert.Equal(t, subsubpath, "/baz")
}
//-----------------------------------------------------------------------
// utils