Skip to content

Commit

Permalink
change ioutil.TempFile -> os.CreateTemp
Browse files Browse the repository at this point in the history
Signed-off-by: Fedor Partanskiy <pfi79@mail.ru>
  • Loading branch information
pfi79 authored and C0rWin committed Aug 21, 2023
1 parent 9db6ed9 commit 2520b6f
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 24 deletions.
3 changes: 1 addition & 2 deletions cmd/common/signer/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"crypto/ecdsa"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -72,7 +71,7 @@ ZsQXrlIqlmNalfYPX+NDDELqlpXQBeEqnA==
},
} {
t.Run(testCase.description, func(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "key")
tmpFile, err := os.CreateTemp("", "key")
require.NoError(t, err)

defer os.Remove(tmpFile.Name())
Expand Down
9 changes: 4 additions & 5 deletions common/viperutil/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package viperutil

import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -133,7 +132,7 @@ func TestStringNotFromFile(t *testing.T) {
}

func TestStringFromFile(t *testing.T) {
file, err := ioutil.TempFile(os.TempDir(), "test")
file, err := os.CreateTemp(os.TempDir(), "test")
require.NoError(t, err, "failed to create temp file")
defer os.Remove(file.Name())

Expand All @@ -155,7 +154,7 @@ func TestStringFromFile(t *testing.T) {
}

func TestPEMBlocksFromFile(t *testing.T) {
file, err := ioutil.TempFile(os.TempDir(), "test")
file, err := os.CreateTemp(os.TempDir(), "test")
require.NoError(t, err, "failed to create temp file")
defer os.Remove(file.Name())

Expand All @@ -181,7 +180,7 @@ func TestPEMBlocksFromFile(t *testing.T) {
}

func TestPEMBlocksFromFileEnv(t *testing.T) {
file, err := ioutil.TempFile(os.TempDir(), "test")
file, err := os.CreateTemp(os.TempDir(), "test")
require.NoError(t, err, "failed to create temp file")
defer os.Remove(file.Name())

Expand Down Expand Up @@ -236,7 +235,7 @@ func TestStringFromFileNotSpecified(t *testing.T) {
func TestStringFromFileEnv(t *testing.T) {
expectedValue := "this is the text in the file"

file, err := ioutil.TempFile(os.TempDir(), "test")
file, err := os.CreateTemp(os.TempDir(), "test")
require.NoError(t, err, "failed to create temp file")
defer os.Remove(file.Name())

Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/persistence/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (f *FilesystemIO) WriteFile(path, name string, data []byte) error {
if path == "" {
return errors.New("empty path not allowed")
}
tmpFile, err := ioutil.TempFile(path, ".ccpackage.")
tmpFile, err := os.CreateTemp(path, ".ccpackage.")
if err != nil {
return errors.Wrapf(err, "error creating temp file in directory '%s'", path)
}
Expand Down
3 changes: 1 addition & 2 deletions core/common/ccprovider/ccinfocache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -234,7 +233,7 @@ func TestSetChaincodesPath(t *testing.T) {
cip := chaincodeInstallPath
defer SetChaincodesPath(cip)

f, err := ioutil.TempFile(dir, "chaincodes")
f, err := os.CreateTemp(dir, "chaincodes")
require.NoError(t, err)
require.Panics(t, func() {
SetChaincodesPath(f.Name())
Expand Down
5 changes: 2 additions & 3 deletions integration/nwo/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package nwo
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strconv"
Expand Down Expand Up @@ -102,7 +101,7 @@ func DeployChaincodeLegacy(n *Network, channel string, orderer *Orderer, chainco

// create temp file for chaincode package if not provided
if chaincode.PackageFile == "" {
tempFile, err := ioutil.TempFile("", "chaincode-package")
tempFile, err := os.CreateTemp("", "chaincode-package")
Expect(err).NotTo(HaveOccurred())
tempFile.Close()
defer os.Remove(tempFile.Name())
Expand All @@ -124,7 +123,7 @@ func DeployChaincodeLegacy(n *Network, channel string, orderer *Orderer, chainco
func PackageAndInstallChaincode(n *Network, chaincode Chaincode, peers ...*Peer) {
// create temp file for chaincode package if not provided
if chaincode.PackageFile == "" {
tempFile, err := ioutil.TempFile("", "chaincode-package")
tempFile, err := os.CreateTemp("", "chaincode-package")
Expect(err).NotTo(HaveOccurred())
tempFile.Close()
defer os.Remove(tempFile.Name())
Expand Down
4 changes: 2 additions & 2 deletions integration/nwo/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ func (n *Network) CreateAndJoinChannel(o *Orderer, channelName string) {
// TODO using configtxgen with -outputAnchorPeersUpdate to update the anchor peers is deprecated and does not work
// with channel participation API. We'll have to generate the channel update explicitly (see UpdateOrgAnchorPeers).
func (n *Network) UpdateChannelAnchors(o *Orderer, channelName string) {
tempFile, err := ioutil.TempFile("", "update-anchors")
tempFile, err := os.CreateTemp("", "update-anchors")
Expect(err).NotTo(HaveOccurred())
tempFile.Close()
defer os.Remove(tempFile.Name())
Expand Down Expand Up @@ -1170,7 +1170,7 @@ func (n *Network) JoinChannel(name string, o *Orderer, peers ...*Peer) {
return
}

tempFile, err := ioutil.TempFile("", "genesis-block")
tempFile, err := os.CreateTemp("", "genesis-block")
Expect(err).NotTo(HaveOccurred())
tempFile.Close()
defer os.Remove(tempFile.Name())
Expand Down
3 changes: 1 addition & 2 deletions integration/nwo/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"compress/gzip"
"encoding/json"
"io"
"io/ioutil"
"os"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -65,7 +64,7 @@ func writeMetadataJSON(tw *tar.Writer, path, ccType, label string) {

func writeCodeTarGz(tw *tar.Writer, codeFiles map[string]string) {
// create temp file to hold code.tar.gz
tempfile, err := ioutil.TempFile("", "code.tar.gz")
tempfile, err := os.CreateTemp("", "code.tar.gz")
Expect(err).NotTo(HaveOccurred())
defer os.Remove(tempfile.Name())

Expand Down
3 changes: 1 addition & 2 deletions integration/pvtdata/pvtdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -257,7 +256,7 @@ var _ = Describe("PrivateData", func() {
Eventually(p.Ready(), network.EventuallyTimeout).Should(BeClosed())

By("joining peer1.org2 to the channel with its Admin2 user")
tempFile, err := ioutil.TempFile("", "genesis-block")
tempFile, err := os.CreateTemp("", "genesis-block")
Expect(err).NotTo(HaveOccurred())
tempFile.Close()
defer os.Remove(tempFile.Name())
Expand Down
3 changes: 1 addition & 2 deletions integration/raft/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -1833,7 +1832,7 @@ type certificateChange struct {
// extendNetwork rotates adds an additional orderer
func extendNetwork(n *nwo.Network) {
// Overwrite the current crypto-config with additional orderers
cryptoConfigYAML, err := ioutil.TempFile("", "crypto-config.yaml")
cryptoConfigYAML, err := os.CreateTemp("", "crypto-config.yaml")
Expect(err).NotTo(HaveOccurred())
defer os.Remove(cryptoConfigYAML.Name())

Expand Down
3 changes: 1 addition & 2 deletions msp/configbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package msp

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -94,7 +93,7 @@ func TestGetLocalMspConfigFails(t *testing.T) {
}

func TestGetPemMaterialFromDirWithFile(t *testing.T) {
tempFile, err := ioutil.TempFile("", "fabric-msp-test")
tempFile, err := os.CreateTemp("", "fabric-msp-test")
require.NoError(t, err)
err = tempFile.Close()
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion orderer/consensus/etcdraft/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ var _ = Describe("Chain", func() {

When("WAL dir is a file", func() {
It("replaces file with fresh WAL dir", func() {
f, err := ioutil.TempFile("", "wal-")
f, err := os.CreateTemp("", "wal-")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(f.Name())

Expand Down

0 comments on commit 2520b6f

Please sign in to comment.