diff --git a/cmd/podsync/config.go b/cmd/podsync/config.go index 2334a920..43156432 100644 --- a/cmd/podsync/config.go +++ b/cmd/podsync/config.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "io/ioutil" + "os" "path/filepath" "regexp" @@ -54,7 +54,7 @@ type Log struct { // LoadConfig loads TOML configuration from a file path func LoadConfig(path string) (*Config, error) { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return nil, errors.Wrapf(err, "failed to read config file: %s", path) } diff --git a/cmd/podsync/config_test.go b/cmd/podsync/config_test.go index c4b13a62..b5de84ac 100644 --- a/cmd/podsync/config_test.go +++ b/cmd/podsync/config_test.go @@ -1,7 +1,6 @@ package main import ( - "io/ioutil" "os" "testing" "time" @@ -235,7 +234,7 @@ data_dir = "/data" func setup(t *testing.T, file string) string { t.Helper() - f, err := ioutil.TempFile("", "") + f, err := os.CreateTemp("", "") require.NoError(t, err) defer f.Close() diff --git a/pkg/db/badger_test.go b/pkg/db/badger_test.go index a188493f..5760bde2 100644 --- a/pkg/db/badger_test.go +++ b/pkg/db/badger_test.go @@ -2,8 +2,6 @@ package db import ( "context" - "io/ioutil" - "os" "testing" "time" @@ -16,23 +14,17 @@ import ( var testCtx = context.TODO() func TestNewBadger(t *testing.T) { - dir, err := ioutil.TempDir("", "podsync-badger-") - require.NoError(t, err) + dir := t.TempDir() db, err := NewBadger(&Config{Dir: dir}) require.NoError(t, err) err = db.Close() assert.NoError(t, err) - - err = os.RemoveAll(dir) - assert.NoError(t, err) } func TestBadger_Version(t *testing.T) { - dir, err := ioutil.TempDir("", "podsync-badger-") - assert.NoError(t, err) - defer os.RemoveAll(dir) + dir := t.TempDir() db, err := NewBadger(&Config{Dir: dir}) require.NoError(t, err) @@ -44,9 +36,7 @@ func TestBadger_Version(t *testing.T) { } func TestBadger_AddFeed(t *testing.T) { - dir, err := ioutil.TempDir("", "podsync-badger-") - assert.NoError(t, err) - defer os.RemoveAll(dir) + dir := t.TempDir() db, err := NewBadger(&Config{Dir: dir}) require.NoError(t, err) @@ -58,9 +48,7 @@ func TestBadger_AddFeed(t *testing.T) { } func TestBadger_GetFeed(t *testing.T) { - dir, err := ioutil.TempDir("", "podsync-badger-") - assert.NoError(t, err) - defer os.RemoveAll(dir) + dir := t.TempDir() db, err := NewBadger(&Config{Dir: dir}) require.NoError(t, err) @@ -78,9 +66,7 @@ func TestBadger_GetFeed(t *testing.T) { } func TestBadger_WalkFeeds(t *testing.T) { - dir, err := ioutil.TempDir("", "podsync-badger-") - assert.NoError(t, err) - defer os.RemoveAll(dir) + dir := t.TempDir() db, err := NewBadger(&Config{Dir: dir}) require.NoError(t, err) @@ -104,9 +90,7 @@ func TestBadger_WalkFeeds(t *testing.T) { } func TestBadger_DeleteFeed(t *testing.T) { - dir, err := ioutil.TempDir("", "podsync-badger-") - assert.NoError(t, err) - defer os.RemoveAll(dir) + dir := t.TempDir() db, err := NewBadger(&Config{Dir: dir}) require.NoError(t, err) @@ -129,9 +113,7 @@ func TestBadger_DeleteFeed(t *testing.T) { } func TestBadger_UpdateEpisode(t *testing.T) { - dir, err := ioutil.TempDir("", "podsync-badger-") - assert.NoError(t, err) - defer os.RemoveAll(dir) + dir := t.TempDir() db, err := NewBadger(&Config{Dir: dir}) require.NoError(t, err) @@ -159,9 +141,7 @@ func TestBadger_UpdateEpisode(t *testing.T) { } func TestBadger_WalkEpisodes(t *testing.T) { - dir, err := ioutil.TempDir("", "podsync-badger-") - assert.NoError(t, err) - defer os.RemoveAll(dir) + dir := t.TempDir() db, err := NewBadger(&Config{Dir: dir}) require.NoError(t, err) diff --git a/pkg/fs/local_test.go b/pkg/fs/local_test.go index b20ca01b..4329886e 100644 --- a/pkg/fs/local_test.go +++ b/pkg/fs/local_test.go @@ -3,13 +3,11 @@ package fs import ( "bytes" "context" - "io/ioutil" "os" "path/filepath" "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var ( @@ -23,10 +21,8 @@ func TestNewLocal(t *testing.T) { } func TestLocal_Create(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "podsync-local-stor-") - require.NoError(t, err) - - defer os.RemoveAll(tmpDir) + tmpDir, err := os.MkdirTemp("", "") + assert.NoError(t, err) stor, err := NewLocal(tmpDir) assert.NoError(t, err) @@ -41,8 +37,8 @@ func TestLocal_Create(t *testing.T) { } func TestLocal_Size(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "podsync-local-stor-") - require.NoError(t, err) + tmpDir, err := os.MkdirTemp("", "") + assert.NoError(t, err) defer os.RemoveAll(tmpDir) @@ -66,10 +62,8 @@ func TestLocal_NoSize(t *testing.T) { } func TestLocal_Delete(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "podsync-local-stor-") - require.NoError(t, err) - - defer os.RemoveAll(tmpDir) + tmpDir, err := os.MkdirTemp("", "") + assert.NoError(t, err) stor, err := NewLocal(tmpDir) assert.NoError(t, err) @@ -89,11 +83,8 @@ func TestLocal_Delete(t *testing.T) { func TestLocal_copyFile(t *testing.T) { reader := bytes.NewReader([]byte{1, 2, 4}) - - tmpDir, err := ioutil.TempDir("", "podsync-test-") - require.NoError(t, err) - - defer os.RemoveAll(tmpDir) + tmpDir, err := os.MkdirTemp("", "") + assert.NoError(t, err) file := filepath.Join(tmpDir, "1") diff --git a/pkg/fs/s3_test.go b/pkg/fs/s3_test.go index ea403366..d5e56dcf 100644 --- a/pkg/fs/s3_test.go +++ b/pkg/fs/s3_test.go @@ -2,7 +2,7 @@ package fs import ( "bytes" - "io/ioutil" + "io" "os" "testing" @@ -98,7 +98,7 @@ func newMockS3(files map[string][]byte, prefix string) (*S3, error) { } func (m *mockS3API) PutObjectRequest(input *s3.PutObjectInput) (*request.Request, *s3.PutObjectOutput) { - content, _ := ioutil.ReadAll(input.Body) + content, _ := io.ReadAll(input.Body) req := request.New(aws.Config{}, metadata.ClientInfo{}, request.Handlers{}, nil, &request.Operation{}, nil, nil) m.files[*input.Key] = content return req, &s3.PutObjectOutput{} diff --git a/pkg/ytdl/ytdl.go b/pkg/ytdl/ytdl.go index 1d33a928..d641a657 100644 --- a/pkg/ytdl/ytdl.go +++ b/pkg/ytdl/ytdl.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net/http" "os" "os/exec" @@ -158,7 +157,7 @@ func (dl *YoutubeDl) Update(ctx context.Context) error { } func (dl *YoutubeDl) Download(ctx context.Context, feedConfig *feed.Config, episode *model.Episode) (r io.ReadCloser, err error) { - tmpDir, err := ioutil.TempDir("", "podsync-") + tmpDir, err := os.MkdirTemp("", "podsync-") if err != nil { return nil, errors.Wrap(err, "failed to get temp dir for download") }