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
28 changes: 14 additions & 14 deletions assemble_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import (
"context"
"crypto/md5"
"crypto/rand"
"github.com/stretchr/testify/require"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"

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

func TestExtract(t *testing.T) {
// Make a test file that's guaranteed to have duplicate chunks.
b, err := ioutil.ReadFile("testdata/chunker.input")
b, err := os.ReadFile("testdata/chunker.input")
if err != nil {
t.Fatal(err)
}
for i := 0; i < 4; i++ { // Replicate it a few times to make sure we get dupes
b = append(b, b...)
}
b = append(b, make([]byte, 2*ChunkSizeMaxDefault)...) // want to have at least one null-chunk in the input
in, err := ioutil.TempFile("", "in")
in, err := os.CreateTemp("", "in")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -67,14 +67,14 @@ func TestExtract(t *testing.T) {
}

// Prepare output files for each test - first a non-existing one
out1, err := ioutil.TempFile("", "out1")
out1, err := os.CreateTemp("", "out1")
if err != nil {
t.Fatal(err)
}
os.Remove(out1.Name())

// This one is a complete file matching what we expect at the end
out2, err := ioutil.TempFile("", "out2")
out2, err := os.CreateTemp("", "out2")
if err != nil {
t.Fatal(err)
}
Expand All @@ -85,7 +85,7 @@ func TestExtract(t *testing.T) {
defer os.Remove(out2.Name())

// Incomplete or damaged file that has most but not all data
out3, err := ioutil.TempFile("", "out3")
out3, err := os.CreateTemp("", "out3")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestExtract(t *testing.T) {
); err != nil {
t.Fatal(err)
}
b, err := ioutil.ReadFile(test.outfile)
b, err := os.ReadFile(test.outfile)
if err != nil {
t.Fatal(err)
}
Expand All @@ -141,7 +141,7 @@ func TestExtract(t *testing.T) {
func TestSeed(t *testing.T) {
// Prepare different types of data slices that'll be used to assemble target
// and seed files with varying amount of duplication
data1, err := ioutil.ReadFile("testdata/chunker.input")
data1, err := os.ReadFile("testdata/chunker.input")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestSeed(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
// Build the destination file so we can chunk it
dst, err := ioutil.TempFile("", "dst")
dst, err := os.CreateTemp("", "dst")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestSeed(t *testing.T) {
// Build the seed files and indexes then populate the array of seeds
var seeds []Seed
for _, f := range test.seeds {
seedFile, err := ioutil.TempFile("", "seed")
seedFile, err := os.CreateTemp("", "seed")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestSeed(t *testing.T) {
); err != nil {
t.Fatal(err)
}
b, err := ioutil.ReadFile(dst.Name())
b, err := os.ReadFile(dst.Name())
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestSelfSeedInPlace(t *testing.T) {
sum := md5.Sum(b)

// Build a temp target file pre-populated with the correct content
dst, err := ioutil.TempFile("", "dst")
dst, err := os.CreateTemp("", "dst")
if err != nil {
t.Fatal(err)
}
Expand All @@ -373,7 +373,7 @@ func TestSelfSeedInPlace(t *testing.T) {
}

// Compare the checksums to that of the input data
b, err = ioutil.ReadFile(dst.Name())
b, err = os.ReadFile(dst.Name())
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions chunker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/bits"
)

Expand Down Expand Up @@ -234,7 +233,7 @@ func (c *Chunker) Advance(n int) error {
_, err := rs.Seek(readerN, io.SeekCurrent)
return err
}
_, err := io.CopyN(ioutil.Discard, c.r, readerN)
_, err := io.CopyN(io.Discard, c.r, readerN)
return err
}

Expand Down
9 changes: 5 additions & 4 deletions cmd/desync/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package main

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

"github.com/stretchr/testify/require"
Expand All @@ -27,13 +28,13 @@ func TestCacheCommand(t *testing.T) {
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)
stderr = io.Discard
cmd.SetOutput(io.Discard)
_, err := cmd.ExecuteC()
require.NoError(t, err)

// If the file was split right, we'll have chunks in the dir now
dirs, err := ioutil.ReadDir(cache)
dirs, err := os.ReadDir(cache)
require.NoError(t, err)
require.NotEmpty(t, dirs)
})
Expand Down
7 changes: 4 additions & 3 deletions cmd/desync/cat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package main
import (
"bytes"
"context"
"io/ioutil"
"io"
"os"
"testing"

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

func TestCatCommand(t *testing.T) {
// Read the whole expected blob from disk
f, err := ioutil.ReadFile("testdata/blob1")
f, err := os.ReadFile("testdata/blob1")
require.NoError(t, err)

for _, test := range []struct {
Expand All @@ -33,7 +34,7 @@ func TestCatCommand(t *testing.T) {

// Redirect the command's output
stdout = b
cmd.SetOutput(ioutil.Discard)
cmd.SetOutput(io.Discard)
_, err := cmd.ExecuteC()
require.NoError(t, err)

Expand Down
10 changes: 5 additions & 5 deletions cmd/desync/chop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"context"
"io/ioutil"
"io"
"os"
"path/filepath"
"testing"
Expand All @@ -29,13 +29,13 @@ func TestChopCommand(t *testing.T) {
cmd.SetArgs(args)

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

// If the file was split right, we'll have chunks in the dir now
dirs, err := ioutil.ReadDir(store)
dirs, err := os.ReadDir(store)
require.NoError(t, err)
require.NotEmpty(t, dirs)
}
Expand All @@ -53,7 +53,7 @@ func TestChopErrors(t *testing.T) {
} {
t.Run(test.name, func(t *testing.T) {
cmd := newChopCommand(context.Background())
cmd.SetOutput(ioutil.Discard)
cmd.SetOutput(io.Discard)
cmd.SetArgs(test.args)
_, err := cmd.ExecuteC()
require.Error(t, err)
Expand Down
28 changes: 14 additions & 14 deletions cmd/desync/chunkserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"path/filepath"
Expand All @@ -25,8 +25,8 @@ func TestChunkServerReadCommand(t *testing.T) {
// Run an "extract" command to confirm the chunk server provides chunks
extractCmd := newExtractCommand(context.Background())
extractCmd.SetArgs([]string{"-s", store, "testdata/blob1.caibx", filepath.Join(outdir, "blob")})
stdout = ioutil.Discard
extractCmd.SetOutput(ioutil.Discard)
stdout = io.Discard
extractCmd.SetOutput(io.Discard)
_, err := extractCmd.ExecuteC()
require.NoError(t, err)

Expand All @@ -46,7 +46,7 @@ func TestChunkServerReadCommand(t *testing.T) {
// the "chop" command and storing the chunks there.
chopCmd := newChopCommand(context.Background())
chopCmd.SetArgs([]string{"-s", store, "testdata/blob2.caibx", "testdata/blob2"})
chopCmd.SetOutput(ioutil.Discard)
chopCmd.SetOutput(io.Discard)
_, err = chopCmd.ExecuteC()
require.Error(t, err)
require.Contains(t, err.Error(), "writing to upstream")
Expand All @@ -63,7 +63,7 @@ func TestChunkServerWriteCommand(t *testing.T) {
// Run a "chop" command to confirm the chunk server can be used to write chunks
chopCmd := newChopCommand(context.Background())
chopCmd.SetArgs([]string{"-s", store, "testdata/blob1.caibx", "testdata/blob1"})
chopCmd.SetOutput(ioutil.Discard)
chopCmd.SetOutput(io.Discard)
_, err := chopCmd.ExecuteC()
require.NoError(t, err)

Expand All @@ -86,16 +86,16 @@ func TestChunkServerVerifiedTLS(t *testing.T) {
// Run the "extract" command to confirm the TLS chunk server can be used
extractCmd := newExtractCommand(context.Background())
extractCmd.SetArgs([]string{"--ca-cert", "testdata/ca.crt", "-s", store, "testdata/blob1.caibx", filepath.Join(outdir, "blob1")})
extractCmd.SetOutput(ioutil.Discard)
extractCmd.SetOutput(io.Discard)
_, err := extractCmd.ExecuteC()
require.NoError(t, err)
}

func TestChunkServerInsecureTLS(t *testing.T) {
outdir := t.TempDir()

stderr = ioutil.Discard
stdout = ioutil.Discard
stderr = io.Discard
stdout = io.Discard

// Start a (writable) server
addr, cancel := startChunkServer(t, "-s", "testdata/blob1.store", "--key", "testdata/server.key", "--cert", "testdata/server.crt")
Expand All @@ -106,15 +106,15 @@ func TestChunkServerInsecureTLS(t *testing.T) {
// Run the "extract" command accepting any cert to confirm the TLS chunk server can be used
extractCmd := newExtractCommand(context.Background())
extractCmd.SetArgs([]string{"-t", "-s", store, "testdata/blob1.caibx", filepath.Join(outdir, "blob1")})
// extractCmd.SetOutput(ioutil.Discard)
// extractCmd.SetOutput(io.Discard)
_, err := extractCmd.ExecuteC()
require.NoError(t, err)

// Run the "extract" command without accepting any cert. Should fail.
extractCmd = newExtractCommand(context.Background())
extractCmd.SetOutput(ioutil.Discard)
extractCmd.SetOutput(io.Discard)
extractCmd.SetArgs([]string{"-s", store, "testdata/blob1.caibx", filepath.Join(outdir, "blob1")})
extractCmd.SetOutput(ioutil.Discard)
extractCmd.SetOutput(io.Discard)
_, err = extractCmd.ExecuteC()
require.Error(t, err)

Expand All @@ -123,8 +123,8 @@ func TestChunkServerInsecureTLS(t *testing.T) {
func TestChunkServerMutualTLS(t *testing.T) {
outdir := t.TempDir()

stderr = ioutil.Discard
stdout = ioutil.Discard
stderr = io.Discard
stdout = io.Discard

// Start a (writable) server
addr, cancel := startChunkServer(t,
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestChunkServerMutualTLS(t *testing.T) {
extractCmd.SetArgs([]string{
"--ca-cert", "testdata/ca.crt",
"-s", store, "testdata/blob1.caibx", filepath.Join(outdir, "blob1")})
extractCmd.SetOutput(ioutil.Discard)
extractCmd.SetOutput(io.Discard)
_, err = extractCmd.ExecuteC()
require.Error(t, err)
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/desync/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

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

Expand All @@ -10,11 +9,11 @@ import (

func TestConfigFile(t *testing.T) {
cfgFileContent := []byte(`{"store-options": {"/path/to/store/":{"uncompressed": true}}}`)
f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
require.NoError(t, err)
f.Close()
defer os.Remove(f.Name())
require.NoError(t, ioutil.WriteFile(f.Name(), cfgFileContent, 0644))
require.NoError(t, os.WriteFile(f.Name(), cfgFileContent, 0644))

// Set the global config file name
cfgFile = f.Name()
Expand All @@ -36,11 +35,11 @@ func TestConfigFile(t *testing.T) {

func TestConfigFileMultipleMatches(t *testing.T) {
cfgFileContent := []byte(`{"store-options": {"/path/to/store/":{"uncompressed": true}, "/path/to/store":{"uncompressed": false}}}`)
f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
require.NoError(t, err)
f.Close()
defer os.Remove(f.Name())
require.NoError(t, ioutil.WriteFile(f.Name(), cfgFileContent, 0644))
require.NoError(t, os.WriteFile(f.Name(), cfgFileContent, 0644))

// Set the global config file name
cfgFile = f.Name()
Expand Down
Loading