github.com/FUSIONFoundation/efsn@v3.6.2-0.20200916075423-dbb5dd5d2cc7+incompatible/swarm/storage/mock/db/db_test.go (about)

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