1
0
Fork 0

Merge pull request #1607 from rqlite/remove-obsolte

Remove use of deprecated ioutil
master
Philip O'Toole 8 months ago committed by GitHub
commit 19d03cc1e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,3 +1,7 @@
## 8.16.7 (unreleased)
### Implementation changes and bug fixes
- [PR #1607](https://github.com/rqlite/rqlite/pull/1607): Remove use of deprecated `ioutil`.
## 8.16.6 (January 16th 2024) ## 8.16.6 (January 16th 2024)
### Implementation changes and bug fixes ### Implementation changes and bug fixes
- [PR #1603](https://github.com/rqlite/rqlite/pull/1603): Standardize logging by Raft module. - [PR #1603](https://github.com/rqlite/rqlite/pull/1603): Standardize logging by Raft module.

@ -3,7 +3,6 @@ package backup
import ( import (
"bytes" "bytes"
"errors" "errors"
"io/ioutil"
"os" "os"
"reflect" "reflect"
"testing" "testing"
@ -16,7 +15,7 @@ import (
func Test_ReadConfigFile(t *testing.T) { func Test_ReadConfigFile(t *testing.T) {
t.Run("valid config file", func(t *testing.T) { t.Run("valid config file", func(t *testing.T) {
// Create a temporary config file // Create a temporary config file
tempFile, err := ioutil.TempFile("", "upload_config") tempFile, err := os.CreateTemp("", "upload_config")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -52,7 +51,7 @@ func Test_ReadConfigFile(t *testing.T) {
defer os.Unsetenv("TEST_VAR") defer os.Unsetenv("TEST_VAR")
// Create a temporary config file with an environment variable // Create a temporary config file with an environment variable
tempFile, err := ioutil.TempFile("", "upload_config") tempFile, err := os.CreateTemp("", "upload_config")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -82,7 +81,7 @@ func Test_ReadConfigFile(t *testing.T) {
defer os.Unsetenv("TEST_VAR1") defer os.Unsetenv("TEST_VAR1")
// Create a temporary config file with an environment variable // Create a temporary config file with an environment variable
tempFile, err := ioutil.TempFile("", "upload_config") tempFile, err := os.CreateTemp("", "upload_config")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -2,7 +2,7 @@ package restore
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io"
"os" "os"
"time" "time"
@ -52,7 +52,7 @@ func ReadConfigFile(filename string) ([]byte, error) {
} }
defer f.Close() defer f.Close()
data, err := ioutil.ReadAll(f) data, err := io.ReadAll(f)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -3,7 +3,6 @@ package restore
import ( import (
"bytes" "bytes"
"errors" "errors"
"io/ioutil"
"os" "os"
"reflect" "reflect"
"testing" "testing"
@ -16,7 +15,7 @@ import (
func Test_ReadConfigFile(t *testing.T) { func Test_ReadConfigFile(t *testing.T) {
t.Run("valid config file", func(t *testing.T) { t.Run("valid config file", func(t *testing.T) {
// Create a temporary config file // Create a temporary config file
tempFile, err := ioutil.TempFile("", "upload_config") tempFile, err := os.CreateTemp("", "upload_config")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -52,7 +51,7 @@ func Test_ReadConfigFile(t *testing.T) {
defer os.Unsetenv("TEST_VAR") defer os.Unsetenv("TEST_VAR")
// Create a temporary config file with an environment variable // Create a temporary config file with an environment variable
tempFile, err := ioutil.TempFile("", "upload_config") tempFile, err := os.CreateTemp("", "upload_config")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -82,7 +81,7 @@ func Test_ReadConfigFile(t *testing.T) {
defer os.Unsetenv("TEST_VAR1") defer os.Unsetenv("TEST_VAR1")
// Create a temporary config file with an environment variable // Create a temporary config file with an environment variable
tempFile, err := ioutil.TempFile("", "upload_config") tempFile, err := os.CreateTemp("", "upload_config")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"time" "time"
) )
@ -60,7 +59,7 @@ func (h *QueuedHTTPTester) Once() (time.Duration, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
_, err = ioutil.ReadAll(resp.Body) _, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
return 0, err return 0, err
} }

@ -5,7 +5,6 @@ import (
"compress/gzip" "compress/gzip"
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
"testing" "testing"
@ -22,7 +21,7 @@ func Test_SingleChunk(t *testing.T) {
Data: mustCompressData(data), Data: mustCompressData(data),
} }
dir, err := ioutil.TempDir("", "dechunker-test") dir, err := os.MkdirTemp("", "dechunker-test")
if err != nil { if err != nil {
t.Fatalf("failed to create temp dir: %v", err) t.Fatalf("failed to create temp dir: %v", err)
} }
@ -47,7 +46,7 @@ func Test_SingleChunk(t *testing.T) {
} }
// Check the contents of the output file. // Check the contents of the output file.
got, err := ioutil.ReadFile(filePath) got, err := os.ReadFile(filePath)
if err != nil { if err != nil {
t.Fatalf("failed to read output file: %v", err) t.Fatalf("failed to read output file: %v", err)
} }
@ -72,7 +71,7 @@ func Test_MultiChunk(t *testing.T) {
Data: mustCompressData(data2), Data: mustCompressData(data2),
} }
dir, err := ioutil.TempDir("", "dechunker-test") dir, err := os.MkdirTemp("", "dechunker-test")
if err != nil { if err != nil {
t.Fatalf("failed to create temp dir: %v", err) t.Fatalf("failed to create temp dir: %v", err)
} }
@ -99,7 +98,7 @@ func Test_MultiChunk(t *testing.T) {
} }
// Check the contents of the output file. // Check the contents of the output file.
got, err := ioutil.ReadFile(filePath) got, err := os.ReadFile(filePath)
if err != nil { if err != nil {
t.Fatalf("failed to read output file: %v", err) t.Fatalf("failed to read output file: %v", err)
} }
@ -130,7 +129,7 @@ func Test_MultiChunkNilData(t *testing.T) {
Data: nil, Data: nil,
} }
dir, err := ioutil.TempDir("", "dechunker-test") dir, err := os.MkdirTemp("", "dechunker-test")
if err != nil { if err != nil {
t.Fatalf("failed to create temp dir: %v", err) t.Fatalf("failed to create temp dir: %v", err)
} }
@ -157,7 +156,7 @@ func Test_MultiChunkNilData(t *testing.T) {
} }
// Check the contents of the output file. // Check the contents of the output file.
got, err := ioutil.ReadFile(filePath) got, err := os.ReadFile(filePath)
if err != nil { if err != nil {
t.Fatalf("failed to read output file: %v", err) t.Fatalf("failed to read output file: %v", err)
} }
@ -184,7 +183,7 @@ func Test_UnexpectedStreamID(t *testing.T) {
Data: compressedData, Data: compressedData,
} }
dir, err := ioutil.TempDir("", "dechunker-test") dir, err := os.MkdirTemp("", "dechunker-test")
if err != nil { if err != nil {
t.Fatalf("failed to create temp dir: %v", err) t.Fatalf("failed to create temp dir: %v", err)
} }
@ -228,7 +227,7 @@ func Test_ChunksOutOfOrder(t *testing.T) {
Data: compressedData, Data: compressedData,
} }
dir, err := ioutil.TempDir("", "dechunker-test") dir, err := os.MkdirTemp("", "dechunker-test")
if err != nil { if err != nil {
t.Fatalf("failed to create temp dir: %v", err) t.Fatalf("failed to create temp dir: %v", err)
} }
@ -256,7 +255,7 @@ func Test_ChunksOutOfOrder(t *testing.T) {
} }
func Test_ReassemblyOfLargeData(t *testing.T) { func Test_ReassemblyOfLargeData(t *testing.T) {
dir, err := ioutil.TempDir("", "test-*") dir, err := os.MkdirTemp("", "test-*")
if err != nil { if err != nil {
t.Fatalf("failed to create temp dir: %v", err) t.Fatalf("failed to create temp dir: %v", err)
} }
@ -300,7 +299,7 @@ func Test_ReassemblyOfLargeData(t *testing.T) {
defer os.Remove(outFilePath) defer os.Remove(outFilePath)
// The output data should be the same as the original largeData. // The output data should be the same as the original largeData.
outData, err := ioutil.ReadFile(outFilePath) outData, err := os.ReadFile(outFilePath)
if err != nil { if err != nil {
t.Fatalf("failed to read output file data: %v", err) t.Fatalf("failed to read output file data: %v", err)
} }

@ -2,7 +2,6 @@ package db
import ( import (
"errors" "errors"
"io/ioutil"
"os" "os"
"strings" "strings"
"testing" "testing"
@ -1139,7 +1138,7 @@ func testSerialize(t *testing.T, db *DB) {
t.Fatalf("failed to insert records: %s", err.Error()) t.Fatalf("failed to insert records: %s", err.Error())
} }
dstDB, err := ioutil.TempFile("", "rqlite-bak-") dstDB, err := os.CreateTemp("", "rqlite-bak-")
if err != nil { if err != nil {
t.Fatalf("failed to create temp file: %s", err.Error()) t.Fatalf("failed to create temp file: %s", err.Error())
} }
@ -1156,7 +1155,7 @@ func testSerialize(t *testing.T, db *DB) {
t.Fatalf("expected DELETE mode to be enabled") t.Fatalf("expected DELETE mode to be enabled")
} }
err = ioutil.WriteFile(dstDB.Name(), b, 0644) err = os.WriteFile(dstDB.Name(), b, 0644)
if err != nil { if err != nil {
t.Fatalf("failed to write serialized database to file: %s", err.Error()) t.Fatalf("failed to write serialized database to file: %s", err.Error())
} }

@ -1,7 +1,6 @@
package log package log
import ( import (
"io/ioutil"
"os" "os"
"testing" "testing"
@ -476,7 +475,7 @@ func Test_LogStats(t *testing.T) {
// mustTempFile returns a path to a temporary file in directory dir. It is up to the // mustTempFile returns a path to a temporary file in directory dir. It is up to the
// caller to remove the file once it is no longer needed. // caller to remove the file once it is no longer needed.
func mustTempFile() string { func mustTempFile() string {
tmpfile, err := ioutil.TempFile("", "rqlite-db-test") tmpfile, err := os.CreateTemp("", "rqlite-db-test")
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())
} }

Loading…
Cancel
Save