Skip to content

Commit

Permalink
Merge pull request #172 from ardevd/replace-ioutil-calls
Browse files Browse the repository at this point in the history
refactor: replaced deprecated ioutil calls with os equivalents
  • Loading branch information
guggero authored Jan 15, 2024
2 parents 05065f4 + dacaa68 commit d286b88
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions basic_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package lndclient
import (
"encoding/hex"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/lightningnetwork/lnd/lncfg"
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 3 additions & 6 deletions basic_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package lndclient

import (
"encoding/hex"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions macaroon_pouch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package lndclient
import (
"context"
"encoding/hex"
"io/ioutil"
"os"
"path/filepath"

"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions macaroon_recipes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package lndclient_test
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"testing"

"github.com/lightninglabs/lndclient"
Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit d286b88

Please sign in to comment.