github.com/jincm/wesharechain@v0.0.0-20210122032815-1537409ce26a/chain/swarm/storage/mock/db/db_test.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package db 18 19 import ( 20 "io/ioutil" 21 "os" 22 "testing" 23 24 "github.com/ethereum/go-ethereum/swarm/storage/mock/test" 25 ) 26 27 // TestDBStore is running a test.MockStore tests 28 // using test.MockStore function. 29 func TestDBStore(t *testing.T) { 30 store, cleanup := newTestStore(t) 31 defer cleanup() 32 33 test.MockStore(t, store, 100) 34 } 35 36 // TestDBStoreListings is running test.MockStoreListings tests. 37 func TestDBStoreListings(t *testing.T) { 38 store, cleanup := newTestStore(t) 39 defer cleanup() 40 41 test.MockStoreListings(t, store, 1000) 42 } 43 44 // TestImportExport is running a test.ImportExport tests 45 // using test.MockStore function. 46 func TestImportExport(t *testing.T) { 47 store1, cleanup := newTestStore(t) 48 defer cleanup() 49 50 store2, cleanup := newTestStore(t) 51 defer cleanup() 52 53 test.ImportExport(t, store1, store2, 100) 54 } 55 56 // newTestStore creates a temporary GlobalStore 57 // that will be closed and data deleted when 58 // calling returned cleanup function. 59 func newTestStore(t *testing.T) (s *GlobalStore, cleanup func()) { 60 dir, err := ioutil.TempDir("", "swarm-mock-db-") 61 if err != nil { 62 t.Fatal(err) 63 } 64 65 s, err = NewGlobalStore(dir) 66 if err != nil { 67 os.RemoveAll(dir) 68 t.Fatal(err) 69 } 70 71 return s, func() { 72 s.Close() 73 os.RemoveAll(dir) 74 } 75 }