Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions assemble_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ func TestExtract(t *testing.T) {
}

// Chop up the input file into a (temporary) local store
store, err := ioutil.TempDir("", "store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(store)
store := t.TempDir()

s, err := NewLocalStore(store, StoreOptions{})
if err != nil {
Expand All @@ -64,11 +60,7 @@ func TestExtract(t *testing.T) {
}

// Make a blank store - used to test a case where no chunk *should* be requested
blankstore, err := ioutil.TempDir("", "blankstore")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(blankstore)
blankstore := t.TempDir()
bs, err := NewLocalStore(blankstore, StoreOptions{})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -160,11 +152,7 @@ func TestSeed(t *testing.T) {
rand.Read(rand2)

// Setup a temporary store
store, err := ioutil.TempDir("", "store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(store)
store := t.TempDir()

s, err := NewLocalStore(store, StoreOptions{})
if err != nil {
Expand Down Expand Up @@ -295,11 +283,7 @@ func TestSeed(t *testing.T) {
// be kept in-place and the self-seed must not cause any re-writes.
func TestSelfSeedInPlace(t *testing.T) {
// Setup a temporary store
store, err := ioutil.TempDir("", "store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(store)
store := t.TempDir()

s, err := NewLocalStore(store, StoreOptions{})
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions cmd/desync/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -22,17 +21,15 @@ func TestCacheCommand(t *testing.T) {
[]string{"--store", "testdata/blob1.store", "--store", "testdata/blob2.store", "testdata/blob1.caibx", "testdata/blob2.caibx"}},
} {
t.Run(test.name, func(t *testing.T) {
cache, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(cache)
cache := t.TempDir()

cmd := newCacheCommand(context.Background())
cmd.SetArgs(append(test.args, "-c", cache))

// Redirect the command's output to turn off the progressbar and run it
stderr = ioutil.Discard
cmd.SetOutput(ioutil.Discard)
_, err = cmd.ExecuteC()
_, err := cmd.ExecuteC()
require.NoError(t, err)

// If the file was split right, we'll have chunks in the dir now
Expand Down
6 changes: 2 additions & 4 deletions cmd/desync/chop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ func TestChopCommand(t *testing.T) {
{"chop with ignore",
[]string{"--ignore", "testdata/blob2.caibx", "testdata/blob1.caibx", "testdata/blob1"}},
} {
store, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(store)
store := t.TempDir()

args := []string{"-s", store}
args = append(args, test.args...)
Expand All @@ -33,7 +31,7 @@ func TestChopCommand(t *testing.T) {
// Redirect the command's output to turn off the progressbar and run it
stderr = ioutil.Discard
cmd.SetOutput(ioutil.Discard)
_, err = cmd.ExecuteC()
_, err := cmd.ExecuteC()
require.NoError(t, err)

// If the file was split right, we'll have chunks in the dir now
Expand Down
19 changes: 5 additions & 14 deletions cmd/desync/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"

Expand All @@ -18,19 +17,15 @@ func TestExtractCommand(t *testing.T) {
require.NoError(t, err)

// Now prepare several files used to extract into
outDir, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(outDir)
outDir := t.TempDir()
out1 := filepath.Join(outDir, "out1") // Doesn't exit
out2 := filepath.Join(outDir, "out2") // Exists, but different content
require.NoError(t, ioutil.WriteFile(out2, []byte{0, 1, 2, 3}, 0644))
out3 := filepath.Join(outDir, "out3") // Exist and complete match
require.NoError(t, ioutil.WriteFile(out3, expected, 0644))

// Make a cache dir
cacheDir, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(cacheDir)
cacheDir := t.TempDir()

for _, test := range []struct {
name string
Expand Down Expand Up @@ -106,9 +101,7 @@ func TestExtractCommand(t *testing.T) {
}

func TestExtractWithFailover(t *testing.T) {
outDir, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(outDir)
outDir := t.TempDir()
out := filepath.Join(outDir, "out")

// Start a server that'll always fail
Expand All @@ -124,14 +117,12 @@ func TestExtractWithFailover(t *testing.T) {
// Redirect the command's output and run it
stderr = ioutil.Discard
cmd.SetOutput(ioutil.Discard)
_, err = cmd.ExecuteC()
_, err := cmd.ExecuteC()
require.NoError(t, err)
}

func TestExtractWithInvalidSeeds(t *testing.T) {
outDir, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(outDir)
outDir := t.TempDir()
out := filepath.Join(outDir, "out")

for _, test := range []struct {
Expand Down
7 changes: 2 additions & 5 deletions cmd/desync/indexserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io/ioutil"
"net"
"net/http"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -47,9 +46,7 @@ func TestIndexServerReadCommand(t *testing.T) {

func TestIndexServerWriteCommand(t *testing.T) {
// Create an empty store to be used for writing
store, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(store)
store := t.TempDir()

// Start a read-write server
addr, cancel := startIndexServer(t, "-s", store, "-w")
Expand All @@ -60,7 +57,7 @@ func TestIndexServerWriteCommand(t *testing.T) {
makeCmd := newMakeCommand(context.Background())
makeCmd.SetArgs([]string{fmt.Sprintf("http://%s/new.caibx", addr), "testdata/blob1"})
makeCmd.SetOutput(ioutil.Discard)
_, err = makeCmd.ExecuteC()
_, err := makeCmd.ExecuteC()
require.NoError(t, err)

// The index server should not accept arbitrary (non-index) files.
Expand Down
8 changes: 2 additions & 6 deletions cmd/desync/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ package main

import (
"context"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/require"
)

func TestPruneCommand(t *testing.T) {
// Create a blank store
store, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(store)
store := t.TempDir()

// Run a "chop" command to populate the store
chopCmd := newChopCommand(context.Background())
chopCmd.SetArgs([]string{"-s", store, "testdata/blob1.caibx", "testdata/blob1"})
_, err = chopCmd.ExecuteC()
_, err := chopCmd.ExecuteC()
require.NoError(t, err)

// Now prune the store. Using a different index that doesn't have the exact same chunks
Expand Down
14 changes: 4 additions & 10 deletions cmd/desync/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package main

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand All @@ -14,28 +12,24 @@ import (

func TestTarCommandArchive(t *testing.T) {
// Create an output dir
out, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(out)
out := t.TempDir()
archive := filepath.Join(out, "tree.catar")

// Run "tar" command to build the catar archive
cmd := newTarCommand(context.Background())
cmd.SetArgs([]string{archive, "testdata/tree"})
_, err = cmd.ExecuteC()
_, err := cmd.ExecuteC()
require.NoError(t, err)
}

func TestTarCommandIndex(t *testing.T) {
// Create an output dir to function as chunk store and to hold the caidx
out, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(out)
out := t.TempDir()
index := filepath.Join(out, "tree.caidx")

// Run "tar" command to build a caidx index and store the chunks
cmd := newTarCommand(context.Background())
cmd.SetArgs([]string{"-s", out, "-i", index, "testdata/tree"})
_, err = cmd.ExecuteC()
_, err := cmd.ExecuteC()
require.NoError(t, err)
}
13 changes: 4 additions & 9 deletions cmd/desync/untar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -16,27 +15,23 @@ import (

func TestUntarCommandArchive(t *testing.T) {
// Create an output dir to extract into
out, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(out)
out := t.TempDir()

// Run "untar" command to unpack an archive
cmd := newUntarCommand(context.Background())
cmd.SetArgs([]string{"--no-same-owner", "--no-same-permissions", "testdata/tree.catar", out})
_, err = cmd.ExecuteC()
_, err := cmd.ExecuteC()
require.NoError(t, err)
}

func TestUntarCommandIndex(t *testing.T) {
// Create an output dir to extract into
out, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(out)
out := t.TempDir()

// Run "untar" to extract from a caidx index
cmd := newUntarCommand(context.Background())
cmd.SetArgs([]string{"-s", "testdata/tree.store", "-i", "--no-same-owner", "--no-same-permissions", "testdata/tree.caidx", out})
_, err = cmd.ExecuteC()
_, err := cmd.ExecuteC()
require.NoError(t, err)
}

Expand Down
6 changes: 2 additions & 4 deletions cmd/desync/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import (

func TestVerifyCommand(t *testing.T) {
// Create a blank store
store, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(store)
store := t.TempDir()

// Run a "chop" command to populate the store
chopCmd := newChopCommand(context.Background())
chopCmd.SetArgs([]string{"-s", store, "testdata/blob1.caibx", "testdata/blob1"})
_, err = chopCmd.ExecuteC()
_, err := chopCmd.ExecuteC()
require.NoError(t, err)

// Place an invalid chunk in the store
Expand Down
12 changes: 2 additions & 10 deletions index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ func TestIndexChunking(t *testing.T) {
}

// Make a temp local store
dir, err := ioutil.TempDir("", "chunktest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
dir := t.TempDir()
s, err := NewLocalStore(dir, StoreOptions{})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -174,11 +170,7 @@ func splitBlob(b *testing.B) {
}

// Make a temp local store
dir, err := ioutil.TempDir("", "chunktest")
if err != nil {
b.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
dir := b.TempDir()
s, err := NewLocalStore(dir, StoreOptions{})
if err != nil {
b.Fatal(err)
Expand Down
6 changes: 1 addition & 5 deletions mount-index_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import (

func TestMountIndex(t *testing.T) {
// Create the mount point
mnt, err := ioutil.TempDir("", "mount-index-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(mnt)
mnt := t.TempDir()

// Define the store
s, err := NewLocalStore("testdata/blob1.store", StoreOptions{})
Expand Down
6 changes: 1 addition & 5 deletions selfseed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import (

func TestSelfSeed(t *testing.T) {
// Setup a temporary store
store, err := ioutil.TempDir("", "store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(store)
store := t.TempDir()

s, err := NewLocalStore(store, StoreOptions{})
if err != nil {
Expand Down
Loading