mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
test: use T.TempDir
to create temporary test directory
The directory created by `T.TempDir` is automatically removed when the test and all its subtests complete. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
5e814afe88
commit
b92df1654c
|
@ -13,8 +13,7 @@ import (
|
||||||
|
|
||||||
func TestCreateAndFind(t *testing.T) {
|
func TestCreateAndFind(t *testing.T) {
|
||||||
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
||||||
dir, _ := os.MkdirTemp("", "seaweedfs_filer_test")
|
dir := t.TempDir()
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
store := &LevelDBStore{}
|
store := &LevelDBStore{}
|
||||||
store.initialize(dir)
|
store.initialize(dir)
|
||||||
testFiler.SetStore(store)
|
testFiler.SetStore(store)
|
||||||
|
@ -67,8 +66,7 @@ func TestCreateAndFind(t *testing.T) {
|
||||||
|
|
||||||
func TestEmptyRoot(t *testing.T) {
|
func TestEmptyRoot(t *testing.T) {
|
||||||
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
||||||
dir, _ := os.MkdirTemp("", "seaweedfs_filer_test2")
|
dir := t.TempDir()
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
store := &LevelDBStore{}
|
store := &LevelDBStore{}
|
||||||
store.initialize(dir)
|
store.initialize(dir)
|
||||||
testFiler.SetStore(store)
|
testFiler.SetStore(store)
|
||||||
|
@ -90,8 +88,7 @@ func TestEmptyRoot(t *testing.T) {
|
||||||
|
|
||||||
func BenchmarkInsertEntry(b *testing.B) {
|
func BenchmarkInsertEntry(b *testing.B) {
|
||||||
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
||||||
dir, _ := os.MkdirTemp("", "seaweedfs_filer_bench")
|
dir := b.TempDir()
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
store := &LevelDBStore{}
|
store := &LevelDBStore{}
|
||||||
store.initialize(dir)
|
store.initialize(dir)
|
||||||
testFiler.SetStore(store)
|
testFiler.SetStore(store)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package leveldb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/filer"
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
||||||
|
@ -11,8 +10,7 @@ import (
|
||||||
|
|
||||||
func TestCreateAndFind(t *testing.T) {
|
func TestCreateAndFind(t *testing.T) {
|
||||||
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
||||||
dir, _ := os.MkdirTemp("", "seaweedfs_filer_test")
|
dir := t.TempDir()
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
store := &LevelDB2Store{}
|
store := &LevelDB2Store{}
|
||||||
store.initialize(dir, 2)
|
store.initialize(dir, 2)
|
||||||
testFiler.SetStore(store)
|
testFiler.SetStore(store)
|
||||||
|
@ -65,8 +63,7 @@ func TestCreateAndFind(t *testing.T) {
|
||||||
|
|
||||||
func TestEmptyRoot(t *testing.T) {
|
func TestEmptyRoot(t *testing.T) {
|
||||||
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
||||||
dir, _ := os.MkdirTemp("", "seaweedfs_filer_test2")
|
dir := t.TempDir()
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
store := &LevelDB2Store{}
|
store := &LevelDB2Store{}
|
||||||
store.initialize(dir, 2)
|
store.initialize(dir, 2)
|
||||||
testFiler.SetStore(store)
|
testFiler.SetStore(store)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package leveldb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/filer"
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
||||||
|
@ -11,8 +10,7 @@ import (
|
||||||
|
|
||||||
func TestCreateAndFind(t *testing.T) {
|
func TestCreateAndFind(t *testing.T) {
|
||||||
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
||||||
dir, _ := os.MkdirTemp("", "seaweedfs_filer_test")
|
dir := t.TempDir()
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
store := &LevelDB3Store{}
|
store := &LevelDB3Store{}
|
||||||
store.initialize(dir)
|
store.initialize(dir)
|
||||||
testFiler.SetStore(store)
|
testFiler.SetStore(store)
|
||||||
|
@ -65,8 +63,7 @@ func TestCreateAndFind(t *testing.T) {
|
||||||
|
|
||||||
func TestEmptyRoot(t *testing.T) {
|
func TestEmptyRoot(t *testing.T) {
|
||||||
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
testFiler := filer.NewFiler(nil, nil, "", "", "", "", nil)
|
||||||
dir, _ := os.MkdirTemp("", "seaweedfs_filer_test2")
|
dir := t.TempDir()
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
store := &LevelDB3Store{}
|
store := &LevelDB3Store{}
|
||||||
store.initialize(dir)
|
store.initialize(dir)
|
||||||
testFiler.SetStore(store)
|
testFiler.SetStore(store)
|
||||||
|
|
|
@ -16,8 +16,7 @@ import (
|
||||||
|
|
||||||
func TestCreateAndFind(t *testing.T) {
|
func TestCreateAndFind(t *testing.T) {
|
||||||
testFiler := filer.NewFiler(nil, nil, "", 0, "", "", "", nil)
|
testFiler := filer.NewFiler(nil, nil, "", 0, "", "", "", nil)
|
||||||
dir, _ := os.MkdirTemp("", "seaweedfs_filer_test")
|
dir := t.TempDir()
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
store := &RocksDBStore{}
|
store := &RocksDBStore{}
|
||||||
store.initialize(dir)
|
store.initialize(dir)
|
||||||
testFiler.SetStore(store)
|
testFiler.SetStore(store)
|
||||||
|
@ -70,8 +69,7 @@ func TestCreateAndFind(t *testing.T) {
|
||||||
|
|
||||||
func TestEmptyRoot(t *testing.T) {
|
func TestEmptyRoot(t *testing.T) {
|
||||||
testFiler := filer.NewFiler(nil, nil, "", 0, "", "", "", nil)
|
testFiler := filer.NewFiler(nil, nil, "", 0, "", "", "", nil)
|
||||||
dir, _ := os.MkdirTemp("", "seaweedfs_filer_test2")
|
dir := t.TempDir()
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
store := &RocksDBStore{}
|
store := &RocksDBStore{}
|
||||||
store.initialize(dir)
|
store.initialize(dir)
|
||||||
testFiler.SetStore(store)
|
testFiler.SetStore(store)
|
||||||
|
@ -93,8 +91,7 @@ func TestEmptyRoot(t *testing.T) {
|
||||||
|
|
||||||
func BenchmarkInsertEntry(b *testing.B) {
|
func BenchmarkInsertEntry(b *testing.B) {
|
||||||
testFiler := filer.NewFiler(nil, nil, "", 0, "", "", "", nil)
|
testFiler := filer.NewFiler(nil, nil, "", 0, "", "", "", nil)
|
||||||
dir, _ := os.MkdirTemp("", "seaweedfs_filer_bench")
|
dir := b.TempDir()
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
store := &RocksDBStore{}
|
store := &RocksDBStore{}
|
||||||
store.initialize(dir)
|
store.initialize(dir)
|
||||||
testFiler.SetStore(store)
|
testFiler.SetStore(store)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -62,11 +61,7 @@ func TestMakeDiff(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompaction(t *testing.T) {
|
func TestCompaction(t *testing.T) {
|
||||||
dir, err := os.MkdirTemp("", "example")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("temp dir creation: %v", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir) // clean up
|
|
||||||
|
|
||||||
v, err := NewVolume(dir, dir, "", 1, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, 0)
|
v, err := NewVolume(dir, dir, "", 1, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -12,11 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSearchVolumesWithDeletedNeedles(t *testing.T) {
|
func TestSearchVolumesWithDeletedNeedles(t *testing.T) {
|
||||||
dir, err := os.MkdirTemp("", "example")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("temp dir creation: %v", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir) // clean up
|
|
||||||
|
|
||||||
v, err := NewVolume(dir, dir, "", 1, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, 0)
|
v, err := NewVolume(dir, dir, "", 1, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,14 +4,11 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOnDisk(t *testing.T) {
|
func TestOnDisk(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
tmpDir, _ := os.MkdirTemp("", "c")
|
|
||||||
defer os.RemoveAll(tmpDir)
|
|
||||||
|
|
||||||
totalDiskSizeInKB := int64(32)
|
totalDiskSizeInKB := int64(32)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue