chore: remove refs to deprecated io/ioutil (#778)

Co-authored-by: guoguangwu <guoguangwu@magic-shield.com>
patterns
David 2024-11-06 10:46:52 +01:00 committed by GitHub
parent 34566aa802
commit 11c1b68cfe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 19 additions and 29 deletions

View File

@ -2,7 +2,6 @@ package approvals
import (
"context"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -16,7 +15,7 @@ import (
)
func NewTestingUtils() (*sql.SQLStore, func()) {
dir, err := ioutil.TempDir("", "whstoretest")
dir, err := os.MkdirTemp("", "whstoretest")
if err != nil {
log.Fatal(err)
}

View File

@ -1,7 +1,6 @@
package hipchat
import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
@ -108,7 +107,7 @@ func init() {
}
func newTestingUtils() (*sql.SQLStore, func()) {
dir, err := ioutil.TempDir("", "whstoretest")
dir, err := os.MkdirTemp("", "whstoretest")
if err != nil {
log.Fatal(err)
}

View File

@ -2,7 +2,6 @@ package slack
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -88,7 +87,7 @@ func (i *fakeSlackImplementer) PostMessage(channelID string, options ...slack.Ms
}
func newTestingUtils() (*sql.SQLStore, func()) {
dir, err := ioutil.TempDir("", "whstoretest")
dir, err := os.MkdirTemp("", "whstoretest")
if err != nil {
log.Fatal(err)
}

View File

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
@ -54,7 +53,7 @@ func readCredentialsFromFile() (*types.Credentials, error) {
return nil, errors.New("GOOGLE_APPLICATION_CREDENTIALS environment variable not set")
}
credentials, err := ioutil.ReadFile(credentialsFile)
credentials, err := os.ReadFile(credentialsFile)
if err != nil {
return nil, fmt.Errorf("failed to read credentials file: %w", err)
}

View File

@ -1,7 +1,7 @@
package teams
import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
@ -24,7 +24,7 @@ func TestTrimLeftChar(t *testing.T) {
func TestTeamsRequest(t *testing.T) {
handler := func(resp http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
if err != nil {
t.Errorf("failed to parse body: %s", err)
}

View File

@ -1,7 +1,7 @@
package webhook
import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
@ -14,7 +14,7 @@ import (
func TestWebhookRequest(t *testing.T) {
currentTime := time.Now()
handler := func(resp http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
if err != nil {
t.Errorf("failed to parse body: %s", err)
}

View File

@ -2,7 +2,6 @@ package http
import (
"bytes"
"io/ioutil"
"log"
"net/http"
"os"
@ -22,7 +21,7 @@ import (
)
func NewTestingUtils() (*sql.SQLStore, func()) {
dir, err := ioutil.TempDir("", "whstoretest")
dir, err := os.MkdirTemp("", "whstoretest")
if err != nil {
log.Fatal(err)
}

View File

@ -1,7 +1,6 @@
package helm3
import (
"io/ioutil"
"log"
"os"
"path/filepath"
@ -21,7 +20,7 @@ import (
)
func newTestingUtils() (*sql.SQLStore, func()) {
dir, err := ioutil.TempDir("", "whstoretest")
dir, err := os.MkdirTemp("", "whstoretest")
if err != nil {
log.Fatal(err)
}

View File

@ -1,7 +1,6 @@
package kubernetes
import (
"io/ioutil"
"log"
"os"
"path/filepath"
@ -112,7 +111,7 @@ func (s *fakeSender) Send(event types.EventNotification) error {
}
func NewTestingUtils() (*sql.SQLStore, func()) {
dir, err := ioutil.TempDir("", "whstoretest")
dir, err := os.MkdirTemp("", "whstoretest")
if err != nil {
log.Fatal(err)
}

View File

@ -1,7 +1,7 @@
package docker
import (
"io/ioutil"
"io"
"net/http"
"strings"
@ -35,7 +35,7 @@ func (r *Registry) ManifestDigest(repository, reference string) (digest.Digest,
// Try to get digest from body instead, should be equal to what would be presented
// in Docker-Content-Digest
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}

View File

@ -3,7 +3,6 @@ package docker
import (
"bytes"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
@ -26,13 +25,13 @@ func TestGetDigest(t *testing.T) {
}
defer resp.Body.Close()
bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyBytes, _ := io.ReadAll(resp.Body)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("content-type", "application/vnd.docker.distribution.manifest.v2+json; charset=ISO-8859-1")
io.Copy(w, resp.Body)
// Reset body for additional calls
resp.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
resp.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
}))
defer ts.Close()

View File

@ -2,7 +2,6 @@ package poll
import (
"context"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -30,7 +29,7 @@ func (g *FakeSecretsGetter) Get(image *types.TrackedImage) (*types.Credentials,
}
func newTestingUtils() (*sql.SQLStore, func()) {
dir, err := ioutil.TempDir("", "whstoretest")
dir, err := os.MkdirTemp("", "whstoretest")
if err != nil {
log.Fatal(err)
}

View File

@ -1,7 +1,6 @@
package pubsub
import (
"io/ioutil"
"log"
"os"
"path/filepath"
@ -20,7 +19,7 @@ import (
)
func newTestingUtils() (*sql.SQLStore, func()) {
dir, err := ioutil.TempDir("", "whstoretest")
dir, err := os.MkdirTemp("", "whstoretest")
if err != nil {
log.Fatal(err)
}

View File

@ -1,7 +1,7 @@
package pubsub
import (
"io/ioutil"
"io"
"net/http"
"regexp"
@ -43,7 +43,7 @@ func getClusterName(metadataEndpoint string) (string, error) {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}