fix lint warnings (#2589)

* resolve deprecation warnings

* drop use of ioutil

* fix license

* run hack/update-codegen.sh
This commit is contained in:
Dave Protasowski 2022-09-12 14:15:45 -04:00 committed by GitHub
parent cc6e435120
commit 3d24b8416b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 65 additions and 166 deletions

View File

@ -20,7 +20,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
@ -39,7 +38,7 @@ func main() {
// processFile reads the ConfigMap manifest from a file and adds or updates the label
// containing the checksum of it's _example data if present.
func processFile(fileName string) error {
in, err := ioutil.ReadFile(fileName)
in, err := os.ReadFile(fileName)
if err != nil {
return fmt.Errorf("failed to read file: %w", err)
}
@ -50,7 +49,7 @@ func processFile(fileName string) error {
}
//nolint:gosec // This is not security critical so open permissions are fine.
if err := ioutil.WriteFile(fileName, out, 0644); err != nil {
if err := os.WriteFile(fileName, out, 0644); err != nil {
return fmt.Errorf("failed to write file: %w", err)
}
return nil

View File

@ -17,7 +17,6 @@ limitations under the License.
package main
import (
"io/ioutil"
"os"
"path"
"testing"
@ -28,7 +27,7 @@ import (
func TestProcess(t *testing.T) {
for _, test := range []string{"add", "update", "nothing"} {
t.Run(test, func(t *testing.T) {
in, err := ioutil.ReadFile(path.Join("testdata", test+".yaml"))
in, err := os.ReadFile(path.Join("testdata", test+".yaml"))
if err != nil {
t.Fatal("Failed to load test fixture:", err)
}
@ -38,7 +37,7 @@ func TestProcess(t *testing.T) {
t.Fatal("Expected no error but got", err)
}
want, err := ioutil.ReadFile(path.Join("testdata", test+"_want.yaml"))
want, err := os.ReadFile(path.Join("testdata", test+"_want.yaml"))
if err != nil && !os.IsNotExist(err) {
t.Fatal("Failed to load test fixture:", err)
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package configmap
import (
"io/ioutil"
"os"
"path"
"path/filepath"
@ -47,7 +46,7 @@ func Load(p string) (map[string]string, error) {
if info.IsDir() {
return nil
}
b, err := ioutil.ReadFile(p)
b, err := os.ReadFile(p)
if err != nil {
return err
}

View File

@ -18,7 +18,6 @@ package configmap
import (
"fmt"
"io/ioutil"
"os"
"path"
"testing"
@ -33,7 +32,7 @@ func TestLoad(t *testing.T) {
"a.b.c": "blah",
".z.y.x": "hidden!",
}
tmpdir, err := ioutil.TempDir("", "")
tmpdir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal("TempDir() =", err)
}
@ -60,7 +59,7 @@ func TestLoad(t *testing.T) {
// Write out the files as they should be loaded.
for k, v := range want {
// Write the actual file to $/.{timestamp}/key
if err := ioutil.WriteFile(path.Join(tsDir, k), []byte(v), 0644); err != nil {
if err := os.WriteFile(path.Join(tsDir, k), []byte(v), 0644); err != nil {
t.Fatalf("WriteFile(..{ts}/%s) = %v", k, err)
}
// Symlink $/key => $/..data/key
@ -91,7 +90,7 @@ func TestLoadError(t *testing.T) {
// "a.b.c": "blah",
// ".z.y.x": "hidden!",
// }
// tmpdir, err := ioutil.TempDir("", "")
// tmpdir, err := os.MkdirTemp("", "")
// if err != nil {
// t.Fatal("TempDir() =", err)
// }
@ -99,7 +98,7 @@ func TestLoadError(t *testing.T) {
// // Write out the files as write-only, so we fail reading.
// for k, v := range written {
// err := ioutil.WriteFile(path.Join(tmpdir, k), []byte(v), 0200)
// err := os.WriteFile(path.Join(tmpdir, k), []byte(v), 0200)
// if err != nil {
// t.Fatalf("WriteFile(%q) = %v", k, err)
// }
@ -111,7 +110,7 @@ func TestLoadError(t *testing.T) {
// }
func TestReadSymlinkedFileError(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "")
tmpdir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal("TempDir() =", err)
}

View File

@ -18,7 +18,7 @@ package testing
import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
"unicode"
@ -45,7 +45,7 @@ func ConfigMapFromTestFile(t testing.TB, name string, allowed ...string) *corev1
func ConfigMapsFromTestFile(t testing.TB, name string, allowed ...string) (*corev1.ConfigMap, *corev1.ConfigMap) {
t.Helper()
b, err := ioutil.ReadFile(fmt.Sprintf("testdata/%s.yaml", name))
b, err := os.ReadFile(fmt.Sprintf("testdata/%s.yaml", name))
if err != nil {
t.Fatal("ReadFile() =", err)
}

2
go.mod
View File

@ -49,6 +49,7 @@ require (
k8s.io/code-generator v0.24.4
k8s.io/gengo v0.0.0-20220613173612-397b4ae3bce7
k8s.io/klog/v2 v2.70.2-0.20220707122935-0990e81f1a8f
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
knative.dev/hack v0.0.0-20220908170219-36b2b3c7a245
sigs.k8s.io/yaml v1.3.0
)
@ -103,7 +104,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)

View File

@ -18,7 +18,7 @@ package metrics
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"net/url"
"testing"
@ -96,7 +96,7 @@ func TestClientMetrics(t *testing.T) {
stub := ClientFunc(func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBufferString("hi")),
Body: io.NopCloser(bytes.NewBufferString("hi")),
}, nil
})

View File

@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"sort"
@ -166,7 +165,7 @@ func TestMetricsExport(t *testing.T) {
t.Fatalf("failed to fetch prometheus metrics: %+v", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("failed to read prometheus response: %+v", err)
}

View File

@ -15,8 +15,8 @@ package metrics
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
"testing"
@ -31,11 +31,11 @@ import (
)
func TestOpenCensusConfig(t *testing.T) {
cert, err := ioutil.ReadFile(filepath.Join("testdata", "client-cert.pem"))
cert, err := os.ReadFile(filepath.Join("testdata", "client-cert.pem"))
if err != nil {
t.Fatal("Couldn't find testdata/client-cert.pem:", err)
}
key, err := ioutil.ReadFile(filepath.Join("testdata", "client-key.pem"))
key, err := os.ReadFile(filepath.Join("testdata", "client-key.pem"))
if err != nil {
t.Fatal("Couldn't find testdata/client-key.pem:", err)
}

View File

@ -29,7 +29,7 @@ import (
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/utils/clock"
)
type storedViews struct {
@ -53,7 +53,7 @@ type meters struct {
meters map[string]*meterExporter
factory ResourceExporterFactory
lock sync.Mutex
clock clock.Clock
clock clock.WithTicker
ticker clock.Ticker
tickerStopChan chan struct{}
}
@ -65,7 +65,7 @@ var (
resourceViews = storedViews{}
allMeters = meters{
meters: map[string]*meterExporter{"": &defaultMeter},
clock: clock.Clock(clock.RealClock{}),
clock: clock.RealClock{},
}
cleanupOnce = new(sync.Once)

View File

@ -24,8 +24,8 @@ import (
"go.opencensus.io/resource"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/wait"
testingclock "k8s.io/utils/clock/testing"
)
var (
@ -129,8 +129,8 @@ func TestSetFactory(t *testing.T) {
}
func TestAllMetersExpiration(t *testing.T) {
allMeters.clock = clock.Clock(clock.NewFakeClock(time.Now()))
fakeClock := allMeters.clock.(*clock.FakeClock)
fakeClock := testingclock.NewFakeClock(time.Now())
allMeters.clock = fakeClock
ClearMetersForTest() // t+0m
// Add resource123
@ -199,8 +199,8 @@ func TestAllMetersExpiration(t *testing.T) {
}
func TestIfAllMeterResourcesAreRemoved(t *testing.T) {
allMeters.clock = clock.Clock(clock.NewFakeClock(time.Now()))
fakeClock := allMeters.clock.(*clock.FakeClock)
fakeClock := testingclock.NewFakeClock(time.Now())
allMeters.clock = fakeClock
ClearMetersForTest() // t+0m
// Register many resources at once
for i := 1; i <= 100; i++ {

View File

@ -17,8 +17,8 @@ limitations under the License.
package network
import (
"io/ioutil"
"net/http"
"os"
"go.uber.org/zap"
)
@ -36,7 +36,7 @@ func ErrorHandler(logger *zap.SugaredLogger) func(http.ResponseWriter, *http.Req
}
func readSockStat(logger *zap.SugaredLogger) string {
b, err := ioutil.ReadFile("/proc/net/sockstat")
b, err := os.ReadFile("/proc/net/sockstat")
if err != nil {
logger.Errorw("Unable to read sockstat", zap.Error(err))
return ""

View File

@ -20,7 +20,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
@ -43,8 +42,7 @@ func TestCleanupOnInterrupt(t *testing.T) {
return
}
// TODO: Move to os.CreateTemp when we adopt 1.16 more widely
readyFile, err := ioutil.TempFile("", "")
readyFile, err := os.CreateTemp("", "")
if err != nil {
t.Fatalf("failed to setup tests")
}

View File

@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"strings"
@ -223,7 +222,7 @@ func (g *GCSClient) ReadObject(ctx context.Context, bucketName, objPath string)
return contents, err
}
defer f.Close()
return ioutil.ReadAll(f)
return io.ReadAll(f)
}
// NewReader creates a new Reader of a gcs file.

View File

@ -18,7 +18,6 @@ package mock
import (
"context"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -434,7 +433,7 @@ func (c *clientMocker) Upload(ctx context.Context, bkt, objPath, filePath string
return NewNoObjectError(bkt, objName, dir)
}
content, err := ioutil.ReadFile(filePath)
content, err := os.ReadFile(filePath)
if err != nil {
return err
}

View File

@ -21,7 +21,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"reflect"
@ -971,7 +970,7 @@ func TestDownload(t *testing.T) {
return
}
fileContent, err := ioutil.ReadFile(file)
fileContent, err := os.ReadFile(file)
if err != nil {
t.Fatalf("cannot read content %v, error %v", file, err)
}
@ -989,7 +988,7 @@ func TestUpload(t *testing.T) {
project1 := "test-project1"
object1 := "dir/object1"
file := "test/upload"
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
t.Fatalf("cannot read content %v, error %v", file, err)
}

View File

@ -22,8 +22,8 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"time"
@ -73,7 +73,7 @@ type GithubClient struct {
// NewGithubClient explicitly authenticates to github with giving token and returns a handle
func NewGithubClient(tokenFilePath string) (*GithubClient, error) {
b, err := ioutil.ReadFile(tokenFilePath)
b, err := os.ReadFile(tokenFilePath)
if err != nil {
return nil, err
}

View File

@ -19,7 +19,6 @@ package interactive
import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
@ -82,7 +81,7 @@ func (d *Docker) AddMount(typeStr, source, target string, optAdditionalArgs ...s
// Returns a function to clean up the mount (but does not delete the directory).
// Uses sudo and probably only works on Linux
func (d *Docker) AddRWOverlay(externalDirectory, internalDirectory string) func() {
tmpDir, err := ioutil.TempDir("", "overlay")
tmpDir, err := os.MkdirTemp("", "overlay")
if err != nil {
log.Fatal(err)
}

View File

@ -20,7 +20,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -385,7 +385,7 @@ func (f *fakePods) GetLogs(podName string, opts *corev1.PodLogOptions) *restclie
Client: fakerest.CreateHTTPClient(func(request *http.Request) (*http.Response, error) {
resp := &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(
Body: io.NopCloser(
strings.NewReader(logsForContainer(opts.Container))),
}
return resp, nil

View File

@ -18,7 +18,6 @@ package config
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -49,7 +48,7 @@ func getBenchmark() (*mpb.BenchmarkInfo, error) {
// Read the Mako config file for this environment.
data, koerr := readFileFromKoData(env + ".config")
if koerr != nil {
data, err = ioutil.ReadFile(filepath.Join(configMako, env+".config"))
data, err = os.ReadFile(filepath.Join(configMako, env+".config"))
if err != nil {
//nolint: errorlint // It's fine not to wrap here.
return nil, fmt.Errorf("cannot load both from kodata and from config mako config map: %s, %s", koerr.Error(), err.Error())
@ -72,5 +71,5 @@ func readFileFromKoData(name string) ([]byte, error) {
return nil, fmt.Errorf("%q does not exist or is empty", koDataPathEnvName)
}
fullFilename := filepath.Join(koDataPath, name)
return ioutil.ReadFile(fullFilename)
return os.ReadFile(fullFilename)
}

View File

@ -20,7 +20,7 @@ package slackutil
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
)
@ -49,5 +49,5 @@ func handleResponse(resp *http.Response) ([]byte, error) {
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("http response code is not StatusOK: '%v'", resp.StatusCode)
}
return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

View File

@ -22,8 +22,8 @@ import (
"encoding/json"
"fmt"
"html"
"io/ioutil"
"net/url"
"os"
"strconv"
"strings"
"time"
@ -44,7 +44,7 @@ type readClient struct {
// NewReadClient reads token file and stores it for later authentication
func NewReadClient(userName, tokenPath string) (ReadOperations, error) {
b, err := ioutil.ReadFile(tokenPath)
b, err := os.ReadFile(tokenPath)
if err != nil {
return nil, err
}

View File

@ -21,7 +21,7 @@ package slackutil
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
"net/url"
@ -42,7 +42,7 @@ type writeClient struct {
// NewWriteClient reads token file and stores it for later authentication
func NewWriteClient(userName, tokenPath string) (WriteOperations, error) {
b, err := ioutil.ReadFile(tokenPath)
b, err := os.ReadFile(tokenPath)
if err != nil {
return nil, err
}

View File

@ -23,7 +23,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
@ -188,7 +187,7 @@ func (sc *SpoofingClient) Poll(req *http.Request, inState ResponseChecker, check
}
defer rawResp.Body.Close()
body, err := ioutil.ReadAll(rawResp.Body)
body, err := io.ReadAll(rawResp.Body)
if err != nil {
return true, err
}

View File

@ -18,7 +18,7 @@ package upgrade_test
import (
"fmt"
"io/ioutil"
"io"
"os"
"testing"
@ -89,6 +89,6 @@ func captureStdOutput(call func()) string {
call()
_ = w.Close()
out, _ := ioutil.ReadAll(r)
out, _ := io.ReadAll(r)
return string(out)
}

View File

@ -22,7 +22,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
@ -226,7 +226,7 @@ func jsonTrace(traceID string) ([]model.SpanModel, error) {
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return empty, err
}

View File

@ -1,86 +0,0 @@
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package clock
import (
"time"
clocks "k8s.io/utils/clock"
testclocks "k8s.io/utils/clock/testing"
)
// PassiveClock allows for injecting fake or real clocks into code
// that needs to read the current time but does not support scheduling
// activity in the future.
//
// Deprecated: Use k8s.io/utils/clock.PassiveClock instead.
type PassiveClock = clocks.PassiveClock
// Clock allows for injecting fake or real clocks into code that
// needs to do arbitrary things based on time.
//
// Deprecated: Use k8s.io/utils/clock.WithTickerAndDelayedExecution instead.
type Clock = clocks.WithTickerAndDelayedExecution
// Deprecated: Use k8s.io/utils/clock.RealClock instead.
type RealClock = clocks.RealClock
// FakePassiveClock implements PassiveClock, but returns an arbitrary time.
//
// Deprecated: Use k8s.io/utils/clock/testing.FakePassiveClock instead.
type FakePassiveClock = testclocks.FakePassiveClock
// FakeClock implements Clock, but returns an arbitrary time.
//
// Deprecated: Use k8s.io/utils/clock/testing.FakeClock instead.
type FakeClock = testclocks.FakeClock
// NewFakePassiveClock returns a new FakePassiveClock.
//
// Deprecated: Use k8s.io/utils/clock/testing.NewFakePassiveClock instead.
func NewFakePassiveClock(t time.Time) *testclocks.FakePassiveClock {
return testclocks.NewFakePassiveClock(t)
}
// NewFakeClock returns a new FakeClock.
//
// Deprecated: Use k8s.io/utils/clock/testing.NewFakeClock instead.
func NewFakeClock(t time.Time) *testclocks.FakeClock {
return testclocks.NewFakeClock(t)
}
// IntervalClock implements Clock, but each invocation of Now steps
// the clock forward the specified duration.
//
// WARNING: most of the Clock methods just `panic`;
// only PassiveClock is honestly implemented.
// The alternative, SimpleIntervalClock, has only the
// PassiveClock methods.
//
// Deprecated: Use k8s.io/utils/clock/testing.SimpleIntervalClock instead.
type IntervalClock = testclocks.IntervalClock
// Timer allows for injecting fake or real timers into code that
// needs to do arbitrary things based on time.
//
// Deprecated: Use k8s.io/utils/clock.Timer instead.
type Timer = clocks.Timer
// Ticker defines the Ticker interface.
//
// Deprecated: Use k8s.io/utils/clock.Ticker instead.
type Ticker = clocks.Ticker

1
vendor/modules.txt vendored
View File

@ -719,7 +719,6 @@ k8s.io/apimachinery/pkg/runtime/serializer/versioning
k8s.io/apimachinery/pkg/selection
k8s.io/apimachinery/pkg/types
k8s.io/apimachinery/pkg/util/cache
k8s.io/apimachinery/pkg/util/clock
k8s.io/apimachinery/pkg/util/diff
k8s.io/apimachinery/pkg/util/errors
k8s.io/apimachinery/pkg/util/framer

View File

@ -19,7 +19,7 @@ import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/url"
"path"
@ -180,7 +180,7 @@ func TestAdmissionValidResponseForResourceTLS(t *testing.T) {
}
defer response.Body.Close()
responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
if err != nil {
t.Error("Failed to read response body", err)
return
@ -305,7 +305,7 @@ func TestAdmissionValidResponseForResource(t *testing.T) {
}
defer response.Body.Close()
responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
if err != nil {
t.Error("Failed to read response body", err)
return
@ -434,7 +434,7 @@ func TestAdmissionInvalidResponseForResource(t *testing.T) {
}
defer response.Body.Close()
respBody, err := ioutil.ReadAll(response.Body)
respBody, err := io.ReadAll(response.Body)
if err != nil {
t.Fatal("Failed to read response body", err)
}
@ -551,7 +551,7 @@ func TestAdmissionWarningResponseForResource(t *testing.T) {
}
defer response.Body.Close()
respBody, err := ioutil.ReadAll(response.Body)
respBody, err := io.ReadAll(response.Body)
if err != nil {
t.Fatal("Failed to read response body", err)
}
@ -656,7 +656,7 @@ func TestAdmissionValidResponseForRequestBody(t *testing.T) {
}
defer response.Body.Close()
responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
if err != nil {
t.Error("Failed to read response body", err)
return

View File

@ -21,7 +21,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"
@ -123,7 +123,7 @@ func TestConversionValidResponse(t *testing.T) {
t.Errorf("Response status code = %v, wanted %v", got, want)
}
responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
if err != nil {
t.Fatal("Failed to read response body", err)
}
@ -212,7 +212,7 @@ func TestConversionInvalidResponse(t *testing.T) {
t.Errorf("Response status code = %v, wanted %v", got, want)
}
responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
if err != nil {
t.Fatal("Failed to read response body", err)
}

View File

@ -19,7 +19,7 @@ package webhook
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
@ -91,7 +91,7 @@ func TestMissingContentType(t *testing.T) {
}
defer response.Body.Close()
responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
if err != nil {
t.Fatal("Failed to read response body", err)
}
@ -147,7 +147,7 @@ func testEmptyRequestBody(t *testing.T, controller interface{}) {
}
defer response.Body.Close()
responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
if err != nil {
t.Fatal("Failed to read response body", err)
}

View File

@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http/httputil"
"sync"
"time"
@ -302,7 +301,7 @@ func (c *ManagedConnection) read() error {
// and if that channel is set.
// TODO(markusthoemmes): Return the messageType along with the payload.
if c.messageChan != nil && (messageType == websocket.TextMessage || messageType == websocket.BinaryMessage) {
if message, _ := ioutil.ReadAll(reader); message != nil {
if message, _ := io.ReadAll(reader); message != nil {
c.messageChan <- message
}
}