diff --git a/cmd/common/signer/signer_test.go b/cmd/common/signer/signer_test.go index 54501807f65..1b0211f3025 100644 --- a/cmd/common/signer/signer_test.go +++ b/cmd/common/signer/signer_test.go @@ -10,7 +10,6 @@ import ( "crypto/ecdsa" "crypto/x509" "encoding/pem" - "io/ioutil" "os" "path/filepath" "testing" @@ -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()) diff --git a/common/viperutil/config_test.go b/common/viperutil/config_test.go index 1b7dfc76c0e..70965ac4b85 100644 --- a/common/viperutil/config_test.go +++ b/common/viperutil/config_test.go @@ -8,7 +8,6 @@ package viperutil import ( "fmt" - "io/ioutil" "os" "strings" "testing" @@ -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()) @@ -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()) @@ -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()) @@ -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()) diff --git a/core/chaincode/persistence/persistence.go b/core/chaincode/persistence/persistence.go index 6132544c535..bd5c85db23c 100644 --- a/core/chaincode/persistence/persistence.go +++ b/core/chaincode/persistence/persistence.go @@ -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) } diff --git a/core/common/ccprovider/ccinfocache_test.go b/core/common/ccprovider/ccinfocache_test.go index 299b6514b54..45b15762db0 100644 --- a/core/common/ccprovider/ccinfocache_test.go +++ b/core/common/ccprovider/ccinfocache_test.go @@ -20,7 +20,6 @@ import ( "archive/tar" "bytes" "compress/gzip" - "io/ioutil" "os" "path/filepath" "testing" @@ -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()) diff --git a/integration/nwo/deploy.go b/integration/nwo/deploy.go index 4df2d453184..87e07aa53f8 100644 --- a/integration/nwo/deploy.go +++ b/integration/nwo/deploy.go @@ -9,7 +9,6 @@ package nwo import ( "encoding/json" "fmt" - "io/ioutil" "os" "os/exec" "strconv" @@ -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()) @@ -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()) diff --git a/integration/nwo/network.go b/integration/nwo/network.go index bc10abfc74c..25ff0571b3f 100644 --- a/integration/nwo/network.go +++ b/integration/nwo/network.go @@ -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()) @@ -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()) diff --git a/integration/nwo/package.go b/integration/nwo/package.go index b7259517564..619e72d084f 100644 --- a/integration/nwo/package.go +++ b/integration/nwo/package.go @@ -11,7 +11,6 @@ import ( "compress/gzip" "encoding/json" "io" - "io/ioutil" "os" . "github.com/onsi/gomega" @@ -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()) diff --git a/integration/pvtdata/pvtdata_test.go b/integration/pvtdata/pvtdata_test.go index 39cb64b66d0..04618fef7b6 100644 --- a/integration/pvtdata/pvtdata_test.go +++ b/integration/pvtdata/pvtdata_test.go @@ -11,7 +11,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -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()) diff --git a/integration/raft/config_test.go b/integration/raft/config_test.go index 1b33aa48dc5..1cd70cb3e8b 100644 --- a/integration/raft/config_test.go +++ b/integration/raft/config_test.go @@ -11,7 +11,6 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" "net/http" "os" "path" @@ -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()) diff --git a/msp/configbuilder_test.go b/msp/configbuilder_test.go index a6bb3488c99..863224a0c3d 100644 --- a/msp/configbuilder_test.go +++ b/msp/configbuilder_test.go @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0 package msp import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -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) diff --git a/orderer/consensus/etcdraft/chain_test.go b/orderer/consensus/etcdraft/chain_test.go index 2cafdfe7113..3a8b74f8663 100644 --- a/orderer/consensus/etcdraft/chain_test.go +++ b/orderer/consensus/etcdraft/chain_test.go @@ -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())