Add tests for query path routing
This commit is contained in:
parent
bc325c4d1c
commit
512c601adc
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user