github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/staking/patchstore_test.go (about) 1 // Copyright (c) 2019 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package staking 7 8 import ( 9 "os" 10 "path/filepath" 11 "testing" 12 13 "github.com/stretchr/testify/require" 14 ) 15 16 func TestInvalidDirectory(t *testing.T) { 17 require := require.New(t) 18 dir := filepath.Join(t.TempDir(), "invalid") 19 _, err := os.Create(dir) 20 require.NoError(err) 21 _, _, _, err = NewPatchStore(dir).Read(0) 22 require.ErrorContains(err, "not a directory") 23 } 24 25 func TestInvalidDirectory2(t *testing.T) { 26 require := require.New(t) 27 dir := t.TempDir() 28 require.NoError(os.Remove(dir)) 29 _, err := os.Stat(dir) 30 require.ErrorIs(err, os.ErrNotExist) 31 _, _, _, err = NewPatchStore(dir).Read(0) 32 require.ErrorContains(err, "no such file or directory") 33 } 34 35 func TestCorruptedData(t *testing.T) { 36 // TODO: add test for corrupted data 37 }