Refactor: move from io/ioutil to io and os package (#2234)

The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <zerjun@beatchain.co>
This commit is contained in:
Eng Zer Jun
2021-09-06 18:33:42 +08:00
committed by GitHub
parent f8ac24db27
commit 426aa7af34
49 changed files with 143 additions and 171 deletions
@@ -21,7 +21,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
@@ -67,7 +67,7 @@ func makeHTTPRequest(ctx context.Context, webhookEndPoint, method string, payloa
if requestErr != nil {
return requestErr
}
body, requestErr = ioutil.ReadAll(r.Body)
body, requestErr = io.ReadAll(r.Body)
if requestErr != nil {
return requestErr
}
@@ -17,7 +17,7 @@ limitations under the License.
package assemble
import (
"io/ioutil"
"os"
"testing"
. "github.com/onsi/ginkgo"
@@ -43,7 +43,7 @@ var _ = Describe("Test Assemble Options", func() {
)
appRev := &v1beta1.ApplicationRevision{}
b, err := ioutil.ReadFile("./testdata/apprevision.yaml")
b, err := os.ReadFile("./testdata/apprevision.yaml")
/* appRevision test data is generated based on below application
apiVersion: core.oam.dev/v1beta1
kind: Application
@@ -156,7 +156,7 @@ var _ = Describe("Test Assemble Options", func() {
compName = "frontend"
)
appRev := &v1beta1.ApplicationRevision{}
b, err := ioutil.ReadFile("./testdata/filter_annotations.yaml")
b, err := os.ReadFile("./testdata/filter_annotations.yaml")
getKeys := func(m map[string]string) []string {
var keys []string
for k := range m {
@@ -19,7 +19,7 @@ package assemble
import (
"context"
"fmt"
"io/ioutil"
"os"
"reflect"
"github.com/google/go-cmp/cmp"
@@ -49,7 +49,7 @@ var _ = Describe("Test WorkloadOption", func() {
BeforeEach(func() {
appRev = &v1beta1.ApplicationRevision{}
b, err := ioutil.ReadFile("./testdata/apprevision.yaml")
b, err := os.ReadFile("./testdata/apprevision.yaml")
Expect(err).Should(BeNil())
err = yaml.Unmarshal(b, appRev)
Expect(err).Should(BeNil())
@@ -21,7 +21,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -61,7 +61,7 @@ func (c *ComponentHandler) customComponentRevisionHook(relatedApps []reconcile.R
}
//nolint:errcheck
defer resp.Body.Close()
respData, err := ioutil.ReadAll(resp.Body)
respData, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
@@ -19,7 +19,7 @@ package applicationconfiguration
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
@@ -36,7 +36,7 @@ import (
var RevisionHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var req RevisionHookRequest
data, err := ioutil.ReadAll(r.Body)
data, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(400)
return
+2 -2
View File
@@ -19,7 +19,7 @@ package utils
import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
@@ -218,7 +218,7 @@ func TestFixOpenAPISchema(t *testing.T) {
schema := swagger.Components.Schemas[model.ParameterFieldName].Value
fixOpenAPISchema("", schema)
fixedSchema, _ := schema.MarshalJSON()
expectedSchema, _ := ioutil.ReadFile(filepath.Join(TestDir, tc.fixedFile))
expectedSchema, _ := os.ReadFile(filepath.Join(TestDir, tc.fixedFile))
assert.Equal(t, string(fixedSchema), string(expectedSchema))
})
}