From dacaa68ee6a5c09bcc4b8b0410994361fd3ae2b8 Mon Sep 17 00:00:00 2001 From: ardevd Date: Mon, 15 Jan 2024 16:34:18 +0100 Subject: [PATCH] refactor: replaced deprecated ioutil calls with os equivalents --- basic_client.go | 4 ++-- basic_client_test.go | 9 +++------ macaroon_pouch.go | 4 ++-- macaroon_recipes_test.go | 4 ++-- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/basic_client.go b/basic_client.go index 0bb7ab2..8a4e57d 100644 --- a/basic_client.go +++ b/basic_client.go @@ -3,7 +3,7 @@ package lndclient import ( "encoding/hex" "fmt" - "io/ioutil" + "os" "path/filepath" "github.com/lightningnetwork/lnd/lncfg" @@ -184,7 +184,7 @@ func parseTLSAndMacaroon(tlsPath, macDir, network string, macPath := filepath.Join(macDir, bco.macFilename) // Load the specified macaroon file. - macBytes, err = ioutil.ReadFile(macPath) + macBytes, err = os.ReadFile(macPath) if err != nil { return nil, nil, err } diff --git a/basic_client_test.go b/basic_client_test.go index 3a4cb86..0749fcf 100644 --- a/basic_client_test.go +++ b/basic_client_test.go @@ -2,7 +2,6 @@ package lndclient import ( "encoding/hex" - "io/ioutil" "os" "testing" @@ -46,21 +45,19 @@ XhkpT5dliEGFLNe6OOgeWTU1JpEXfCud/GImtNMHQi4EDWQfvWuCNGhOoQ== // Now let's write the data to a file to make sure parseTLSAndMacaroon // parses that properly as well. - tempDirPath, err := ioutil.TempDir("", ".testCreds") - require.NoError(t, err) - defer os.RemoveAll(tempDirPath) + tempDirPath := t.TempDir() certPath := tempDirPath + "/tls.cert" tlsPEMBytes := []byte(tlsData) - err = ioutil.WriteFile(certPath, tlsPEMBytes, 0644) + err = os.WriteFile(certPath, tlsPEMBytes, 0644) require.NoError(t, err) macPath := tempDirPath + "/test.macaroon" macBytes, err := hex.DecodeString(macData) require.NoError(t, err) - err = ioutil.WriteFile(macPath, macBytes, 0644) + err = os.WriteFile(macPath, macBytes, 0644) require.NoError(t, err) _, _, err = parseTLSAndMacaroon( diff --git a/macaroon_pouch.go b/macaroon_pouch.go index 5adf85b..a2115ad 100644 --- a/macaroon_pouch.go +++ b/macaroon_pouch.go @@ -3,7 +3,7 @@ package lndclient import ( "context" "encoding/hex" - "io/ioutil" + "os" "path/filepath" "google.golang.org/grpc/metadata" @@ -64,7 +64,7 @@ type serializedMacaroon string // newSerializedMacaroon reads a new serializedMacaroon from that target // macaroon path. If the file can't be found, then an error is returned. func newSerializedMacaroon(macaroonPath string) (serializedMacaroon, error) { - macBytes, err := ioutil.ReadFile(macaroonPath) + macBytes, err := os.ReadFile(macaroonPath) if err != nil { return "", err } diff --git a/macaroon_recipes_test.go b/macaroon_recipes_test.go index ab1a2d3..dcb5baa 100644 --- a/macaroon_recipes_test.go +++ b/macaroon_recipes_test.go @@ -3,7 +3,7 @@ package lndclient_test import ( "context" "encoding/json" - "io/ioutil" + "os" "testing" "github.com/lightninglabs/lndclient" @@ -48,7 +48,7 @@ func (m *lightningMock) ListPermissions( func TestMacaroonRecipe(t *testing.T) { // Load our static permissions exported from lnd by calling // `lncli listpermissions > permissions.json`. - content, err := ioutil.ReadFile("testdata/permissions.json") + content, err := os.ReadFile("testdata/permissions.json") require.NoError(t, err) data := &permissionJSONData{}