Merge pull request #208 from meshplus/test/add-storages

test: add storages unittest
This commit is contained in:
Aiden X 2020-10-20 13:31:19 +08:00 committed by GitHub
commit 9b4a16b9a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 2 deletions

View File

@ -32,10 +32,10 @@ func Initialize(repoRoot string) error {
}
func Get(name string) (storage.Storage, error) {
strg, ok := s.storages[name]
storage, ok := s.storages[name]
if !ok {
return nil, fmt.Errorf("wrong storage name")
}
return strg, nil
return storage, nil
}

View File

@ -0,0 +1,36 @@
package storages
import (
"io/ioutil"
"testing"
"github.com/stretchr/testify/require"
)
func TestInitialize(t *testing.T) {
dir, err := ioutil.TempDir("", "TestInitialize")
require.Nil(t, err)
err = Initialize(dir)
require.Nil(t, err)
// Initialize twice
err = Initialize(dir)
require.Contains(t, err.Error(), "create blockchain storage: resource temporarily unavailable")
}
func TestGet(t *testing.T) {
dir, err := ioutil.TempDir("", "TestGet")
require.Nil(t, err)
err = Initialize(dir)
require.Nil(t, err)
s, err := Get(BlockChain)
require.Nil(t, err)
require.NotNil(t, s)
s, err = Get("WrongName")
require.NotNil(t, err)
require.Nil(t, s)
}