Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove dependency on io/ioutil #1879

Merged
merged 1 commit into from
Feb 21, 2023
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
21 changes: 10 additions & 11 deletions backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package badger
import (
"bytes"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand All @@ -34,7 +33,7 @@ import (
)

func TestBackupRestore1(t *testing.T) {
dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)
db, err := Open(getTestOptions(dir))
Expand Down Expand Up @@ -72,10 +71,10 @@ func TestBackupRestore1(t *testing.T) {
require.NoError(t, err)

// Use different directory.
dir, err = ioutil.TempDir("", "badger-test")
dir, err = os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)
bak, err := ioutil.TempFile(dir, "badgerbak")
bak, err := os.CreateTemp(dir, "badgerbak")
require.NoError(t, err)
_, err = db.Backup(bak, 0)
require.NoError(t, err)
Expand Down Expand Up @@ -118,7 +117,7 @@ func TestBackupRestore1(t *testing.T) {
}

func TestBackupRestore2(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "badger-test")
tmpdir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)

defer removeDir(tmpdir)
Expand Down Expand Up @@ -306,7 +305,7 @@ func TestBackup(t *testing.T) {
require.NoError(t, err)
}
t.Run("disk mode", func(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "badger-test")
tmpdir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)

defer removeDir(tmpdir)
Expand All @@ -326,7 +325,7 @@ func TestBackup(t *testing.T) {

func TestBackupRestore3(t *testing.T) {
var bb bytes.Buffer
tmpdir, err := ioutil.TempDir("", "badger-test")
tmpdir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)

defer removeDir(tmpdir)
Expand Down Expand Up @@ -387,7 +386,7 @@ func TestBackupRestore3(t *testing.T) {
}

func TestBackupLoadIncremental(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "badger-test")
tmpdir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)

defer removeDir(tmpdir)
Expand Down Expand Up @@ -507,7 +506,7 @@ func TestBackupLoadIncremental(t *testing.T) {
}

func TestBackupBitClear(t *testing.T) {
dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)

Expand All @@ -528,11 +527,11 @@ func TestBackupBitClear(t *testing.T) {
require.NoError(t, err)

// Use different directory.
dir, err = ioutil.TempDir("", "badger-test")
dir, err = os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)

bak, err := ioutil.TempFile(dir, "badgerbak")
bak, err := os.CreateTemp(dir, "badgerbak")
require.NoError(t, err)
_, err = db.Backup(bak, 0)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions badger/cmd/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"log"
"math"
"math/rand"
"os"
"strconv"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -382,7 +382,7 @@ func runTest(cmd *cobra.Command, args []string) error {
var tmpDb *badger.DB
var subscribeDB *badger.DB
if checkSubscriber {
dir, err := ioutil.TempDir("", "bank_subscribe")
dir, err := os.MkdirTemp("", "bank_subscribe")
y.Check(err)

subscribeDB, err = badger.Open(badger.DefaultOptions(dir).WithSyncWrites(false))
Expand All @@ -393,7 +393,7 @@ func runTest(cmd *cobra.Command, args []string) error {
}

if checkStream {
dir, err := ioutil.TempDir("", "bank_stream")
dir, err := os.MkdirTemp("", "bank_stream")
y.Check(err)

tmpDb, err = badger.Open(badger.DefaultOptions(dir).WithSyncWrites(false))
Expand Down
4 changes: 2 additions & 2 deletions badger/cmd/rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package cmd

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

Expand Down Expand Up @@ -79,5 +79,5 @@ func getKey(path string) ([]byte, error) {
if err != nil {
return nil, err
}
return ioutil.ReadAll(fp)
return io.ReadAll(fp)
}
11 changes: 5 additions & 6 deletions badger/cmd/rotate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package cmd

import (
"io/ioutil"
"math/rand"
"os"
"testing"
Expand All @@ -29,7 +28,7 @@ import (
)

func TestRotate(t *testing.T) {
dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

Expand All @@ -38,7 +37,7 @@ func TestRotate(t *testing.T) {
_, err = rand.Read(key)
require.NoError(t, err)

fp, err := ioutil.TempFile("", "*.key")
fp, err := os.CreateTemp("", "*.key")
require.NoError(t, err)
_, err = fp.Write(key)
require.NoError(t, err)
Expand All @@ -64,7 +63,7 @@ func TestRotate(t *testing.T) {
key2 := make([]byte, 32)
_, err = rand.Read(key2)
require.NoError(t, err)
fp2, err := ioutil.TempFile("", "*.key")
fp2, err := os.CreateTemp("", "*.key")
require.NoError(t, err)
_, err = fp2.Write(key2)
require.NoError(t, err)
Expand Down Expand Up @@ -99,7 +98,7 @@ func TestRotate(t *testing.T) {

// This test shows that rotate tool can be used to enable encryption.
func TestRotatePlainTextToEncrypted(t *testing.T) {
dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

Expand All @@ -117,7 +116,7 @@ func TestRotatePlainTextToEncrypted(t *testing.T) {
// Create an encryption key.
key := make([]byte, 32)
y.Check2(rand.Read(key))
fp, err := ioutil.TempFile("", "*.key")
fp, err := os.CreateTemp("", "*.key")
require.NoError(t, err)
_, err = fp.Write(key)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package badger

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

Expand Down Expand Up @@ -150,7 +150,7 @@ func TestFlushPanic(t *testing.T) {
}

func TestBatchErrDeadlock(t *testing.T) {
dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)

Expand Down
19 changes: 9 additions & 10 deletions db2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"encoding/binary"
"flag"
"fmt"
"io/ioutil"
"log"
"math"
"math/rand"
Expand Down Expand Up @@ -54,7 +53,7 @@ func TestTruncateVlogWithClose(t *testing.T) {
return m
}

dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)

Expand Down Expand Up @@ -425,7 +424,7 @@ func TestBigValues(t *testing.T) {
// tables on level 3 and 3 tables on level 2. Tables on level 2 have overlap with 2, 4, 3 tables on
// level 3.
func TestCompactionFilePicking(t *testing.T) {
dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)

Expand Down Expand Up @@ -578,7 +577,7 @@ func TestReadSameVlog(t *testing.T) {
func TestL0GCBug(t *testing.T) {
t.Skipf("TestL0GCBug is DISABLED. TODO(ibrahim): Do we need this?")

dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)

Expand Down Expand Up @@ -673,7 +672,7 @@ func TestWindowsDataLoss(t *testing.T) {
t.Skip("The test is only for Windows.")
}

dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)

Expand Down Expand Up @@ -826,7 +825,7 @@ func TestIsClosed(t *testing.T) {
if inMemory {
opt.InMemory = true
} else {
dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)

Expand Down Expand Up @@ -867,7 +866,7 @@ func TestMaxVersion(t *testing.T) {
})
})
t.Run("multiple versions", func(t *testing.T) {
dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)

Expand All @@ -893,7 +892,7 @@ func TestMaxVersion(t *testing.T) {
require.NoError(t, db.Close())
})
t.Run("Managed mode", func(t *testing.T) {
dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)

Expand All @@ -919,7 +918,7 @@ func TestMaxVersion(t *testing.T) {
}

func TestTxnReadTs(t *testing.T) {
dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)

Expand Down Expand Up @@ -1017,7 +1016,7 @@ func TestKeyCount(t *testing.T) {
}

N := uint64(10 * 1e6) // 10 million entries
dir, err := ioutil.TempDir("", "badger-test")
dir, err := os.MkdirTemp("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)
opt := DefaultOptions(dir).
Expand Down
Loading