Skip to content

Commit

Permalink
chore(cmd,util): replace use of io/ioutil (#1530)
Browse files Browse the repository at this point in the history
  • Loading branch information
julieqiu authored Aug 14, 2024
1 parent f888517 commit 87cb4e8
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cmd/gapic-showcase/compliance_suite_errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -291,7 +291,7 @@ func checkExpectedFailure(t *testing.T, verb, url, requestBody, failure, errorPr
return
}

body, err := ioutil.ReadAll(httpResponse.Body)
body, err := io.ReadAll(httpResponse.Body)
httpResponse.Body.Close()
if err != nil {
t.Fatalf("%s could not read response body: %s", errorPrefix, err)
Expand Down
7 changes: 4 additions & 3 deletions cmd/gapic-showcase/compliance_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -108,7 +109,7 @@ func TestComplianceSuite(t *testing.T) {

// Unmarshal httpResponse body, interpreted as JSON.
// should do this.
responseBody, err := ioutil.ReadAll(httpResponse.Body)
responseBody, err := io.ReadAll(httpResponse.Body)
httpResponse.Body.Close()
if err != nil {
t.Errorf("%s could not read httpResponse body: %s", errorPrefix, err)
Expand Down Expand Up @@ -427,7 +428,7 @@ func loadComplianceSuiteFile() (err error) {
// Locate, load
_, thisFile, _, _ := runtime.Caller(0)
complianceSuiteFileName = filepath.Join(filepath.Dir(thisFile), "../../schema/google/showcase/v1beta1/compliance_suite.json")
complianceSuiteJSON, err = ioutil.ReadFile(complianceSuiteFileName)
complianceSuiteJSON, err = os.ReadFile(complianceSuiteFileName)
if err != nil {
return fmt.Errorf("could not open suite file %q", complianceSuiteFileName)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gapic-showcase/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"strings"
"sync"

Expand Down Expand Up @@ -228,7 +228,7 @@ func newEndpointGRPC(lis net.Listener, config RuntimeConfig, backend *services.B
log.Fatalf("Failed to load server TLS cert/key with error:%v", err)
}

cert, err := ioutil.ReadFile(config.tlsCaCert)
cert, err := os.ReadFile(config.tlsCaCert)
if err != nil {
log.Fatalf("Failed to load root CA cert file with error:%v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gapic-showcase/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package main

import (
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestRESTCalls(t *testing.T) {
continue
}

body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
response.Body.Close()
if err != nil {
jsonOptions.Restore()
Expand Down
3 changes: 1 addition & 2 deletions util/compile_protos.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package util

import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
Expand All @@ -39,7 +38,7 @@ func CompileProtos(version string) {
log.Fatalf("Error: unable to get working dir: %+v", err)
}

outDir, err := ioutil.TempDir(os.TempDir(), "gapic-showcase")
outDir, err := os.MkdirTemp(os.TempDir(), "gapic-showcase")
if err != nil {
log.Fatalf("Error: unable to create a temporary dir: %+v\n", err)
}
Expand Down
4 changes: 2 additions & 2 deletions util/genrest/goviewcreator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package genrest

import (
"io/ioutil"
"os"
"reflect"
"testing"

Expand Down Expand Up @@ -144,7 +144,7 @@ func TestConstructStreamingServer(t *testing.T) {
actualSources += helperSources[key].Contents() + "\n"
}

expectedSources, err := ioutil.ReadFile("testdata/TestConstructServerStreamer.go.baseline")
expectedSources, err := os.ReadFile("testdata/TestConstructServerStreamer.go.baseline")
if err != nil {
t.Fatalf("could not load file: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions util/genrest/protomodelcreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package genrest

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

"cloud.google.com/go/iam/apiv1/iampb"
Expand Down Expand Up @@ -182,7 +181,7 @@ func GetServiceConfig() (*serviceconfig.Service, error) {
// hard-coding this location isn't terrible.
serviceConfigPath := "schema/google/showcase/v1beta1/showcase_v1beta1.yaml"

y, err := ioutil.ReadFile(serviceConfigPath)
y, err := os.ReadFile(serviceConfigPath)
if err != nil {
cwd, _ := os.Getwd()
return nil, fmt.Errorf("error reading service config %q (cwd==%q): %v", serviceConfigPath, cwd, err)
Expand Down
3 changes: 1 addition & 2 deletions util/genrest/resttools/checkrequestformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"
"strings"
Expand All @@ -45,7 +44,7 @@ func CheckRequestFormat(jsonReader io.Reader, request *http.Request, message pro
return err
}

jsonBytes, err := ioutil.ReadAll(jsonReader)
jsonBytes, err := io.ReadAll(jsonReader)
if err != nil {
return err
}
Expand Down

0 comments on commit 87cb4e8

Please sign in to comment.