Skip to content

Commit

Permalink
Do not use deprecated io/ioutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
talal committed Nov 24, 2021
1 parent a3b3396 commit 9aa7114
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions test/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -292,7 +291,7 @@ var _ = Describe("Controller", func() {

response := recorder.Result()
Expect(response.StatusCode).To(Equal(200))
responseBytes, err := ioutil.ReadAll(response.Body)
responseBytes, err := io.ReadAll(response.Body)
Expect(err).ToNot(HaveOccurred())

// Write actual content to file to make it easy to copy the
Expand All @@ -301,7 +300,7 @@ var _ = Describe("Controller", func() {
fixturePath, err := filepath.Abs("fixtures/metrics.prom")
Expect(err).ToNot(HaveOccurred())
actualPath := fixturePath + ".actual"
err = ioutil.WriteFile(actualPath, responseBytes, 0600)
err = os.WriteFile(actualPath, responseBytes, 0600)
Expect(err).ToNot(HaveOccurred())

cmd := exec.Command("diff", "-u", fixturePath, actualPath)
Expand Down
7 changes: 3 additions & 4 deletions test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package test
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -65,7 +64,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
// Get directory for control plane binaries.
// setup-envtest should have downloaded binaries in a directory inside bin/k8s.
files, err := ioutil.ReadDir("bin/k8s")
files, err := os.ReadDir("bin/k8s")
Expect(err).ToNot(HaveOccurred())
if len(files) != 1 || !files[0].IsDir() {
Fail("test/bin/k8s should only have one directory and that directory should contain control plane binaries")
Expand Down Expand Up @@ -116,10 +115,10 @@ var _ = BeforeSuite(func() {

By("adding mock PrometheusRule resources")
mockDir := filepath.Join("fixtures", "prometheusrules")
mockFiles, err := ioutil.ReadDir(mockDir)
mockFiles, err := os.ReadDir(mockDir)
Expect(err).ToNot(HaveOccurred())
for _, file := range mockFiles {
b, err := ioutil.ReadFile(filepath.Join(mockDir, file.Name()))
b, err := os.ReadFile(filepath.Join(mockDir, file.Name()))
Expect(err).ToNot(HaveOccurred())

var pr monitoringv1.PrometheusRule
Expand Down

0 comments on commit 9aa7114

Please sign in to comment.