Skip to content

Commit

Permalink
change ioutil.ReadAll -> io.ReadAll
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 denyeart committed Aug 19, 2023
1 parent 79468d8 commit 59ccd8d
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 46 deletions.
5 changes: 2 additions & 3 deletions cmd/cryptogen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"text/template"
Expand Down Expand Up @@ -241,14 +240,14 @@ func getConfig() (*Config, error) {
var configData string

if *genConfigFile != nil {
data, err := ioutil.ReadAll(*genConfigFile)
data, err := io.ReadAll(*genConfigFile)
if err != nil {
return nil, fmt.Errorf("Error reading configuration: %s", err)
}

configData = string(data)
} else if *extConfigFile != nil {
data, err := ioutil.ReadAll(*extConfigFile)
data, err := io.ReadAll(*extConfigFile)
if err != nil {
return nil, fmt.Errorf("Error reading configuration: %s", err)
}
Expand Down
5 changes: 3 additions & 2 deletions common/fabhttp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package fabhttp_test
import (
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
Expand Down Expand Up @@ -114,7 +115,7 @@ var _ = Describe("Server", func() {
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
Expect(resp.Header.Get("Content-Type")).To(Equal("text/plain; charset=utf-8"))
buff, err := ioutil.ReadAll(resp.Body)
buff, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(buff)).To(Equal("secure"))
resp.Body.Close()
Expand Down Expand Up @@ -151,7 +152,7 @@ var _ = Describe("Server", func() {
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
Expect(resp.Header.Get("Content-Type")).To(Equal("text/plain; charset=utf-8"))
buff, err := ioutil.ReadAll(resp.Body)
buff, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(buff)).To(Equal("insecure"))
resp.Body.Close()
Expand Down
14 changes: 7 additions & 7 deletions common/metrics/prometheus/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package prometheus_test

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"

Expand Down Expand Up @@ -72,7 +72,7 @@ var _ = Describe("Provider", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(bytes)).To(ContainSubstring(`# HELP peer_playground_counter_name This is some help text for the counter`))
Expect(string(bytes)).To(ContainSubstring(`# TYPE peer_playground_counter_name counter`))
Expand All @@ -93,7 +93,7 @@ var _ = Describe("Provider", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(bytes)).To(ContainSubstring(`peer_playground_counter_name 1`))
})
Expand Down Expand Up @@ -124,7 +124,7 @@ var _ = Describe("Provider", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(bytes)).To(ContainSubstring(`# HELP peer_playground_gauge_name This is some help text for the gauge`))
Expect(string(bytes)).To(ContainSubstring(`# TYPE peer_playground_gauge_name gauge`))
Expand Down Expand Up @@ -158,7 +158,7 @@ var _ = Describe("Provider", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(bytes)).To(ContainSubstring(`# HELP peer_playground_histogram_name This is some help text for the gauge`))
Expect(string(bytes)).To(ContainSubstring(`# TYPE peer_playground_histogram_name histogram`))
Expand Down Expand Up @@ -189,7 +189,7 @@ var _ = Describe("Provider", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(bytes)).To(ContainSubstring(`# HELP peer_playground_histogram_name This is some help text for the gauge`))
Expect(string(bytes)).To(ContainSubstring(`# TYPE peer_playground_histogram_name histogram`))
Expand Down Expand Up @@ -223,7 +223,7 @@ var _ = Describe("Provider", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(bytes)).To(ContainSubstring(`# HELP peer_playground_counter_name This is some help text for the counter`))
Expect(string(bytes)).To(ContainSubstring(`# TYPE peer_playground_counter_name counter`))
Expand Down
4 changes: 2 additions & 2 deletions core/chaincode/persistence/chaincode_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (cps *ChaincodePackageStreamer) MetadataBytes() ([]byte, error) {

defer tarFileStream.Close()

md, err := ioutil.ReadAll(tarFileStream)
md, err := io.ReadAll(tarFileStream)
if err != nil {
return nil, errors.WithMessage(err, "could read metadata file")
}
Expand Down Expand Up @@ -303,7 +303,7 @@ func ParseChaincodePackage(source []byte) (*ChaincodePackageMetadata, []byte, er
return ccPackageMetadata, nil, errors.Errorf("tar entry %s is not a regular file, type %v", header.Name, header.Typeflag)
}

fileBytes, err := ioutil.ReadAll(tarReader)
fileBytes, err := io.ReadAll(tarReader)
if err != nil {
return ccPackageMetadata, nil, errors.Wrapf(err, "could not read %s from tar", header.Name)
}
Expand Down
10 changes: 5 additions & 5 deletions core/chaincode/persistence/chaincode_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package persistence_test

import (
"io/ioutil"
"io"
"os"

pb "github.com/hyperledger/fabric-protos-go/peer"
Expand Down Expand Up @@ -48,7 +48,7 @@ var _ = Describe("FallbackPackageLocator", func() {
Label: "Real-Label",
}))
Expect(mdBytes).To(MatchJSON(`{"type":"Fake-Type","path":"Fake-Path","label":"Real-Label","extra_field":"extra-field-value"}`))
code, err := ioutil.ReadAll(stream)
code, err := io.ReadAll(stream)
Expect(err).NotTo(HaveOccurred())
Expect(code).To(Equal([]byte("package")))
Expect(fakeLegacyLocator.GetChaincodeDepSpecCallCount()).To(Equal(0))
Expand Down Expand Up @@ -92,7 +92,7 @@ var _ = Describe("FallbackPackageLocator", func() {
Type: "GOLANG",
}))
Expect(mdBytes).To(MatchJSON(`{"type":"GOLANG","path":"legacy-path","label":""}`))
code, err := ioutil.ReadAll(stream)
code, err := io.ReadAll(stream)
Expect(err).NotTo(HaveOccurred())
Expect(code).To(Equal([]byte("legacy-code")))
})
Expand Down Expand Up @@ -322,7 +322,7 @@ var _ = Describe("ChaincodePackageStreamer", func() {
It("reads a file from the package", func() {
code, err := streamer.Code()
Expect(err).NotTo(HaveOccurred())
codeBytes, err := ioutil.ReadAll(code)
codeBytes, err := io.ReadAll(code)
code.Close()
Expect(err).NotTo(HaveOccurred())
Expect(codeBytes).To(Equal([]byte("package")))
Expand All @@ -344,7 +344,7 @@ var _ = Describe("ChaincodePackageStreamer", func() {
It("reads a file from the package", func() {
code, err := streamer.File("code.tar.gz")
Expect(err).NotTo(HaveOccurred())
codeBytes, err := ioutil.ReadAll(code)
codeBytes, err := io.ReadAll(code)
code.Close()
Expect(err).NotTo(HaveOccurred())
Expect(codeBytes).To(Equal([]byte("package")))
Expand Down
6 changes: 3 additions & 3 deletions core/chaincode/platforms/platforms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"io"

docker "github.com/fsouza/go-dockerclient"
"github.com/hyperledger/fabric/common/metadata"
Expand Down Expand Up @@ -145,7 +145,7 @@ ENV CORE_CHAINCODE_BUILDLEVEL=%s`, metadata.Version, metadata.Version)
It("creates a stream for the package", func() {
reader, err := registry.GenerateDockerBuild("fakeType", "", nil, client)
Expect(err).NotTo(HaveOccurred())
_, err = ioutil.ReadAll(reader)
_, err = io.ReadAll(reader)
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -162,7 +162,7 @@ ENV CORE_CHAINCODE_BUILDLEVEL=%s`, metadata.Version, metadata.Version)
pw.WriteReturns(errors.New("fake-error"))
reader, err := registry.GenerateDockerBuild("fakeType", "", nil, client)
Expect(err).NotTo(HaveOccurred())
_, err = ioutil.ReadAll(reader)
_, err = io.ReadAll(reader)
Expect(err).To(MatchError("Failed to inject \"Dockerfile\": fake-error"))
})
})
Expand Down
3 changes: 1 addition & 2 deletions core/common/ccprovider/cc_statedb_artifacts_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"path/filepath"
"strings"
)
Expand Down Expand Up @@ -81,7 +80,7 @@ func ExtractFileEntries(tarBytes []byte, databaseType string) (map[string][]*Tar
dir, _ := filepath.Split(hdr.Name)
// remove the ending slash
if strings.HasPrefix(hdr.Name, "META-INF/statedb/"+databaseType) {
fileContent, err := ioutil.ReadAll(tarReader)
fileContent, err := io.ReadAll(tarReader)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions core/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package container_test

import (
"bytes"
"io"
"io/ioutil"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -64,7 +65,7 @@ var _ = Describe("Router", func() {
ccid, md, codeStream := fakeExternalBuilder.BuildArgsForCall(0)
Expect(ccid).To(Equal("package-id"))
Expect(md).To(Equal([]byte(`{"some":"json"}`)))
codePackage, err := ioutil.ReadAll(codeStream)
codePackage, err := io.ReadAll(codeStream)
Expect(err).NotTo(HaveOccurred())
Expect(codePackage).To(Equal([]byte("code-bytes")))
})
Expand Down Expand Up @@ -124,7 +125,7 @@ var _ = Describe("Router", func() {
Type: "package-type",
Path: "package-path",
}))
codePackage, err := ioutil.ReadAll(codeStream)
codePackage, err := io.ReadAll(codeStream)
Expect(err).NotTo(HaveOccurred())
Expect(codePackage).To(Equal([]byte("code-bytes")))
})
Expand Down
3 changes: 1 addition & 2 deletions core/container/dockercontroller/dockercontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"testing"
"time"

Expand Down Expand Up @@ -441,7 +440,7 @@ func TestBuild(t *testing.T) {
ccType, path, codePackageStream := fakePlatformBuilder.GenerateDockerBuildArgsForCall(0)
require.Equal(t, "TYPE", ccType)
require.Equal(t, "path", path)
codePackage, err := ioutil.ReadAll(codePackageStream)
codePackage, err := io.ReadAll(codePackageStream)
require.NoError(t, err)
require.Equal(t, []byte("code-package"), codePackage)
})
Expand Down
10 changes: 5 additions & 5 deletions core/operations/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var _ = Describe("System", func() {
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
Expect(resp.Header.Get("Content-Type")).To(Equal("text/plain; charset=utf-8"))
buff, err := ioutil.ReadAll(resp.Body)
buff, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(buff)).To(Equal("secure"))
resp.Body.Close()
Expand Down Expand Up @@ -181,7 +181,7 @@ var _ = Describe("System", func() {
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
Expect(resp.Header.Get("Content-Type")).To(Equal("text/plain; charset=utf-8"))
buff, err := ioutil.ReadAll(resp.Body)
buff, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(buff)).To(Equal("insecure"))
resp.Body.Close()
Expand Down Expand Up @@ -275,7 +275,7 @@ var _ = Describe("System", func() {
resp, err := client.Get(fmt.Sprintf("https://%s/healthz", system.Addr()))
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusServiceUnavailable))
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
resp.Body.Close()

Expand Down Expand Up @@ -324,7 +324,7 @@ var _ = Describe("System", func() {
resp, err := client.Get(metricsURL)
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
resp.Body.Close()
Expect(err).NotTo(HaveOccurred())
Expect(body).To(ContainSubstring("# TYPE go_gc_duration_seconds summary"))
Expand All @@ -342,7 +342,7 @@ var _ = Describe("System", func() {
resp, err := client.Get(metricsURL)
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
resp.Body.Close()
Expect(err).NotTo(HaveOccurred())
Expect(string(body)).To(ContainSubstring("# TYPE fabric_version gauge"))
Expand Down
6 changes: 3 additions & 3 deletions integration/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ func CheckLogspecOperations(client *http.Client, logspecURL string) {
resp, err := client.Get(logspecURL)
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
resp.Body.Close()
Expect(err).NotTo(HaveOccurred())
Expect(string(bodyBytes)).To(MatchJSON(`{"spec":"info"}`))
Expand All @@ -927,7 +927,7 @@ func CheckLogspecOperations(client *http.Client, logspecURL string) {
resp, err = client.Get(logspecURL)
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
bodyBytes, err = ioutil.ReadAll(resp.Body)
bodyBytes, err = io.ReadAll(resp.Body)
resp.Body.Close()
Expect(err).NotTo(HaveOccurred())
Expect(string(bodyBytes)).To(MatchJSON(`{"spec":"debug"}`))
Expand Down Expand Up @@ -955,7 +955,7 @@ func getBody(client *http.Client, url string) func() string {
resp, err := client.Get(url)
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
resp.Body.Close()
return string(bodyBytes)
Expand Down
3 changes: 2 additions & 1 deletion integration/e2e/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package e2e
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
Expand Down Expand Up @@ -133,7 +134,7 @@ func doHealthCheck(client *http.Client, url string) (int, *healthz.HealthStatus)
resp, err := client.Get(url)
Expect(err).NotTo(HaveOccurred())

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
resp.Body.Close()

Expand Down
4 changes: 2 additions & 2 deletions integration/nwo/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package nwo

import (
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/hyperledger/fabric/integration/nwo/runner"
Expand Down Expand Up @@ -58,7 +58,7 @@ func (c *Components) Build(path string) string {
resp, err := http.Get(fmt.Sprintf("http://%s/%s", c.ServerAddress, path))
Expect(err).NotTo(HaveOccurred())

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())

if resp.StatusCode != http.StatusOK {
Expand Down
3 changes: 2 additions & 1 deletion integration/raft/channel_participation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"io"
"io/ioutil"
"math"
"net/http"
Expand Down Expand Up @@ -1002,7 +1003,7 @@ func doBodyFailure(client *http.Client, req *http.Request, expectedStatus int, e
resp, err := client.Do(req)
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(expectedStatus))
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
resp.Body.Close()

Expand Down
Loading

0 comments on commit 59ccd8d

Please sign in to comment.