Merge pull request #208 from meshplus/test/add-storages
test: add storages unittest
This commit is contained in:
commit
9b4a16b9a4
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue