Skip to content

Commit

Permalink
Replace deprecated function calls
Browse files Browse the repository at this point in the history
Signed-off-by: Maksym Pavlenko <[email protected]>
  • Loading branch information
mxpv committed Apr 1, 2024
1 parent d8e042a commit 7a81903
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 53 deletions.
4 changes: 2 additions & 2 deletions cmd/podsync/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podsync/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -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()
Expand Down
36 changes: 8 additions & 28 deletions pkg/db/badger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package db

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

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 8 additions & 17 deletions pkg/fs/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions pkg/fs/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fs

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

Expand Down Expand Up @@ -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{}
Expand Down
3 changes: 1 addition & 2 deletions pkg/ytdl/ytdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 7a81903

Please sign in to comment.