github.com/codingfuture/orig-energi3@v0.8.4/swarm/storage/mock/db/db_test.go (about)

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