Skip to content

Commit

Permalink
Go 1.19 released, so update supported Go versions. (#721)
Browse files Browse the repository at this point in the history
* Go 1.19 released, so update supported Go versions.

* Remove the usage of the deprecated ioutil package.
  • Loading branch information
aalexand committed Aug 18, 2022
1 parent c133b57 commit 1763105
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 56 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.18', 'tip']
go: ['1.18', '1.19', 'tip']
# Supported macOS versions can be found in
# https://github.com/actions/virtual-environments#available-environments.
os: ['macos-10.15', 'macos-11']
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.18', 'tip']
go: ['1.18', '1.19', 'tip']
os: ['ubuntu-20.04', 'ubuntu-18.04']
steps:
- name: Update Go version using setup-go
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.18']
go: ['1.18', '1.19']
steps:
- name: Update Go version using setup-go
uses: actions/setup-go@v2
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_test.go
Expand Up @@ -15,7 +15,7 @@
package pprof

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

Expand All @@ -28,13 +28,13 @@ func TestParseData(t *testing.T) {
}

const path = "testdata/"
files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
t.Errorf("Problem reading directory %s : %v", path, err)
}
for _, f := range files {
file := path + f.Name()
inbytes, err := ioutil.ReadFile(file)
inbytes, err := os.ReadFile(file)
if err != nil {
t.Errorf("Problem reading file: %s : %v", file, err)
continue
Expand Down
2 changes: 1 addition & 1 deletion go.mod
@@ -1,6 +1,6 @@
module github.com/google/pprof

go 1.17
go 1.18

require (
github.com/chzyer/readline v1.5.0
Expand Down
11 changes: 5 additions & 6 deletions internal/driver/driver_test.go
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"net"
_ "net/http/pprof"
"os"
Expand Down Expand Up @@ -117,7 +116,7 @@ func TestParse(t *testing.T) {
flags := strings.Split(tc.flags, ",")

// Encode profile into a protobuf and decode it again.
protoTempFile, err := ioutil.TempFile("", "profile_proto")
protoTempFile, err := os.CreateTemp("", "profile_proto")
if err != nil {
t.Errorf("cannot create tempfile: %v", err)
}
Expand Down Expand Up @@ -145,7 +144,7 @@ func TestParse(t *testing.T) {
setCurrentConfig(baseConfig)

// Read the profile from the encoded protobuf
outputTempFile, err := ioutil.TempFile("", "profile_output")
outputTempFile, err := os.CreateTemp("", "profile_output")
if err != nil {
t.Errorf("cannot create tempfile: %v", err)
}
Expand Down Expand Up @@ -180,14 +179,14 @@ func TestParse(t *testing.T) {
if err := PProf(o2); err != nil {
t.Errorf("%s: %v", tc.source, err)
}
b, err := ioutil.ReadFile(outputTempFile.Name())
b, err := os.ReadFile(outputTempFile.Name())
if err != nil {
t.Errorf("Failed to read profile %s: %v", outputTempFile.Name(), err)
}

// Read data file with expected solution
solution = "testdata/" + solution
sbuf, err := ioutil.ReadFile(solution)
sbuf, err := os.ReadFile(solution)
if err != nil {
t.Fatalf("reading solution file %s: %v", solution, err)
}
Expand Down Expand Up @@ -215,7 +214,7 @@ func TestParse(t *testing.T) {
}
t.Errorf("%s\n%s\n", solution, d)
if *updateFlag {
err := ioutil.WriteFile(solution, b, 0644)
err := os.WriteFile(solution, b, 0644)
if err != nil {
t.Errorf("failed to update the solution file %q: %v", solution, err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/driver/fetch.go
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -507,7 +506,7 @@ func fetchURL(source string, timeout time.Duration, tr http.RoundTripper) (io.Re
func statusCodeError(resp *http.Response) error {
if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
// error is from pprof endpoint
if body, err := ioutil.ReadAll(resp.Body); err == nil {
if body, err := io.ReadAll(resp.Body); err == nil {
return fmt.Errorf("server response: %s - %s", resp.Status, body)
}
}
Expand Down
15 changes: 7 additions & 8 deletions internal/driver/fetch_test.go
Expand Up @@ -22,7 +22,6 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"math/big"
"net"
"net/http"
Expand Down Expand Up @@ -52,7 +51,7 @@ func TestSymbolizationPath(t *testing.T) {
saveHome := os.Getenv(homeEnv())
savePath := os.Getenv("PPROF_BINARY_PATH")

tempdir, err := ioutil.TempDir("", "home")
tempdir, err := os.MkdirTemp("", "home")
if err != nil {
t.Fatal("creating temp dir: ", err)
}
Expand Down Expand Up @@ -530,7 +529,7 @@ func TestHTTPSInsecure(t *testing.T) {
t.Skip("test assumes tcp available")
}
saveHome := os.Getenv(homeEnv())
tempdir, err := ioutil.TempDir("", "home")
tempdir, err := os.MkdirTemp("", "home")
if err != nil {
t.Fatal("creating temp dir: ", err)
}
Expand Down Expand Up @@ -564,7 +563,7 @@ func TestHTTPSInsecure(t *testing.T) {
}()
defer l.Close()

outputTempFile, err := ioutil.TempFile("", "profile_output")
outputTempFile, err := os.CreateTemp("", "profile_output")
if err != nil {
t.Fatalf("Failed to create tempfile: %v", err)
}
Expand Down Expand Up @@ -603,7 +602,7 @@ func TestHTTPSWithServerCertFetch(t *testing.T) {
t.Skip("test assumes tcp available")
}
saveHome := os.Getenv(homeEnv())
tempdir, err := ioutil.TempDir("", "home")
tempdir, err := os.MkdirTemp("", "home")
if err != nil {
t.Fatal("creating temp dir: ", err)
}
Expand Down Expand Up @@ -645,7 +644,7 @@ func TestHTTPSWithServerCertFetch(t *testing.T) {
}()
defer l.Close()

outputTempFile, err := ioutil.TempFile("", "profile_output")
outputTempFile, err := os.CreateTemp("", "profile_output")
if err != nil {
t.Fatalf("Failed to create tempfile: %v", err)
}
Expand All @@ -665,15 +664,15 @@ func TestHTTPSWithServerCertFetch(t *testing.T) {
Symbolize: "remote",
}

certTempFile, err := ioutil.TempFile("", "cert_output")
certTempFile, err := os.CreateTemp("", "cert_output")
if err != nil {
t.Errorf("cannot create cert tempfile: %v", err)
}
defer os.Remove(certTempFile.Name())
defer certTempFile.Close()
certTempFile.Write(certBytes)

keyTempFile, err := ioutil.TempFile("", "key_output")
keyTempFile, err := os.CreateTemp("", "key_output")
if err != nil {
t.Errorf("cannot create key tempfile: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/driver/settings.go
Expand Up @@ -3,7 +3,6 @@ package driver
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -33,7 +32,7 @@ func settingsFileName() (string, error) {

// readSettings reads settings from fname.
func readSettings(fname string) (*settings, error) {
data, err := ioutil.ReadFile(fname)
data, err := os.ReadFile(fname)
if err != nil {
if os.IsNotExist(err) {
return &settings{}, nil
Expand Down Expand Up @@ -64,7 +63,7 @@ func writeSettings(fname string, settings *settings) error {
return fmt.Errorf("failed to create settings directory: %w", err)
}

if err := ioutil.WriteFile(fname, data, 0644); err != nil {
if err := os.WriteFile(fname, data, 0644); err != nil {
return fmt.Errorf("failed to write settings: %w", err)
}
return nil
Expand Down
3 changes: 1 addition & 2 deletions internal/driver/settings_test.go
@@ -1,7 +1,6 @@
package driver

import (
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand All @@ -13,7 +12,7 @@ import (
// and the name of the settings file. The caller must delete the directory when
// done.
func settingsDirAndFile(t *testing.T) (string, string) {
tmpDir, err := ioutil.TempDir("", "pprof_settings_test")
tmpDir, err := os.MkdirTemp("", "pprof_settings_test")
if err != nil {
t.Fatalf("error creating temporary directory: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/driver/webui_test.go
Expand Up @@ -16,7 +16,7 @@ package driver

import (
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestWebInterface(t *testing.T) {
t.Error("could not fetch", c.path, err)
continue
}
data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
t.Error("could not read response", c.path, err)
continue
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestWebInterface(t *testing.T) {
t.Error("could not fetch", c.path, err)
return
}
if _, err = ioutil.ReadAll(res.Body); err != nil {
if _, err = io.ReadAll(res.Body); err != nil {
t.Error("could not read response", c.path, err)
}
}()
Expand Down
6 changes: 3 additions & 3 deletions internal/graph/dotgraph_test.go
Expand Up @@ -18,7 +18,7 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strconv"
Expand Down Expand Up @@ -214,7 +214,7 @@ func baseAttrsAndConfig() (*DotAttributes, *DotConfig) {

func compareGraphs(t *testing.T, got []byte, wantFile string) {
wantFile = filepath.Join("testdata", wantFile)
want, err := ioutil.ReadFile(wantFile)
want, err := os.ReadFile(wantFile)
if err != nil {
t.Fatalf("error reading test file %s: %v", wantFile, err)
}
Expand All @@ -226,7 +226,7 @@ func compareGraphs(t *testing.T, got []byte, wantFile string) {
}
t.Errorf("Compose incorrectly wrote %s", string(d))
if *updateFlag {
err := ioutil.WriteFile(wantFile, got, 0644)
err := os.WriteFile(wantFile, got, 0644)
if err != nil {
t.Errorf("failed to update the golden file %q: %v", wantFile, err)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/proftest/proftest.go
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"regexp"
Expand All @@ -31,14 +30,14 @@ import (
// differences. It is meant for testing purposes to display the
// differences between expected and actual output.
func Diff(b1, b2 []byte) (data []byte, err error) {
f1, err := ioutil.TempFile("", "proto_test")
f1, err := os.CreateTemp("", "proto_test")
if err != nil {
return nil, err
}
defer os.Remove(f1.Name())
defer f1.Close()

f2, err := ioutil.TempFile("", "proto_test")
f2, err := os.CreateTemp("", "proto_test")
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/report/report_test.go
Expand Up @@ -16,7 +16,7 @@ package report

import (
"bytes"
"io/ioutil"
"os"
"regexp"
"runtime"
"strings"
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestSource(t *testing.T) {
t.Fatalf("%s: %v", tc.want, err)
}

gold, err := ioutil.ReadFile(tc.want)
gold, err := os.ReadFile(tc.want)
if err != nil {
t.Fatalf("%s: %v", tc.want, err)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/report/source_test.go
Expand Up @@ -17,7 +17,6 @@ package report
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -123,7 +122,7 @@ func testSourceMapping(t *testing.T, zeroAddress bool) {
}

func TestOpenSourceFile(t *testing.T) {
tempdir, err := ioutil.TempDir("", "")
tempdir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
Expand Down Expand Up @@ -195,7 +194,7 @@ func TestOpenSourceFile(t *testing.T) {
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatalf("failed to create dir %q: %v", dir, err)
}
if err := ioutil.WriteFile(path, nil, 0644); err != nil {
if err := os.WriteFile(path, nil, 0644); err != nil {
t.Fatalf("failed to create file %q: %v", path, err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/symbolizer/symbolizer.go
Expand Up @@ -19,7 +19,7 @@ package symbolizer

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"path/filepath"
Expand Down Expand Up @@ -110,13 +110,13 @@ func postURL(source, post string, tr http.RoundTripper) ([]byte, error) {
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("http post %s: %v", source, statusCodeError(resp))
}
return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

func statusCodeError(resp *http.Response) error {
if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
// error is from pprof endpoint
if body, err := ioutil.ReadAll(resp.Body); err == nil {
if body, err := io.ReadAll(resp.Body); err == nil {
return fmt.Errorf("server response: %s - %s", resp.Status, body)
}
}
Expand Down

0 comments on commit 1763105

Please sign in to comment.