diff --git a/internal/storages/storages.go b/internal/storages/storages.go index 92633c5..9e66b9c 100644 --- a/internal/storages/storages.go +++ b/internal/storages/storages.go @@ -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 } diff --git a/internal/storages/storages_test.go b/internal/storages/storages_test.go new file mode 100644 index 0000000..0003a94 --- /dev/null +++ b/internal/storages/storages_test.go @@ -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) +}