Update deprecated io/ioutil functions

ioutil has been deprecated since go 1.16, this fixes all of the
deprecated functions we are using:

ioutil.ReadFile -> os.ReadFile
ioutil.ReadAll -> io.ReadAll
ioutil.WriteFile -> os.WriteFile
ioutil.TempFile -> os.CreateTemp
ioutil.TempDir -> os.MkdirTemp

All of the above are a simple name change, the function arguments and
results are exactly the same as before.

ioutil.ReadDir -> os.ReadDir

now returns a os.DirEntry but the IsDir and Name functions work the
same. The difference is that the FileInfo must be retrieved with the
Info() function which can also return an error.

These were identified by running:
golangci-lint run --build-tags=integration ./...
This commit is contained in:
Brian C. Lane 2023-03-06 11:07:30 -08:00 committed by Brian C. Lane
parent 0e4a5b34b2
commit 7a4bb863dd
37 changed files with 113 additions and 126 deletions

View file

@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
@ -72,7 +71,7 @@ func (a APICall) Do(t *testing.T) APICallResult {
a.Handler.ServeHTTP(respRecorder, req)
resp := respRecorder.Result()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
require.NoErrorf(t, err, "%s: could not read response body", a.Path)
if a.ExpectedStatus != 0 {

View file

@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
@ -107,7 +107,7 @@ func TestRouteWithReply(t *testing.T, api http.Handler, external bool, method, p
}
var err error
replyJSON, err = ioutil.ReadAll(resp.Body)
replyJSON, err = io.ReadAll(resp.Body)
require.NoErrorf(t, err, "%s: could not read response body", path)
assert.Equalf(t, expectedStatus, resp.StatusCode, "SendHTTP failed for path %s: %v", path, string(replyJSON))
@ -147,7 +147,7 @@ func TestTOMLRoute(t *testing.T, api http.Handler, external bool, method, path,
t.Skip("This test is for internal testing only")
}
replyTOML, err := ioutil.ReadAll(resp.Body)
replyTOML, err := io.ReadAll(resp.Body)
require.NoErrorf(t, err, "%s: could not read response body", path)
assert.Equalf(t, expectedStatus, resp.StatusCode, "SendHTTP failed for path %s: %v", path, string(replyTOML))
@ -177,7 +177,7 @@ func TestNonJsonRoute(t *testing.T, api http.Handler, external bool, method, pat
response := SendHTTP(api, external, method, path, body)
assert.Equalf(t, expectedStatus, response.StatusCode, "%s: status mismatch", path)
responseBodyBytes, err := ioutil.ReadAll(response.Body)
responseBodyBytes, err := io.ReadAll(response.Body)
require.NoErrorf(t, err, "%s: could not read response body", path)
responseBody := string(responseBodyBytes)
@ -209,7 +209,7 @@ func CompareImageTypes() cmp.Option {
// Create a temporary repository
func SetUpTemporaryRepository() (string, error) {
dir, err := ioutil.TempDir("/tmp", "osbuild-composer-test-")
dir, err := os.MkdirTemp("/tmp", "osbuild-composer-test-")
if err != nil {
return "", err
}