From 512c601adcfb4040a000c0948c5ba98941d4cd79 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 30 Jan 2018 15:30:25 +0100 Subject: [PATCH] Add tests for query path routing --- store/rootmultistore.go | 2 +- store/rootmultistore_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/store/rootmultistore.go b/store/rootmultistore.go index 3e6fde5c34..62131611b2 100644 --- a/store/rootmultistore.go +++ b/store/rootmultistore.go @@ -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 } diff --git a/store/rootmultistore_test.go b/store/rootmultistore_test.go index 99e9050628..d2cc44230d 100644 --- a/store/rootmultistore_test.go +++ b/store/rootmultistore_test.go @@ -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