mirror of https://github.com/minio/minio.git
test: use `T.TempDir` to create temporary test directory (#15400)
This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `ioutil.TempDir` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
f23f442d33
commit
0a3b1ad4eb
|
@ -20,17 +20,11 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testBitrotReaderWriterAlgo(t *testing.T, bitrotAlgo BitrotAlgorithm) {
|
func testBitrotReaderWriterAlgo(t *testing.T, bitrotAlgo BitrotAlgorithm) {
|
||||||
tmpDir, err := ioutil.TempDir("", "")
|
tmpDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpDir)
|
|
||||||
|
|
||||||
volume := "testvol"
|
volume := "testvol"
|
||||||
filePath := "testfile"
|
filePath := "testfile"
|
||||||
|
@ -60,7 +54,9 @@ func testBitrotReaderWriterAlgo(t *testing.T, bitrotAlgo BitrotAlgorithm) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
writer.(io.Closer).Close()
|
if bw, ok := writer.(io.Closer); ok {
|
||||||
|
bw.Close()
|
||||||
|
}
|
||||||
|
|
||||||
reader := newBitrotReader(disk, nil, volume, filePath, 35, bitrotAlgo, bitrotWriterSum(writer), 10)
|
reader := newBitrotReader(disk, nil, volume, filePath, 35, bitrotAlgo, bitrotWriterSum(writer), 10)
|
||||||
b := make([]byte, 10)
|
b := make([]byte, 10)
|
||||||
|
@ -76,6 +72,9 @@ func testBitrotReaderWriterAlgo(t *testing.T, bitrotAlgo BitrotAlgorithm) {
|
||||||
if _, err = reader.ReadAt(b[:5], 30); err != nil {
|
if _, err = reader.ReadAt(b[:5], 30); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if br, ok := reader.(io.Closer); ok {
|
||||||
|
br.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAllBitrotAlgorithms(t *testing.T) {
|
func TestAllBitrotAlgorithms(t *testing.T) {
|
||||||
|
|
|
@ -37,11 +37,7 @@ func TestServerConfigMigrateV1(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Init Test config failed")
|
t.Fatalf("Init Test config failed")
|
||||||
}
|
}
|
||||||
rootPath, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
rootPath := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(rootPath)
|
|
||||||
globalConfigDir = &ConfigDir{path: rootPath}
|
globalConfigDir = &ConfigDir{path: rootPath}
|
||||||
|
|
||||||
globalObjLayerMutex.Lock()
|
globalObjLayerMutex.Lock()
|
||||||
|
@ -74,13 +70,7 @@ func TestServerConfigMigrateV1(t *testing.T) {
|
||||||
// Test if all migrate code returns nil when config file does not
|
// Test if all migrate code returns nil when config file does not
|
||||||
// exist
|
// exist
|
||||||
func TestServerConfigMigrateInexistentConfig(t *testing.T) {
|
func TestServerConfigMigrateInexistentConfig(t *testing.T) {
|
||||||
rootPath, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
globalConfigDir = &ConfigDir{path: t.TempDir()}
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(rootPath)
|
|
||||||
|
|
||||||
globalConfigDir = &ConfigDir{path: rootPath}
|
|
||||||
|
|
||||||
if err := migrateV2ToV3(); err != nil {
|
if err := migrateV2ToV3(); err != nil {
|
||||||
t.Fatal("migrate v2 to v3 should succeed when no config file is found")
|
t.Fatal("migrate v2 to v3 should succeed when no config file is found")
|
||||||
|
@ -164,11 +154,7 @@ func TestServerConfigMigrateInexistentConfig(t *testing.T) {
|
||||||
|
|
||||||
// Test if a config migration from v2 to v33 is successfully done
|
// Test if a config migration from v2 to v33 is successfully done
|
||||||
func TestServerConfigMigrateV2toV33(t *testing.T) {
|
func TestServerConfigMigrateV2toV33(t *testing.T) {
|
||||||
rootPath, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
rootPath := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(rootPath)
|
|
||||||
|
|
||||||
globalConfigDir = &ConfigDir{path: rootPath}
|
globalConfigDir = &ConfigDir{path: rootPath}
|
||||||
|
|
||||||
|
@ -234,11 +220,7 @@ func TestServerConfigMigrateV2toV33(t *testing.T) {
|
||||||
|
|
||||||
// Test if all migrate code returns error with corrupted config files
|
// Test if all migrate code returns error with corrupted config files
|
||||||
func TestServerConfigMigrateFaultyConfig(t *testing.T) {
|
func TestServerConfigMigrateFaultyConfig(t *testing.T) {
|
||||||
rootPath, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
rootPath := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(rootPath)
|
|
||||||
|
|
||||||
globalConfigDir = &ConfigDir{path: rootPath}
|
globalConfigDir = &ConfigDir{path: rootPath}
|
||||||
configPath := rootPath + SlashSeparator + minioConfigFile
|
configPath := rootPath + SlashSeparator + minioConfigFile
|
||||||
|
@ -331,35 +313,31 @@ func TestServerConfigMigrateFaultyConfig(t *testing.T) {
|
||||||
|
|
||||||
// Test if all migrate code returns error with corrupted config files
|
// Test if all migrate code returns error with corrupted config files
|
||||||
func TestServerConfigMigrateCorruptedConfig(t *testing.T) {
|
func TestServerConfigMigrateCorruptedConfig(t *testing.T) {
|
||||||
rootPath, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
rootPath := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(rootPath)
|
|
||||||
|
|
||||||
globalConfigDir = &ConfigDir{path: rootPath}
|
globalConfigDir = &ConfigDir{path: rootPath}
|
||||||
configPath := rootPath + SlashSeparator + minioConfigFile
|
configPath := rootPath + SlashSeparator + minioConfigFile
|
||||||
|
|
||||||
for i := 3; i <= 17; i++ {
|
for i := 3; i <= 17; i++ {
|
||||||
// Create a corrupted config file
|
// Create a corrupted config file
|
||||||
if err = ioutil.WriteFile(configPath, []byte(fmt.Sprintf("{ \"version\":\"%d\", \"credential\": { \"accessKey\": 1 } }", i)),
|
if err := ioutil.WriteFile(configPath, []byte(fmt.Sprintf("{ \"version\":\"%d\", \"credential\": { \"accessKey\": 1 } }", i)),
|
||||||
0o644); err != nil {
|
0o644); err != nil {
|
||||||
t.Fatal("Unexpected error: ", err)
|
t.Fatal("Unexpected error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test different migrate versions and be sure they are returning an error
|
// Test different migrate versions and be sure they are returning an error
|
||||||
if err = migrateConfig(); err == nil {
|
if err := migrateConfig(); err == nil {
|
||||||
t.Fatal("migrateConfig() should fail with a corrupted json")
|
t.Fatal("migrateConfig() should fail with a corrupted json")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a corrupted config file for version '2'.
|
// Create a corrupted config file for version '2'.
|
||||||
if err = ioutil.WriteFile(configPath, []byte("{ \"version\":\"2\", \"credentials\": { \"accessKeyId\": 1 } }"), 0o644); err != nil {
|
if err := ioutil.WriteFile(configPath, []byte("{ \"version\":\"2\", \"credentials\": { \"accessKeyId\": 1 } }"), 0o644); err != nil {
|
||||||
t.Fatal("Unexpected error: ", err)
|
t.Fatal("Unexpected error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test different migrate versions and be sure they are returning an error
|
// Test different migrate versions and be sure they are returning an error
|
||||||
if err = migrateConfig(); err == nil {
|
if err := migrateConfig(); err == nil {
|
||||||
t.Fatal("migrateConfig() should fail with a corrupted json")
|
t.Fatal("migrateConfig() should fail with a corrupted json")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -100,15 +99,11 @@ func TestDataUpdateTracker(t *testing.T) {
|
||||||
|
|
||||||
dut.Current.bf = dut.newBloomFilter()
|
dut.Current.bf = dut.newBloomFilter()
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "TestDataUpdateTracker")
|
tmpDir := t.TempDir()
|
||||||
|
err := os.MkdirAll(filepath.Dir(filepath.Join(tmpDir, dataUpdateTrackerFilename)), os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
err = os.MkdirAll(filepath.Dir(filepath.Join(tmpDir, dataUpdateTrackerFilename)), os.ModePerm)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpDir)
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
dut.start(ctx, tmpDir)
|
dut.start(ctx, tmpDir)
|
||||||
|
|
|
@ -35,12 +35,8 @@ type usageTestFile struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDataUsageUpdate(t *testing.T) {
|
func TestDataUsageUpdate(t *testing.T) {
|
||||||
base, err := ioutil.TempDir("", "TestDataUsageUpdate")
|
base := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Skip(err)
|
|
||||||
}
|
|
||||||
const bucket = "bucket"
|
const bucket = "bucket"
|
||||||
defer os.RemoveAll(base)
|
|
||||||
files := []usageTestFile{
|
files := []usageTestFile{
|
||||||
{name: "rootfile", size: 10000},
|
{name: "rootfile", size: 10000},
|
||||||
{name: "rootfile2", size: 10000},
|
{name: "rootfile2", size: 10000},
|
||||||
|
@ -251,12 +247,8 @@ func TestDataUsageUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDataUsageUpdatePrefix(t *testing.T) {
|
func TestDataUsageUpdatePrefix(t *testing.T) {
|
||||||
base, err := ioutil.TempDir("", "TestDataUpdateUsagePrefix")
|
base := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Skip(err)
|
|
||||||
}
|
|
||||||
scannerSleeper.Update(0, 0)
|
scannerSleeper.Update(0, 0)
|
||||||
defer os.RemoveAll(base)
|
|
||||||
files := []usageTestFile{
|
files := []usageTestFile{
|
||||||
{name: "bucket/rootfile", size: 10000},
|
{name: "bucket/rootfile", size: 10000},
|
||||||
{name: "bucket/rootfile2", size: 10000},
|
{name: "bucket/rootfile2", size: 10000},
|
||||||
|
@ -537,12 +529,8 @@ func generateUsageTestFiles(t *testing.T, base, bucket string, nFolders, nFiles,
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDataUsageCacheSerialize(t *testing.T) {
|
func TestDataUsageCacheSerialize(t *testing.T) {
|
||||||
base, err := ioutil.TempDir("", "TestDataUsageCacheSerialize")
|
base := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Skip(err)
|
|
||||||
}
|
|
||||||
const bucket = "abucket"
|
const bucket = "abucket"
|
||||||
defer os.RemoveAll(base)
|
|
||||||
files := []usageTestFile{
|
files := []usageTestFile{
|
||||||
{name: "rootfile", size: 10000},
|
{name: "rootfile", size: 10000},
|
||||||
{name: "rootfile2", size: 10000},
|
{name: "rootfile2", size: 10000},
|
||||||
|
|
|
@ -85,19 +85,17 @@ var erasureDecodeTests = []struct {
|
||||||
|
|
||||||
func TestErasureDecode(t *testing.T) {
|
func TestErasureDecode(t *testing.T) {
|
||||||
for i, test := range erasureDecodeTests {
|
for i, test := range erasureDecodeTests {
|
||||||
setup, err := newErasureTestSetup(test.dataBlocks, test.onDisks-test.dataBlocks, test.blocksize)
|
setup, err := newErasureTestSetup(t, test.dataBlocks, test.onDisks-test.dataBlocks, test.blocksize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test %d: failed to create test setup: %v", i, err)
|
t.Fatalf("Test %d: failed to create test setup: %v", i, err)
|
||||||
}
|
}
|
||||||
erasure, err := NewErasure(context.Background(), test.dataBlocks, test.onDisks-test.dataBlocks, test.blocksize)
|
erasure, err := NewErasure(context.Background(), test.dataBlocks, test.onDisks-test.dataBlocks, test.blocksize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
setup.Remove()
|
|
||||||
t.Fatalf("Test %d: failed to create ErasureStorage: %v", i, err)
|
t.Fatalf("Test %d: failed to create ErasureStorage: %v", i, err)
|
||||||
}
|
}
|
||||||
disks := setup.disks
|
disks := setup.disks
|
||||||
data := make([]byte, test.data)
|
data := make([]byte, test.data)
|
||||||
if _, err = io.ReadFull(crand.Reader, data); err != nil {
|
if _, err = io.ReadFull(crand.Reader, data); err != nil {
|
||||||
setup.Remove()
|
|
||||||
t.Fatalf("Test %d: failed to generate random test data: %v", i, err)
|
t.Fatalf("Test %d: failed to generate random test data: %v", i, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,11 +111,9 @@ func TestErasureDecode(t *testing.T) {
|
||||||
n, err := erasure.Encode(context.Background(), bytes.NewReader(data), writers, buffer, erasure.dataBlocks+1)
|
n, err := erasure.Encode(context.Background(), bytes.NewReader(data), writers, buffer, erasure.dataBlocks+1)
|
||||||
closeBitrotWriters(writers)
|
closeBitrotWriters(writers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
setup.Remove()
|
|
||||||
t.Fatalf("Test %d: failed to create erasure test file: %v", i, err)
|
t.Fatalf("Test %d: failed to create erasure test file: %v", i, err)
|
||||||
}
|
}
|
||||||
if n != test.data {
|
if n != test.data {
|
||||||
setup.Remove()
|
|
||||||
t.Fatalf("Test %d: failed to create erasure test file", i)
|
t.Fatalf("Test %d: failed to create erasure test file", i)
|
||||||
}
|
}
|
||||||
for i, w := range writers {
|
for i, w := range writers {
|
||||||
|
@ -195,7 +191,6 @@ func TestErasureDecode(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setup.Remove()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,12 +205,11 @@ func TestErasureDecodeRandomOffsetLength(t *testing.T) {
|
||||||
dataBlocks := 7
|
dataBlocks := 7
|
||||||
parityBlocks := 7
|
parityBlocks := 7
|
||||||
blockSize := int64(1 * humanize.MiByte)
|
blockSize := int64(1 * humanize.MiByte)
|
||||||
setup, err := newErasureTestSetup(dataBlocks, parityBlocks, blockSize)
|
setup, err := newErasureTestSetup(t, dataBlocks, parityBlocks, blockSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer setup.Remove()
|
|
||||||
disks := setup.disks
|
disks := setup.disks
|
||||||
erasure, err := NewErasure(context.Background(), dataBlocks, parityBlocks, blockSize)
|
erasure, err := NewErasure(context.Background(), dataBlocks, parityBlocks, blockSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -288,11 +282,10 @@ func TestErasureDecodeRandomOffsetLength(t *testing.T) {
|
||||||
// Benchmarks
|
// Benchmarks
|
||||||
|
|
||||||
func benchmarkErasureDecode(data, parity, dataDown, parityDown int, size int64, b *testing.B) {
|
func benchmarkErasureDecode(data, parity, dataDown, parityDown int, size int64, b *testing.B) {
|
||||||
setup, err := newErasureTestSetup(data, parity, blockSizeV2)
|
setup, err := newErasureTestSetup(b, data, parity, blockSizeV2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("failed to create test setup: %v", err)
|
b.Fatalf("failed to create test setup: %v", err)
|
||||||
}
|
}
|
||||||
defer setup.Remove()
|
|
||||||
disks := setup.disks
|
disks := setup.disks
|
||||||
erasure, err := NewErasure(context.Background(), data, parity, blockSizeV2)
|
erasure, err := NewErasure(context.Background(), data, parity, blockSizeV2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -87,21 +87,19 @@ var erasureEncodeTests = []struct {
|
||||||
|
|
||||||
func TestErasureEncode(t *testing.T) {
|
func TestErasureEncode(t *testing.T) {
|
||||||
for i, test := range erasureEncodeTests {
|
for i, test := range erasureEncodeTests {
|
||||||
setup, err := newErasureTestSetup(test.dataBlocks, test.onDisks-test.dataBlocks, test.blocksize)
|
setup, err := newErasureTestSetup(t, test.dataBlocks, test.onDisks-test.dataBlocks, test.blocksize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test %d: failed to create test setup: %v", i, err)
|
t.Fatalf("Test %d: failed to create test setup: %v", i, err)
|
||||||
}
|
}
|
||||||
disks := setup.disks
|
disks := setup.disks
|
||||||
erasure, err := NewErasure(context.Background(), test.dataBlocks, test.onDisks-test.dataBlocks, test.blocksize)
|
erasure, err := NewErasure(context.Background(), test.dataBlocks, test.onDisks-test.dataBlocks, test.blocksize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
setup.Remove()
|
|
||||||
t.Fatalf("Test %d: failed to create ErasureStorage: %v", i, err)
|
t.Fatalf("Test %d: failed to create ErasureStorage: %v", i, err)
|
||||||
}
|
}
|
||||||
buffer := make([]byte, test.blocksize, 2*test.blocksize)
|
buffer := make([]byte, test.blocksize, 2*test.blocksize)
|
||||||
|
|
||||||
data := make([]byte, test.data)
|
data := make([]byte, test.data)
|
||||||
if _, err = io.ReadFull(rand.Reader, data); err != nil {
|
if _, err = io.ReadFull(rand.Reader, data); err != nil {
|
||||||
setup.Remove()
|
|
||||||
t.Fatalf("Test %d: failed to generate random test data: %v", i, err)
|
t.Fatalf("Test %d: failed to generate random test data: %v", i, err)
|
||||||
}
|
}
|
||||||
writers := make([]io.Writer, len(disks))
|
writers := make([]io.Writer, len(disks))
|
||||||
|
@ -160,18 +158,16 @@ func TestErasureEncode(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setup.Remove()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Benchmarks
|
// Benchmarks
|
||||||
|
|
||||||
func benchmarkErasureEncode(data, parity, dataDown, parityDown int, size int64, b *testing.B) {
|
func benchmarkErasureEncode(data, parity, dataDown, parityDown int, size int64, b *testing.B) {
|
||||||
setup, err := newErasureTestSetup(data, parity, blockSizeV2)
|
setup, err := newErasureTestSetup(b, data, parity, blockSizeV2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("failed to create test setup: %v", err)
|
b.Fatalf("failed to create test setup: %v", err)
|
||||||
}
|
}
|
||||||
defer setup.Remove()
|
|
||||||
erasure, err := NewErasure(context.Background(), data, parity, blockSizeV2)
|
erasure, err := NewErasure(context.Background(), data, parity, blockSizeV2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("failed to create ErasureStorage: %v", err)
|
b.Fatalf("failed to create ErasureStorage: %v", err)
|
||||||
|
|
|
@ -70,19 +70,17 @@ func TestErasureHeal(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create some test data
|
// create some test data
|
||||||
setup, err := newErasureTestSetup(test.dataBlocks, test.disks-test.dataBlocks, test.blocksize)
|
setup, err := newErasureTestSetup(t, test.dataBlocks, test.disks-test.dataBlocks, test.blocksize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test %d: failed to setup Erasure environment: %v", i, err)
|
t.Fatalf("Test %d: failed to setup Erasure environment: %v", i, err)
|
||||||
}
|
}
|
||||||
disks := setup.disks
|
disks := setup.disks
|
||||||
erasure, err := NewErasure(context.Background(), test.dataBlocks, test.disks-test.dataBlocks, test.blocksize)
|
erasure, err := NewErasure(context.Background(), test.dataBlocks, test.disks-test.dataBlocks, test.blocksize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
setup.Remove()
|
|
||||||
t.Fatalf("Test %d: failed to create ErasureStorage: %v", i, err)
|
t.Fatalf("Test %d: failed to create ErasureStorage: %v", i, err)
|
||||||
}
|
}
|
||||||
data := make([]byte, test.size)
|
data := make([]byte, test.size)
|
||||||
if _, err = io.ReadFull(rand.Reader, data); err != nil {
|
if _, err = io.ReadFull(rand.Reader, data); err != nil {
|
||||||
setup.Remove()
|
|
||||||
t.Fatalf("Test %d: failed to create random test data: %v", i, err)
|
t.Fatalf("Test %d: failed to create random test data: %v", i, err)
|
||||||
}
|
}
|
||||||
buffer := make([]byte, test.blocksize, 2*test.blocksize)
|
buffer := make([]byte, test.blocksize, 2*test.blocksize)
|
||||||
|
@ -93,7 +91,6 @@ func TestErasureHeal(t *testing.T) {
|
||||||
_, err = erasure.Encode(context.Background(), bytes.NewReader(data), writers, buffer, erasure.dataBlocks+1)
|
_, err = erasure.Encode(context.Background(), bytes.NewReader(data), writers, buffer, erasure.dataBlocks+1)
|
||||||
closeBitrotWriters(writers)
|
closeBitrotWriters(writers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
setup.Remove()
|
|
||||||
t.Fatalf("Test %d: failed to create random test data: %v", i, err)
|
t.Fatalf("Test %d: failed to create random test data: %v", i, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +153,5 @@ func TestErasureHeal(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setup.Remove()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1073,10 +1073,7 @@ func TestGetObjectInlineNotInline(t *testing.T) {
|
||||||
// Create a backend with 4 disks named disk{1...4}, this name convention
|
// Create a backend with 4 disks named disk{1...4}, this name convention
|
||||||
// because we will unzip some object data from a sample archive.
|
// because we will unzip some object data from a sample archive.
|
||||||
const numDisks = 4
|
const numDisks = 4
|
||||||
path, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
path := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var fsDirs []string
|
var fsDirs []string
|
||||||
for i := 1; i <= numDisks; i++ {
|
for i := 1; i <= numDisks; i++ {
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -118,20 +117,13 @@ type erasureTestSetup struct {
|
||||||
disks []StorageAPI
|
disks []StorageAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes the temporary disk directories.
|
|
||||||
func (e erasureTestSetup) Remove() {
|
|
||||||
for _, path := range e.diskPaths {
|
|
||||||
os.RemoveAll(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns an initialized setup for erasure tests.
|
// Returns an initialized setup for erasure tests.
|
||||||
func newErasureTestSetup(dataBlocks int, parityBlocks int, blockSize int64) (*erasureTestSetup, error) {
|
func newErasureTestSetup(tb testing.TB, dataBlocks int, parityBlocks int, blockSize int64) (*erasureTestSetup, error) {
|
||||||
diskPaths := make([]string, dataBlocks+parityBlocks)
|
diskPaths := make([]string, dataBlocks+parityBlocks)
|
||||||
disks := make([]StorageAPI, len(diskPaths))
|
disks := make([]StorageAPI, len(diskPaths))
|
||||||
var err error
|
var err error
|
||||||
for i := range diskPaths {
|
for i := range diskPaths {
|
||||||
disks[i], diskPaths[i], err = newXLStorageTestSetup()
|
disks[i], diskPaths[i], err = newXLStorageTestSetup(tb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,11 +104,7 @@ func TestFormatErasureEmpty(t *testing.T) {
|
||||||
// Tests xl format migration.
|
// Tests xl format migration.
|
||||||
func TestFormatErasureMigrate(t *testing.T) {
|
func TestFormatErasureMigrate(t *testing.T) {
|
||||||
// Get test root.
|
// Get test root.
|
||||||
rootPath, err := getTestRoot()
|
rootPath := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(rootPath)
|
|
||||||
|
|
||||||
m := &formatErasureV1{}
|
m := &formatErasureV1{}
|
||||||
m.Format = formatBackendErasure
|
m.Format = formatBackendErasure
|
||||||
|
|
|
@ -30,11 +30,10 @@ import (
|
||||||
|
|
||||||
func TestFSRenameFile(t *testing.T) {
|
func TestFSRenameFile(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
_, path, err := newXLStorageTestSetup()
|
_, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
if err = fsMkdir(GlobalContext, pathJoin(path, "testvolume1")); err != nil {
|
if err = fsMkdir(GlobalContext, pathJoin(path, "testvolume1")); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -55,11 +54,10 @@ func TestFSRenameFile(t *testing.T) {
|
||||||
|
|
||||||
func TestFSStats(t *testing.T) {
|
func TestFSStats(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
_, path, err := newXLStorageTestSetup()
|
_, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
|
|
||||||
|
@ -183,11 +181,10 @@ func TestFSStats(t *testing.T) {
|
||||||
|
|
||||||
func TestFSCreateAndOpen(t *testing.T) {
|
func TestFSCreateAndOpen(t *testing.T) {
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
_, path, err := newXLStorageTestSetup()
|
_, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol")); err != nil {
|
if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol")); err != nil {
|
||||||
t.Fatalf("Unable to create directory, %s", err)
|
t.Fatalf("Unable to create directory, %s", err)
|
||||||
|
@ -248,11 +245,10 @@ func TestFSCreateAndOpen(t *testing.T) {
|
||||||
|
|
||||||
func TestFSDeletes(t *testing.T) {
|
func TestFSDeletes(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
_, path, err := newXLStorageTestSetup()
|
_, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol")); err != nil {
|
if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol")); err != nil {
|
||||||
|
@ -350,11 +346,10 @@ func TestFSDeletes(t *testing.T) {
|
||||||
|
|
||||||
func BenchmarkFSDeleteFile(b *testing.B) {
|
func BenchmarkFSDeleteFile(b *testing.B) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
_, path, err := newXLStorageTestSetup()
|
_, path, err := newXLStorageTestSetup(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("Unable to create xlStorage test setup, %s", err)
|
b.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
if err = fsMkdir(GlobalContext, pathJoin(path, "benchmark")); err != nil {
|
if err = fsMkdir(GlobalContext, pathJoin(path, "benchmark")); err != nil {
|
||||||
|
@ -384,11 +379,10 @@ func BenchmarkFSDeleteFile(b *testing.B) {
|
||||||
// Tests fs removes.
|
// Tests fs removes.
|
||||||
func TestFSRemoves(t *testing.T) {
|
func TestFSRemoves(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
_, path, err := newXLStorageTestSetup()
|
_, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol")); err != nil {
|
if err = fsMkdir(GlobalContext, pathJoin(path, "success-vol")); err != nil {
|
||||||
|
@ -501,11 +495,10 @@ func TestFSRemoves(t *testing.T) {
|
||||||
|
|
||||||
func TestFSRemoveMeta(t *testing.T) {
|
func TestFSRemoveMeta(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
_, fsPath, err := newXLStorageTestSetup()
|
_, fsPath, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(fsPath)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
if err = fsMkdir(GlobalContext, pathJoin(fsPath, "success-vol")); err != nil {
|
if err = fsMkdir(GlobalContext, pathJoin(fsPath, "success-vol")); err != nil {
|
||||||
|
@ -529,10 +522,7 @@ func TestFSRemoveMeta(t *testing.T) {
|
||||||
|
|
||||||
defer rwPool.Close(filePath)
|
defer rwPool.Close(filePath)
|
||||||
|
|
||||||
tmpDir, tmpErr := ioutil.TempDir(globalTestTmpDir, "minio-")
|
tmpDir := t.TempDir()
|
||||||
if tmpErr != nil {
|
|
||||||
t.Fatal(tmpErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := fsRemoveMeta(GlobalContext, fsPath, filePath, tmpDir); err != nil {
|
if err := fsRemoveMeta(GlobalContext, fsPath, filePath, tmpDir); err != nil {
|
||||||
t.Fatalf("Unable to remove file, %s", err)
|
t.Fatalf("Unable to remove file, %s", err)
|
||||||
|
@ -548,15 +538,9 @@ func TestFSRemoveMeta(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFSIsFile(t *testing.T) {
|
func TestFSIsFile(t *testing.T) {
|
||||||
dirPath, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
filePath := pathJoin(t.TempDir(), "tmpfile")
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unable to create tmp directory %s", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dirPath)
|
|
||||||
|
|
||||||
filePath := pathJoin(dirPath, "tmpfile")
|
if err := ioutil.WriteFile(filePath, nil, 0o777); err != nil {
|
||||||
|
|
||||||
if err = ioutil.WriteFile(filePath, nil, 0o777); err != nil {
|
|
||||||
t.Fatalf("Unable to create file %s", filePath)
|
t.Fatalf("Unable to create file %s", filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -48,11 +47,10 @@ func TestRWPoolLongPath(t *testing.T) {
|
||||||
// Tests all RWPool methods.
|
// Tests all RWPool methods.
|
||||||
func TestRWPool(t *testing.T) {
|
func TestRWPool(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
_, path, err := newXLStorageTestSetup()
|
_, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
rwPool := &fsIOPool{
|
rwPool := &fsIOPool{
|
||||||
readersMap: make(map[string]*lock.RLockedFile),
|
readersMap: make(map[string]*lock.RLockedFile),
|
||||||
|
|
|
@ -23,8 +23,6 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -1886,18 +1884,14 @@ func initFSObjectsB(disk string, t *testing.B) (obj ObjectLayer) {
|
||||||
// BenchmarkListObjects - Run ListObject Repeatedly and benchmark.
|
// BenchmarkListObjects - Run ListObject Repeatedly and benchmark.
|
||||||
func BenchmarkListObjects(b *testing.B) {
|
func BenchmarkListObjects(b *testing.B) {
|
||||||
// Make a temporary directory to use as the obj.
|
// Make a temporary directory to use as the obj.
|
||||||
directory, err := ioutil.TempDir(globalTestTmpDir, "minio-list-benchmark")
|
directory := b.TempDir()
|
||||||
if err != nil {
|
|
||||||
b.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(directory)
|
|
||||||
|
|
||||||
// Create the obj.
|
// Create the obj.
|
||||||
obj := initFSObjectsB(directory, b)
|
obj := initFSObjectsB(directory, b)
|
||||||
|
|
||||||
bucket := "ls-benchmark-bucket"
|
bucket := "ls-benchmark-bucket"
|
||||||
// Create a bucket.
|
// Create a bucket.
|
||||||
err = obj.MakeBucketWithLocation(context.Background(), bucket, BucketOptions{})
|
err := obj.MakeBucketWithLocation(context.Background(), bucket, BucketOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,25 +67,16 @@ type result struct {
|
||||||
entries []string
|
entries []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustSetupDir(t *testing.T) string {
|
|
||||||
// Create unique test directory.
|
|
||||||
dir, err := ioutil.TempDir(globalTestTmpDir, "minio-list-dir")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unable to setup directory, %s", err)
|
|
||||||
}
|
|
||||||
return dir
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test to read empty directory.
|
// Test to read empty directory.
|
||||||
func setupTestReadDirEmpty(t *testing.T) (testResults []result) {
|
func setupTestReadDirEmpty(t *testing.T) (testResults []result) {
|
||||||
// Add empty entry slice for this test directory.
|
// Add empty entry slice for this test directory.
|
||||||
testResults = append(testResults, result{mustSetupDir(t), []string{}})
|
testResults = append(testResults, result{t.TempDir(), []string{}})
|
||||||
return testResults
|
return testResults
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test to read non-empty directory with only files.
|
// Test to read non-empty directory with only files.
|
||||||
func setupTestReadDirFiles(t *testing.T) (testResults []result) {
|
func setupTestReadDirFiles(t *testing.T) (testResults []result) {
|
||||||
dir := mustSetupDir(t)
|
dir := t.TempDir()
|
||||||
entries := []string{}
|
entries := []string{}
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
name := fmt.Sprintf("file-%d", i)
|
name := fmt.Sprintf("file-%d", i)
|
||||||
|
@ -107,7 +98,7 @@ func setupTestReadDirFiles(t *testing.T) (testResults []result) {
|
||||||
|
|
||||||
// Test to read non-empty directory with directories and files.
|
// Test to read non-empty directory with directories and files.
|
||||||
func setupTestReadDirGeneric(t *testing.T) (testResults []result) {
|
func setupTestReadDirGeneric(t *testing.T) (testResults []result) {
|
||||||
dir := mustSetupDir(t)
|
dir := t.TempDir()
|
||||||
if err := os.MkdirAll(filepath.Join(dir, "mydir"), 0o777); err != nil {
|
if err := os.MkdirAll(filepath.Join(dir, "mydir"), 0o777); err != nil {
|
||||||
t.Fatalf("Unable to create prefix directory \"mydir\", %s", err)
|
t.Fatalf("Unable to create prefix directory \"mydir\", %s", err)
|
||||||
}
|
}
|
||||||
|
@ -134,7 +125,7 @@ func setupTestReadDirSymlink(t *testing.T) (testResults []result) {
|
||||||
t.Skip("symlinks not available on windows")
|
t.Skip("symlinks not available on windows")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
dir := mustSetupDir(t)
|
dir := t.TempDir()
|
||||||
entries := []string{}
|
entries := []string{}
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
name1 := fmt.Sprintf("file-%d", i)
|
name1 := fmt.Sprintf("file-%d", i)
|
||||||
|
@ -241,7 +232,7 @@ func TestReadDirN(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
dir := mustSetupDir(t)
|
dir := t.TempDir()
|
||||||
|
|
||||||
for c := 1; c <= testCase.numFiles; c++ {
|
for c := 1; c <= testCase.numFiles; c++ {
|
||||||
err := ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("%d", c)), []byte{}, os.ModePerm)
|
err := ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("%d", c)), []byte{}, os.ModePerm)
|
||||||
|
|
|
@ -18,18 +18,16 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tests - mkdirAll()
|
// Tests - mkdirAll()
|
||||||
func TestOSMkdirAll(t *testing.T) {
|
func TestOSMkdirAll(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
_, path, err := newXLStorageTestSetup()
|
_, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
if err = mkdirAll("", 0o777); err != errInvalidArgument {
|
if err = mkdirAll("", 0o777); err != errInvalidArgument {
|
||||||
t.Fatal("Unexpected error", err)
|
t.Fatal("Unexpected error", err)
|
||||||
|
@ -47,11 +45,10 @@ func TestOSMkdirAll(t *testing.T) {
|
||||||
// Tests - renameAll()
|
// Tests - renameAll()
|
||||||
func TestOSRenameAll(t *testing.T) {
|
func TestOSRenameAll(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
_, path, err := newXLStorageTestSetup()
|
_, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
if err = mkdirAll(pathJoin(path, "testvolume1"), 0o777); err != nil {
|
if err = mkdirAll(pathJoin(path, "testvolume1"), 0o777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -20,9 +20,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -439,25 +437,21 @@ func testStorageAPIRenameFile(t *testing.T, storage StorageAPI) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStorageRESTHTTPServerClient(t *testing.T) (*httptest.Server, *storageRESTClient, string) {
|
func newStorageRESTHTTPServerClient(t *testing.T) *storageRESTClient {
|
||||||
prevHost, prevPort := globalMinioHost, globalMinioPort
|
prevHost, prevPort := globalMinioHost, globalMinioPort
|
||||||
defer func() {
|
defer func() {
|
||||||
globalMinioHost, globalMinioPort = prevHost, prevPort
|
globalMinioHost, globalMinioPort = prevHost, prevPort
|
||||||
}()
|
}()
|
||||||
|
|
||||||
endpointPath, err := ioutil.TempDir("", ".TestStorageREST.")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
httpServer := httptest.NewServer(router)
|
httpServer := httptest.NewServer(router)
|
||||||
|
t.Cleanup(httpServer.Close)
|
||||||
|
|
||||||
url, err := xnet.ParseHTTPURL(httpServer.URL)
|
url, err := xnet.ParseHTTPURL(httpServer.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error %v", err)
|
t.Fatalf("unexpected error %v", err)
|
||||||
}
|
}
|
||||||
url.Path = endpointPath
|
url.Path = t.TempDir()
|
||||||
|
|
||||||
globalMinioHost, globalMinioPort = mustSplitHostPort(url.Host)
|
globalMinioHost, globalMinioPort = mustSplitHostPort(url.Host)
|
||||||
|
|
||||||
|
@ -476,101 +470,77 @@ func newStorageRESTHTTPServerClient(t *testing.T) (*httptest.Server, *storageRES
|
||||||
|
|
||||||
restClient := newStorageRESTClient(endpoint, false)
|
restClient := newStorageRESTClient(endpoint, false)
|
||||||
|
|
||||||
return httpServer, restClient, endpointPath
|
return restClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientDiskInfo(t *testing.T) {
|
func TestStorageRESTClientDiskInfo(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIDiskInfo(t, restClient)
|
testStorageAPIDiskInfo(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientMakeVol(t *testing.T) {
|
func TestStorageRESTClientMakeVol(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIMakeVol(t, restClient)
|
testStorageAPIMakeVol(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientListVols(t *testing.T) {
|
func TestStorageRESTClientListVols(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIListVols(t, restClient)
|
testStorageAPIListVols(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientStatVol(t *testing.T) {
|
func TestStorageRESTClientStatVol(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIStatVol(t, restClient)
|
testStorageAPIStatVol(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientDeleteVol(t *testing.T) {
|
func TestStorageRESTClientDeleteVol(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIDeleteVol(t, restClient)
|
testStorageAPIDeleteVol(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientStatInfoFile(t *testing.T) {
|
func TestStorageRESTClientStatInfoFile(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIStatInfoFile(t, restClient)
|
testStorageAPIStatInfoFile(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientListDir(t *testing.T) {
|
func TestStorageRESTClientListDir(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIListDir(t, restClient)
|
testStorageAPIListDir(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientReadAll(t *testing.T) {
|
func TestStorageRESTClientReadAll(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIReadAll(t, restClient)
|
testStorageAPIReadAll(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientReadFile(t *testing.T) {
|
func TestStorageRESTClientReadFile(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIReadFile(t, restClient)
|
testStorageAPIReadFile(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientAppendFile(t *testing.T) {
|
func TestStorageRESTClientAppendFile(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIAppendFile(t, restClient)
|
testStorageAPIAppendFile(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientDeleteFile(t *testing.T) {
|
func TestStorageRESTClientDeleteFile(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIDeleteFile(t, restClient)
|
testStorageAPIDeleteFile(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRESTClientRenameFile(t *testing.T) {
|
func TestStorageRESTClientRenameFile(t *testing.T) {
|
||||||
httpServer, restClient, endpointPath := newStorageRESTHTTPServerClient(t)
|
restClient := newStorageRESTHTTPServerClient(t)
|
||||||
defer httpServer.Close()
|
|
||||||
defer os.RemoveAll(endpointPath)
|
|
||||||
|
|
||||||
testStorageAPIRenameFile(t, restClient)
|
testStorageAPIRenameFile(t, restClient)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1452,11 +1452,6 @@ func getListenNotificationURL(endPoint, bucketName string, prefixes, suffixes, e
|
||||||
return makeTestTargetURL(endPoint, bucketName, "", queryValue)
|
return makeTestTargetURL(endPoint, bucketName, "", queryValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns temp root directory. `
|
|
||||||
func getTestRoot() (string, error) {
|
|
||||||
return ioutil.TempDir(globalTestTmpDir, "api-")
|
|
||||||
}
|
|
||||||
|
|
||||||
// getRandomDisks - Creates a slice of N random disks, each of the form - minio-XXX
|
// getRandomDisks - Creates a slice of N random disks, each of the form - minio-XXX
|
||||||
func getRandomDisks(N int) ([]string, error) {
|
func getRandomDisks(N int) ([]string, error) {
|
||||||
var erasureDisks []string
|
var erasureDisks []string
|
||||||
|
|
|
@ -20,8 +20,6 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -137,11 +135,7 @@ func testTreeWalkMarker(t *testing.T, listDir ListDirFunc, isLeaf IsLeafFunc, is
|
||||||
|
|
||||||
// Test tree-walk.
|
// Test tree-walk.
|
||||||
func TestTreeWalk(t *testing.T) {
|
func TestTreeWalk(t *testing.T) {
|
||||||
fsDir, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
fsDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unable to create tmp directory: %s", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(fsDir)
|
|
||||||
|
|
||||||
endpoints := mustGetNewEndpoints(fsDir)
|
endpoints := mustGetNewEndpoints(fsDir)
|
||||||
disk, err := newStorageAPI(endpoints[0])
|
disk, err := newStorageAPI(endpoints[0])
|
||||||
|
@ -181,11 +175,7 @@ func TestTreeWalk(t *testing.T) {
|
||||||
|
|
||||||
// Test if tree walk go-routine exits cleanly if tree walk is aborted because of timeout.
|
// Test if tree walk go-routine exits cleanly if tree walk is aborted because of timeout.
|
||||||
func TestTreeWalkTimeout(t *testing.T) {
|
func TestTreeWalkTimeout(t *testing.T) {
|
||||||
fsDir, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
fsDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unable to create tmp directory: %s", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(fsDir)
|
|
||||||
endpoints := mustGetNewEndpoints(fsDir)
|
endpoints := mustGetNewEndpoints(fsDir)
|
||||||
disk, err := newStorageAPI(endpoints[0])
|
disk, err := newStorageAPI(endpoints[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -254,11 +244,7 @@ func TestTreeWalkTimeout(t *testing.T) {
|
||||||
// without recursively traversing prefixes.
|
// without recursively traversing prefixes.
|
||||||
func TestRecursiveTreeWalk(t *testing.T) {
|
func TestRecursiveTreeWalk(t *testing.T) {
|
||||||
// Create a backend directories fsDir1.
|
// Create a backend directories fsDir1.
|
||||||
fsDir1, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
fsDir1 := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unable to create tmp directory: %s", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(fsDir1)
|
|
||||||
|
|
||||||
endpoints := mustGetNewEndpoints(fsDir1)
|
endpoints := mustGetNewEndpoints(fsDir1)
|
||||||
disk1, err := newStorageAPI(endpoints[0])
|
disk1, err := newStorageAPI(endpoints[0])
|
||||||
|
@ -365,11 +351,7 @@ func TestRecursiveTreeWalk(t *testing.T) {
|
||||||
|
|
||||||
func TestSortedness(t *testing.T) {
|
func TestSortedness(t *testing.T) {
|
||||||
// Create a backend directories fsDir1.
|
// Create a backend directories fsDir1.
|
||||||
fsDir1, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
fsDir1 := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Unable to create tmp directory: %s", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(fsDir1)
|
|
||||||
|
|
||||||
endpoints := mustGetNewEndpoints(fsDir1)
|
endpoints := mustGetNewEndpoints(fsDir1)
|
||||||
disk1, err := newStorageAPI(endpoints[0])
|
disk1, err := newStorageAPI(endpoints[0])
|
||||||
|
@ -440,11 +422,7 @@ func TestSortedness(t *testing.T) {
|
||||||
|
|
||||||
func TestTreeWalkIsEnd(t *testing.T) {
|
func TestTreeWalkIsEnd(t *testing.T) {
|
||||||
// Create a backend directories fsDir1.
|
// Create a backend directories fsDir1.
|
||||||
fsDir1, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
fsDir1 := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Unable to create tmp directory: %s", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(fsDir1)
|
|
||||||
|
|
||||||
endpoints := mustGetNewEndpoints(fsDir1)
|
endpoints := mustGetNewEndpoints(fsDir1)
|
||||||
disk1, err := newStorageAPI(endpoints[0])
|
disk1, err := newStorageAPI(endpoints[0])
|
||||||
|
|
|
@ -117,11 +117,8 @@ func TestIsValidVolname(t *testing.T) {
|
||||||
|
|
||||||
// creates a temp dir and sets up xlStorage layer.
|
// creates a temp dir and sets up xlStorage layer.
|
||||||
// returns xlStorage layer, temp dir path to be used for the purpose of tests.
|
// returns xlStorage layer, temp dir path to be used for the purpose of tests.
|
||||||
func newXLStorageTestSetup() (*xlStorageDiskIDCheck, string, error) {
|
func newXLStorageTestSetup(tb testing.TB) (*xlStorageDiskIDCheck, string, error) {
|
||||||
diskPath, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
diskPath := tb.TempDir()
|
||||||
if err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize a new xlStorage layer.
|
// Initialize a new xlStorage layer.
|
||||||
storage, err := newLocalXLStorage(diskPath)
|
storage, err := newLocalXLStorage(diskPath)
|
||||||
|
@ -141,64 +138,37 @@ func newXLStorageTestSetup() (*xlStorageDiskIDCheck, string, error) {
|
||||||
|
|
||||||
// createPermDeniedFile - creates temporary directory and file with path '/mybucket/myobject'
|
// createPermDeniedFile - creates temporary directory and file with path '/mybucket/myobject'
|
||||||
func createPermDeniedFile(t *testing.T) (permDeniedDir string) {
|
func createPermDeniedFile(t *testing.T) (permDeniedDir string) {
|
||||||
var errMsg string
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if errMsg == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if permDeniedDir != "" {
|
|
||||||
os.RemoveAll(permDeniedDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Fatalf(errMsg)
|
|
||||||
}()
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if permDeniedDir, err = ioutil.TempDir(globalTestTmpDir, "minio-"); err != nil {
|
permDeniedDir = t.TempDir()
|
||||||
errMsg = fmt.Sprintf("Unable to create temporary directory. %v", err)
|
|
||||||
return permDeniedDir
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = os.Mkdir(slashpath.Join(permDeniedDir, "mybucket"), 0o775); err != nil {
|
if err = os.Mkdir(slashpath.Join(permDeniedDir, "mybucket"), 0o775); err != nil {
|
||||||
errMsg = fmt.Sprintf("Unable to create temporary directory %v. %v", slashpath.Join(permDeniedDir, "mybucket"), err)
|
t.Fatalf(fmt.Sprintf("Unable to create temporary directory %v. %v", slashpath.Join(permDeniedDir, "mybucket"), err))
|
||||||
return permDeniedDir
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = ioutil.WriteFile(slashpath.Join(permDeniedDir, "mybucket", "myobject"), []byte(""), 0o400); err != nil {
|
if err = ioutil.WriteFile(slashpath.Join(permDeniedDir, "mybucket", "myobject"), []byte(""), 0o400); err != nil {
|
||||||
errMsg = fmt.Sprintf("Unable to create file %v. %v", slashpath.Join(permDeniedDir, "mybucket", "myobject"), err)
|
t.Fatalf(fmt.Sprintf("Unable to create file %v. %v", slashpath.Join(permDeniedDir, "mybucket", "myobject"), err))
|
||||||
return permDeniedDir
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.Chmod(slashpath.Join(permDeniedDir, "mybucket"), 0o400); err != nil {
|
if err = os.Chmod(slashpath.Join(permDeniedDir, "mybucket"), 0o400); err != nil {
|
||||||
errMsg = fmt.Sprintf("Unable to change permission to temporary directory %v. %v", slashpath.Join(permDeniedDir, "mybucket"), err)
|
t.Fatalf(fmt.Sprintf("Unable to change permission to temporary directory %v. %v", slashpath.Join(permDeniedDir, "mybucket"), err))
|
||||||
return permDeniedDir
|
|
||||||
}
|
}
|
||||||
|
t.Cleanup(func() {
|
||||||
|
os.Chmod(slashpath.Join(permDeniedDir, "mybucket"), 0o775)
|
||||||
|
})
|
||||||
|
|
||||||
if err = os.Chmod(permDeniedDir, 0o400); err != nil {
|
if err = os.Chmod(permDeniedDir, 0o400); err != nil {
|
||||||
errMsg = fmt.Sprintf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err)
|
t.Fatalf(fmt.Sprintf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err))
|
||||||
}
|
}
|
||||||
|
t.Cleanup(func() {
|
||||||
|
os.Chmod(permDeniedDir, 0o775)
|
||||||
|
})
|
||||||
|
|
||||||
return permDeniedDir
|
return permDeniedDir
|
||||||
}
|
}
|
||||||
|
|
||||||
// removePermDeniedFile - removes temporary directory and file with path '/mybucket/myobject'
|
|
||||||
func removePermDeniedFile(permDeniedDir string) {
|
|
||||||
if err := os.Chmod(permDeniedDir, 0o775); err == nil {
|
|
||||||
if err = os.Chmod(slashpath.Join(permDeniedDir, "mybucket"), 0o775); err == nil {
|
|
||||||
os.RemoveAll(permDeniedDir)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestXLStorages xlStorage.getDiskInfo()
|
// TestXLStorages xlStorage.getDiskInfo()
|
||||||
func TestXLStorageGetDiskInfo(t *testing.T) {
|
func TestXLStorageGetDiskInfo(t *testing.T) {
|
||||||
path, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
path := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unable to create a temporary directory, %s", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
diskPath string
|
diskPath string
|
||||||
|
@ -217,11 +187,7 @@ func TestXLStorageGetDiskInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestXLStorageIsDirEmpty(t *testing.T) {
|
func TestXLStorageIsDirEmpty(t *testing.T) {
|
||||||
tmp, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
tmp := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmp)
|
|
||||||
|
|
||||||
// Should give false on non-existent directory.
|
// Should give false on non-existent directory.
|
||||||
dir1 := slashpath.Join(tmp, "non-existent-directory")
|
dir1 := slashpath.Join(tmp, "non-existent-directory")
|
||||||
|
@ -231,7 +197,7 @@ func TestXLStorageIsDirEmpty(t *testing.T) {
|
||||||
|
|
||||||
// Should give false for not-a-directory.
|
// Should give false for not-a-directory.
|
||||||
dir2 := slashpath.Join(tmp, "file")
|
dir2 := slashpath.Join(tmp, "file")
|
||||||
err = ioutil.WriteFile(dir2, []byte("hello"), 0o777)
|
err := ioutil.WriteFile(dir2, []byte("hello"), 0o777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -256,13 +222,11 @@ func TestXLStorageReadVersionLegacy(t *testing.T) {
|
||||||
const legacyJSON = `{"version":"1.0.1","format":"xl","stat":{"size":2016,"modTime":"2021-10-11T23:40:34.914361617Z"},"erasure":{"algorithm":"klauspost/reedsolomon/vandermonde","data":2,"parity":2,"blockSize":10485760,"index":2,"distribution":[2,3,4,1],"checksum":[{"name":"part.1","algorithm":"highwayhash256S"}]},"minio":{"release":"RELEASE.2019-12-30T05-45-39Z"},"meta":{"X-Minio-Internal-Server-Side-Encryption-Iv":"kInsJB/0yxyz/40ZI+lmQYJfZacDYqZsGh2wEiv+N50=","X-Minio-Internal-Server-Side-Encryption-S3-Kms-Key-Id":"my-minio-key","X-Minio-Internal-Server-Side-Encryption-S3-Kms-Sealed-Key":"eyJhZWFkIjoiQUVTLTI1Ni1HQ00tSE1BQy1TSEEtMjU2IiwiaWQiOiJjMzEwNDVjODFmMTA2MWU5NTI4ODcxZmNhMmRkYzA3YyIsIml2IjoiOWQ5cUxGMFhSaFBXbEVqT2JDMmo0QT09Iiwibm9uY2UiOiJYaERsemlCU1cwSENuK2RDIiwiYnl0ZXMiOiJUM0lmY1haQ1dtMWpLeWxBWmFUUnczbDVoYldLWW95dm5iNTZVaWJEbE5LOFZVU2tuQmx3NytIMG8yZnRzZ1UrIn0=","X-Minio-Internal-Server-Side-Encryption-S3-Sealed-Key":"IAAfANqt801MT+wwzQRkfFhTrndmhfNiN0alKwDS4AQ1dznNADRQgoq6I4pPVfRsbDp5rQawlripQZvPWUSNJA==","X-Minio-Internal-Server-Side-Encryption-Seal-Algorithm":"DAREv2-HMAC-SHA256","content-type":"application/octet-stream","etag":"20000f00cf5e68d3d6b60e44fcd8b9e8-1"},"parts":[{"number":1,"name":"part.1","etag":"","size":2016,"actualSize":1984}]}`
|
const legacyJSON = `{"version":"1.0.1","format":"xl","stat":{"size":2016,"modTime":"2021-10-11T23:40:34.914361617Z"},"erasure":{"algorithm":"klauspost/reedsolomon/vandermonde","data":2,"parity":2,"blockSize":10485760,"index":2,"distribution":[2,3,4,1],"checksum":[{"name":"part.1","algorithm":"highwayhash256S"}]},"minio":{"release":"RELEASE.2019-12-30T05-45-39Z"},"meta":{"X-Minio-Internal-Server-Side-Encryption-Iv":"kInsJB/0yxyz/40ZI+lmQYJfZacDYqZsGh2wEiv+N50=","X-Minio-Internal-Server-Side-Encryption-S3-Kms-Key-Id":"my-minio-key","X-Minio-Internal-Server-Side-Encryption-S3-Kms-Sealed-Key":"eyJhZWFkIjoiQUVTLTI1Ni1HQ00tSE1BQy1TSEEtMjU2IiwiaWQiOiJjMzEwNDVjODFmMTA2MWU5NTI4ODcxZmNhMmRkYzA3YyIsIml2IjoiOWQ5cUxGMFhSaFBXbEVqT2JDMmo0QT09Iiwibm9uY2UiOiJYaERsemlCU1cwSENuK2RDIiwiYnl0ZXMiOiJUM0lmY1haQ1dtMWpLeWxBWmFUUnczbDVoYldLWW95dm5iNTZVaWJEbE5LOFZVU2tuQmx3NytIMG8yZnRzZ1UrIn0=","X-Minio-Internal-Server-Side-Encryption-S3-Sealed-Key":"IAAfANqt801MT+wwzQRkfFhTrndmhfNiN0alKwDS4AQ1dznNADRQgoq6I4pPVfRsbDp5rQawlripQZvPWUSNJA==","X-Minio-Internal-Server-Side-Encryption-Seal-Algorithm":"DAREv2-HMAC-SHA256","content-type":"application/octet-stream","etag":"20000f00cf5e68d3d6b60e44fcd8b9e8-1"},"parts":[{"number":1,"name":"part.1","etag":"","size":2016,"actualSize":1984}]}`
|
||||||
|
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, _, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to cfgreate xlStorage test setup, %s", err)
|
t.Fatalf("Unable to cfgreate xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Create files for the test cases.
|
// Create files for the test cases.
|
||||||
if err = xlStorage.MakeVol(context.Background(), "exists-legacy"); err != nil {
|
if err = xlStorage.MakeVol(context.Background(), "exists-legacy"); err != nil {
|
||||||
t.Fatalf("Unable to create a volume \"exists-legacy\", %s", err)
|
t.Fatalf("Unable to create a volume \"exists-legacy\", %s", err)
|
||||||
|
@ -285,13 +249,11 @@ func TestXLStorageReadVersionLegacy(t *testing.T) {
|
||||||
// TestXLStorageReadVersion - TestXLStorages the functionality implemented by xlStorage ReadVersion storage API.
|
// TestXLStorageReadVersion - TestXLStorages the functionality implemented by xlStorage ReadVersion storage API.
|
||||||
func TestXLStorageReadVersion(t *testing.T) {
|
func TestXLStorageReadVersion(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, _, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to cfgreate xlStorage test setup, %s", err)
|
t.Fatalf("Unable to cfgreate xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
xlMeta, _ := ioutil.ReadFile("testdata/xl.meta")
|
xlMeta, _ := ioutil.ReadFile("testdata/xl.meta")
|
||||||
|
|
||||||
// Create files for the test cases.
|
// Create files for the test cases.
|
||||||
|
@ -370,13 +332,11 @@ func TestXLStorageReadVersion(t *testing.T) {
|
||||||
// TestXLStorageReadAll - TestXLStorages the functionality implemented by xlStorage ReadAll storage API.
|
// TestXLStorageReadAll - TestXLStorages the functionality implemented by xlStorage ReadAll storage API.
|
||||||
func TestXLStorageReadAll(t *testing.T) {
|
func TestXLStorageReadAll(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, _, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Create files for the test cases.
|
// Create files for the test cases.
|
||||||
if err = xlStorage.MakeVol(context.Background(), "exists"); err != nil {
|
if err = xlStorage.MakeVol(context.Background(), "exists"); err != nil {
|
||||||
t.Fatalf("Unable to create a volume \"exists\", %s", err)
|
t.Fatalf("Unable to create a volume \"exists\", %s", err)
|
||||||
|
@ -505,11 +465,10 @@ func TestNewXLStorage(t *testing.T) {
|
||||||
// Asserts the failures too against the expected failures.
|
// Asserts the failures too against the expected failures.
|
||||||
func TestXLStorageMakeVol(t *testing.T) {
|
func TestXLStorageMakeVol(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
// Create a file.
|
// Create a file.
|
||||||
|
@ -558,11 +517,7 @@ func TestXLStorageMakeVol(t *testing.T) {
|
||||||
|
|
||||||
// TestXLStorage for permission denied.
|
// TestXLStorage for permission denied.
|
||||||
if runtime.GOOS != globalWindowsOSName {
|
if runtime.GOOS != globalWindowsOSName {
|
||||||
permDeniedDir, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
permDeniedDir := createPermDeniedFile(t)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unable to create temporary directory. %v", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(permDeniedDir)
|
|
||||||
if err = os.Chmod(permDeniedDir, 0o400); err != nil {
|
if err = os.Chmod(permDeniedDir, 0o400); err != nil {
|
||||||
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err)
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err)
|
||||||
}
|
}
|
||||||
|
@ -596,11 +551,10 @@ func TestXLStorageMakeVol(t *testing.T) {
|
||||||
// TestXLStorageDeleteVol - Validates the expected behavior of xlStorage.DeleteVol for various cases.
|
// TestXLStorageDeleteVol - Validates the expected behavior of xlStorage.DeleteVol for various cases.
|
||||||
func TestXLStorageDeleteVol(t *testing.T) {
|
func TestXLStorageDeleteVol(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||||
|
@ -654,17 +608,20 @@ func TestXLStorageDeleteVol(t *testing.T) {
|
||||||
|
|
||||||
// TestXLStorage for permission denied.
|
// TestXLStorage for permission denied.
|
||||||
if runtime.GOOS != globalWindowsOSName {
|
if runtime.GOOS != globalWindowsOSName {
|
||||||
var permDeniedDir string
|
permDeniedDir := t.TempDir()
|
||||||
if permDeniedDir, err = ioutil.TempDir(globalTestTmpDir, "minio-"); err != nil {
|
|
||||||
t.Fatalf("Unable to create temporary directory. %v", err)
|
|
||||||
}
|
|
||||||
defer removePermDeniedFile(permDeniedDir)
|
|
||||||
if err = os.Mkdir(slashpath.Join(permDeniedDir, "mybucket"), 0o400); err != nil {
|
if err = os.Mkdir(slashpath.Join(permDeniedDir, "mybucket"), 0o400); err != nil {
|
||||||
t.Fatalf("Unable to create temporary directory %v. %v", slashpath.Join(permDeniedDir, "mybucket"), err)
|
t.Fatalf("Unable to create temporary directory %v. %v", slashpath.Join(permDeniedDir, "mybucket"), err)
|
||||||
}
|
}
|
||||||
|
t.Cleanup(func() {
|
||||||
|
os.Chmod(slashpath.Join(permDeniedDir, "mybucket"), 0o775)
|
||||||
|
})
|
||||||
|
|
||||||
if err = os.Chmod(permDeniedDir, 0o400); err != nil {
|
if err = os.Chmod(permDeniedDir, 0o400); err != nil {
|
||||||
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err)
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err)
|
||||||
}
|
}
|
||||||
|
t.Cleanup(func() {
|
||||||
|
os.Chmod(permDeniedDir, 0o775)
|
||||||
|
})
|
||||||
|
|
||||||
// Initialize xlStorage storage layer for permission denied error.
|
// Initialize xlStorage storage layer for permission denied error.
|
||||||
_, err = newLocalXLStorage(permDeniedDir)
|
_, err = newLocalXLStorage(permDeniedDir)
|
||||||
|
@ -691,7 +648,7 @@ func TestXLStorageDeleteVol(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xlStorageDeletedStorage, diskPath, err := newXLStorageTestSetup()
|
xlStorageDeletedStorage, diskPath, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
|
@ -709,11 +666,10 @@ func TestXLStorageDeleteVol(t *testing.T) {
|
||||||
// TestXLStorageStatVol - TestXLStorages validate the volume info returned by xlStorage.StatVol() for various inputs.
|
// TestXLStorageStatVol - TestXLStorages validate the volume info returned by xlStorage.StatVol() for various inputs.
|
||||||
func TestXLStorageStatVol(t *testing.T) {
|
func TestXLStorageStatVol(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, _, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||||
|
@ -756,7 +712,7 @@ func TestXLStorageStatVol(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xlStorageDeletedStorage, diskPath, err := newXLStorageTestSetup()
|
xlStorageDeletedStorage, diskPath, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
|
@ -774,7 +730,7 @@ func TestXLStorageStatVol(t *testing.T) {
|
||||||
// TestXLStorageListVols - Validates the result and the error output for xlStorage volume listing functionality xlStorage.ListVols().
|
// TestXLStorageListVols - Validates the result and the error output for xlStorage volume listing functionality xlStorage.ListVols().
|
||||||
func TestXLStorageListVols(t *testing.T) {
|
func TestXLStorageListVols(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
|
@ -821,14 +777,13 @@ func TestXLStorageListVols(t *testing.T) {
|
||||||
// TestXLStorageListDir - TestXLStorages validate the directory listing functionality provided by xlStorage.ListDir .
|
// TestXLStorageListDir - TestXLStorages validate the directory listing functionality provided by xlStorage.ListDir .
|
||||||
func TestXLStorageListDir(t *testing.T) {
|
func TestXLStorageListDir(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, _, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// create xlStorage test setup.
|
// create xlStorage test setup.
|
||||||
xlStorageDeletedStorage, diskPath, err := newXLStorageTestSetup()
|
xlStorageDeletedStorage, diskPath, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
|
@ -916,7 +871,6 @@ func TestXLStorageListDir(t *testing.T) {
|
||||||
// TestXLStorage for permission denied.
|
// TestXLStorage for permission denied.
|
||||||
if runtime.GOOS != globalWindowsOSName {
|
if runtime.GOOS != globalWindowsOSName {
|
||||||
permDeniedDir := createPermDeniedFile(t)
|
permDeniedDir := createPermDeniedFile(t)
|
||||||
defer removePermDeniedFile(permDeniedDir)
|
|
||||||
|
|
||||||
// Initialize xlStorage storage layer for permission denied error.
|
// Initialize xlStorage storage layer for permission denied error.
|
||||||
_, err = newLocalXLStorage(permDeniedDir)
|
_, err = newLocalXLStorage(permDeniedDir)
|
||||||
|
@ -959,11 +913,10 @@ func TestXLStorageDeleteFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||||
|
@ -983,6 +936,9 @@ func TestXLStorageDeleteFile(t *testing.T) {
|
||||||
if err = os.Chmod(pathJoin(path, "no-permissions"), 0o555); err != nil {
|
if err = os.Chmod(pathJoin(path, "no-permissions"), 0o555); err != nil {
|
||||||
t.Fatalf("Unable to chmod directory, %s", err.Error())
|
t.Fatalf("Unable to chmod directory, %s", err.Error())
|
||||||
}
|
}
|
||||||
|
t.Cleanup(func() {
|
||||||
|
os.Chmod(pathJoin(path, "no-permissions"), 0o775)
|
||||||
|
})
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
srcVol string
|
srcVol string
|
||||||
|
@ -1046,7 +1002,6 @@ func TestXLStorageDeleteFile(t *testing.T) {
|
||||||
// TestXLStorage for permission denied.
|
// TestXLStorage for permission denied.
|
||||||
if runtime.GOOS != globalWindowsOSName {
|
if runtime.GOOS != globalWindowsOSName {
|
||||||
permDeniedDir := createPermDeniedFile(t)
|
permDeniedDir := createPermDeniedFile(t)
|
||||||
defer removePermDeniedFile(permDeniedDir)
|
|
||||||
|
|
||||||
// Initialize xlStorage storage layer for permission denied error.
|
// Initialize xlStorage storage layer for permission denied error.
|
||||||
_, err = newLocalXLStorage(permDeniedDir)
|
_, err = newLocalXLStorage(permDeniedDir)
|
||||||
|
@ -1072,7 +1027,7 @@ func TestXLStorageDeleteFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorageDeletedStorage, diskPath, err := newXLStorageTestSetup()
|
xlStorageDeletedStorage, diskPath, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
|
@ -1096,11 +1051,10 @@ func TestXLStorageDeleteFile(t *testing.T) {
|
||||||
// TestXLStorageReadFile - TestXLStorages xlStorage.ReadFile with wide range of cases and asserts the result and error response.
|
// TestXLStorageReadFile - TestXLStorages xlStorage.ReadFile with wide range of cases and asserts the result and error response.
|
||||||
func TestXLStorageReadFile(t *testing.T) {
|
func TestXLStorageReadFile(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
volume := "success-vol"
|
volume := "success-vol"
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
|
@ -1269,7 +1223,6 @@ func TestXLStorageReadFile(t *testing.T) {
|
||||||
// TestXLStorage for permission denied.
|
// TestXLStorage for permission denied.
|
||||||
if runtime.GOOS != globalWindowsOSName {
|
if runtime.GOOS != globalWindowsOSName {
|
||||||
permDeniedDir := createPermDeniedFile(t)
|
permDeniedDir := createPermDeniedFile(t)
|
||||||
defer removePermDeniedFile(permDeniedDir)
|
|
||||||
|
|
||||||
// Initialize xlStorage storage layer for permission denied error.
|
// Initialize xlStorage storage layer for permission denied error.
|
||||||
_, err = newLocalXLStorage(permDeniedDir)
|
_, err = newLocalXLStorage(permDeniedDir)
|
||||||
|
@ -1325,22 +1278,18 @@ var xlStorageReadFileWithVerifyTests = []struct {
|
||||||
// TestXLStorageReadFile.
|
// TestXLStorageReadFile.
|
||||||
func TestXLStorageReadFileWithVerify(t *testing.T) {
|
func TestXLStorageReadFileWithVerify(t *testing.T) {
|
||||||
volume, object := "test-vol", "myobject"
|
volume, object := "test-vol", "myobject"
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, _, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.RemoveAll(path)
|
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
if err = xlStorage.MakeVol(context.Background(), volume); err != nil {
|
if err = xlStorage.MakeVol(context.Background(), volume); err != nil {
|
||||||
os.RemoveAll(path)
|
|
||||||
t.Fatalf("Unable to create volume %s: %v", volume, err)
|
t.Fatalf("Unable to create volume %s: %v", volume, err)
|
||||||
}
|
}
|
||||||
data := make([]byte, 8*1024)
|
data := make([]byte, 8*1024)
|
||||||
if _, err = io.ReadFull(rand.Reader, data); err != nil {
|
if _, err = io.ReadFull(rand.Reader, data); err != nil {
|
||||||
os.RemoveAll(path)
|
|
||||||
t.Fatalf("Unable to create generate random data: %v", err)
|
t.Fatalf("Unable to create generate random data: %v", err)
|
||||||
}
|
}
|
||||||
if err = xlStorage.AppendFile(context.Background(), volume, object, data); err != nil {
|
if err = xlStorage.AppendFile(context.Background(), volume, object, data); err != nil {
|
||||||
os.RemoveAll(path)
|
|
||||||
t.Fatalf("Unable to create object: %v", err)
|
t.Fatalf("Unable to create object: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1369,11 +1318,10 @@ func TestXLStorageReadFileWithVerify(t *testing.T) {
|
||||||
|
|
||||||
// TestXLStorageFormatFileChange - to test if changing the diskID makes the calls fail.
|
// TestXLStorageFormatFileChange - to test if changing the diskID makes the calls fail.
|
||||||
func TestXLStorageFormatFileChange(t *testing.T) {
|
func TestXLStorageFormatFileChange(t *testing.T) {
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, _, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
if err = xlStorage.MakeVol(context.Background(), volume); err != nil {
|
if err = xlStorage.MakeVol(context.Background(), volume); err != nil {
|
||||||
t.Fatalf("MakeVol failed with %s", err)
|
t.Fatalf("MakeVol failed with %s", err)
|
||||||
|
@ -1393,11 +1341,10 @@ func TestXLStorageFormatFileChange(t *testing.T) {
|
||||||
// TestXLStorage xlStorage.AppendFile()
|
// TestXLStorage xlStorage.AppendFile()
|
||||||
func TestXLStorageAppendFile(t *testing.T) {
|
func TestXLStorageAppendFile(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||||
|
@ -1438,7 +1385,6 @@ func TestXLStorageAppendFile(t *testing.T) {
|
||||||
// TestXLStorage for permission denied.
|
// TestXLStorage for permission denied.
|
||||||
if runtime.GOOS != globalWindowsOSName {
|
if runtime.GOOS != globalWindowsOSName {
|
||||||
permDeniedDir := createPermDeniedFile(t)
|
permDeniedDir := createPermDeniedFile(t)
|
||||||
defer removePermDeniedFile(permDeniedDir)
|
|
||||||
|
|
||||||
var xlStoragePermStorage StorageAPI
|
var xlStoragePermStorage StorageAPI
|
||||||
// Initialize xlStorage storage layer for permission denied error.
|
// Initialize xlStorage storage layer for permission denied error.
|
||||||
|
@ -1472,11 +1418,10 @@ func TestXLStorageAppendFile(t *testing.T) {
|
||||||
// TestXLStorage xlStorage.RenameFile()
|
// TestXLStorage xlStorage.RenameFile()
|
||||||
func TestXLStorageRenameFile(t *testing.T) {
|
func TestXLStorageRenameFile(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, _, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
if err := xlStorage.MakeVol(context.Background(), "src-vol"); err != nil {
|
if err := xlStorage.MakeVol(context.Background(), "src-vol"); err != nil {
|
||||||
|
@ -1690,11 +1635,10 @@ func TestXLStorageRenameFile(t *testing.T) {
|
||||||
// TestXLStorageDeleteVersion will test if version deletes and bulk deletes work as expected.
|
// TestXLStorageDeleteVersion will test if version deletes and bulk deletes work as expected.
|
||||||
func TestXLStorageDeleteVersion(t *testing.T) {
|
func TestXLStorageDeleteVersion(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xl, path, err := newXLStorageTestSetup()
|
xl, _, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
volume := "myvol-vol"
|
volume := "myvol-vol"
|
||||||
|
@ -1782,11 +1726,10 @@ func TestXLStorageDeleteVersion(t *testing.T) {
|
||||||
// TestXLStorage xlStorage.StatInfoFile()
|
// TestXLStorage xlStorage.StatInfoFile()
|
||||||
func TestXLStorageStatInfoFile(t *testing.T) {
|
func TestXLStorageStatInfoFile(t *testing.T) {
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
xlStorage, path, err := newXLStorageTestSetup()
|
xlStorage, _, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
// Setup test environment.
|
// Setup test environment.
|
||||||
if err := xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
if err := xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||||
|
@ -1878,11 +1821,10 @@ func TestXLStorageVerifyFile(t *testing.T) {
|
||||||
// 4) Streaming bitrot check on corrupted file
|
// 4) Streaming bitrot check on corrupted file
|
||||||
|
|
||||||
// create xlStorage test setup
|
// create xlStorage test setup
|
||||||
storage, path, err := newXLStorageTestSetup()
|
storage, path, err := newXLStorageTestSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(path)
|
|
||||||
|
|
||||||
volName := "testvol"
|
volName := "testvol"
|
||||||
fileName := "testfile"
|
fileName := "testfile"
|
||||||
|
@ -1976,11 +1918,7 @@ func TestXLStorageVerifyFile(t *testing.T) {
|
||||||
// TestXLStorageReadMetadata tests readMetadata
|
// TestXLStorageReadMetadata tests readMetadata
|
||||||
func TestXLStorageReadMetadata(t *testing.T) {
|
func TestXLStorageReadMetadata(t *testing.T) {
|
||||||
volume, object := "test-vol", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
volume, object := "test-vol", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||||
tmpDir, err := ioutil.TempDir("", "")
|
tmpDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpDir)
|
|
||||||
|
|
||||||
disk, err := newLocalXLStorage(tmpDir)
|
disk, err := newLocalXLStorage(tmpDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -22,7 +22,6 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -39,10 +38,7 @@ func getUmask() int {
|
||||||
|
|
||||||
// Tests if the directory and file creations happen with proper umask.
|
// Tests if the directory and file creations happen with proper umask.
|
||||||
func TestIsValidUmaskVol(t *testing.T) {
|
func TestIsValidUmaskVol(t *testing.T) {
|
||||||
tmpPath, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
tmpPath := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Initializing temporary directory failed with %s.", err)
|
|
||||||
}
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
volName string
|
volName string
|
||||||
expectedUmask int
|
expectedUmask int
|
||||||
|
@ -62,7 +58,6 @@ func TestIsValidUmaskVol(t *testing.T) {
|
||||||
if err = disk.MakeVol(context.Background(), testCase.volName); err != nil {
|
if err = disk.MakeVol(context.Background(), testCase.volName); err != nil {
|
||||||
t.Fatalf("Creating a volume failed with %s expected to pass.", err)
|
t.Fatalf("Creating a volume failed with %s expected to pass.", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpPath)
|
|
||||||
|
|
||||||
// Stat to get permissions bits.
|
// Stat to get permissions bits.
|
||||||
st, err := os.Stat(path.Join(tmpPath, testCase.volName))
|
st, err := os.Stat(path.Join(tmpPath, testCase.volName))
|
||||||
|
@ -81,10 +76,7 @@ func TestIsValidUmaskVol(t *testing.T) {
|
||||||
|
|
||||||
// Tests if the file creations happen with proper umask.
|
// Tests if the file creations happen with proper umask.
|
||||||
func TestIsValidUmaskFile(t *testing.T) {
|
func TestIsValidUmaskFile(t *testing.T) {
|
||||||
tmpPath, err := ioutil.TempDir(globalTestTmpDir, "minio-")
|
tmpPath := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Initializing temporary directory failed with %s.", err)
|
|
||||||
}
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
volName string
|
volName string
|
||||||
expectedUmask int
|
expectedUmask int
|
||||||
|
@ -105,8 +97,6 @@ func TestIsValidUmaskFile(t *testing.T) {
|
||||||
t.Fatalf("Creating a volume failed with %s expected to pass.", err)
|
t.Fatalf("Creating a volume failed with %s expected to pass.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer os.RemoveAll(tmpPath)
|
|
||||||
|
|
||||||
// Attempt to create a file to verify the permissions later.
|
// Attempt to create a file to verify the permissions later.
|
||||||
// AppendFile creates file with 0666 perms.
|
// AppendFile creates file with 0666 perms.
|
||||||
if err = disk.AppendFile(context.Background(), testCase.volName, pathJoin("hello-world.txt", xlStorageFormatFile), []byte("Hello World")); err != nil {
|
if err = disk.AppendFile(context.Background(), testCase.volName, pathJoin("hello-world.txt", xlStorageFormatFile), []byte("Hello World")); err != nil {
|
||||||
|
|
|
@ -24,8 +24,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,16 +40,10 @@ func TestUNCPaths(t *testing.T) {
|
||||||
{string(bytes.Repeat([]byte("界"), 280)), false},
|
{string(bytes.Repeat([]byte("界"), 280)), false},
|
||||||
{`/p/q/r/s/t`, true},
|
{`/p/q/r/s/t`, true},
|
||||||
}
|
}
|
||||||
dir, err := ioutil.TempDir("", "testdisk-")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
// Cleanup on exit of test
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
// Instantiate posix object to manage a disk
|
// Instantiate posix object to manage a disk
|
||||||
var fs StorageAPI
|
fs, err := newLocalXLStorage(dir)
|
||||||
fs, err = newLocalXLStorage(dir)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -81,15 +73,9 @@ func TestUNCPaths(t *testing.T) {
|
||||||
// Test to validate xlStorage behavior on windows when a non-final path component is a file.
|
// Test to validate xlStorage behavior on windows when a non-final path component is a file.
|
||||||
func TestUNCPathENOTDIR(t *testing.T) {
|
func TestUNCPathENOTDIR(t *testing.T) {
|
||||||
// Instantiate posix object to manage a disk
|
// Instantiate posix object to manage a disk
|
||||||
dir, err := ioutil.TempDir("", "testdisk-")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
// Cleanup on exit of test
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
var fs StorageAPI
|
fs, err := newLocalXLStorage(dir)
|
||||||
fs, err = newLocalXLStorage(dir)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,21 +21,13 @@
|
||||||
package disk_test
|
package disk_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/minio/minio/internal/disk"
|
"github.com/minio/minio/internal/disk"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFree(t *testing.T) {
|
func TestFree(t *testing.T) {
|
||||||
path, err := ioutil.TempDir(os.TempDir(), "minio-")
|
di, err := disk.GetInfo(t.TempDir())
|
||||||
defer os.RemoveAll(path)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
di, err := disk.GetInfo(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,18 +46,9 @@ func TestLockFail(t *testing.T) {
|
||||||
|
|
||||||
// Tests lock directory fail.
|
// Tests lock directory fail.
|
||||||
func TestLockDirFail(t *testing.T) {
|
func TestLockDirFail(t *testing.T) {
|
||||||
d, err := ioutil.TempDir("", "lockDir")
|
d := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
err = os.Remove(d)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, err = LockedOpenFile(d, os.O_APPEND, 0o600)
|
_, err := LockedOpenFile(d, os.O_APPEND, 0o600)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Should fail here")
|
t.Fatal("Should fail here")
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,8 @@ func TestCrossDeviceMountPaths(t *testing.T) {
|
||||||
/dev/2 /path/to/1/2 type2 flags,1,2=3 2 2
|
/dev/2 /path/to/1/2 type2 flags,1,2=3 2 2
|
||||||
/dev/3 /path/to/1.1 type3 falgs,1,2=3 3 3
|
/dev/3 /path/to/1.1 type3 falgs,1,2=3 3 3
|
||||||
`
|
`
|
||||||
dir, err := ioutil.TempDir("", "TestReadProcmountInfos")
|
var err error
|
||||||
if err != nil {
|
dir := t.TempDir()
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
mountsPath := filepath.Join(dir, "mounts")
|
mountsPath := filepath.Join(dir, "mounts")
|
||||||
if err = ioutil.WriteFile(mountsPath, []byte(successCase), 0o666); err != nil {
|
if err = ioutil.WriteFile(mountsPath, []byte(successCase), 0o666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -89,11 +86,8 @@ func TestCrossDeviceMount(t *testing.T) {
|
||||||
/dev/2 /path/to/1/2 type2 flags,1,2=3 2 2
|
/dev/2 /path/to/1/2 type2 flags,1,2=3 2 2
|
||||||
/dev/3 /path/to/1.1 type3 falgs,1,2=3 3 3
|
/dev/3 /path/to/1.1 type3 falgs,1,2=3 3 3
|
||||||
`
|
`
|
||||||
dir, err := ioutil.TempDir("", "TestReadProcmountInfos")
|
var err error
|
||||||
if err != nil {
|
dir := t.TempDir()
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
mountsPath := filepath.Join(dir, "mounts")
|
mountsPath := filepath.Join(dir, "mounts")
|
||||||
if err = ioutil.WriteFile(mountsPath, []byte(successCase), 0o666); err != nil {
|
if err = ioutil.WriteFile(mountsPath, []byte(successCase), 0o666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -140,11 +134,8 @@ func TestReadProcmountInfos(t *testing.T) {
|
||||||
/dev/1 /path/to/1 type1 flags 1 1
|
/dev/1 /path/to/1 type1 flags 1 1
|
||||||
/dev/2 /path/to/2 type2 flags,1,2=3 2 2
|
/dev/2 /path/to/2 type2 flags,1,2=3 2 2
|
||||||
`
|
`
|
||||||
dir, err := ioutil.TempDir("", "TestReadProcmountInfos")
|
var err error
|
||||||
if err != nil {
|
dir := t.TempDir()
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
mountsPath := filepath.Join(dir, "mounts")
|
mountsPath := filepath.Join(dir, "mounts")
|
||||||
if err = ioutil.WriteFile(mountsPath, []byte(successCase), 0o666); err != nil {
|
if err = ioutil.WriteFile(mountsPath, []byte(successCase), 0o666); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue