mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #111567 from inosato/remove-ioutil-from-component-base
Remove ioutil from component-base
This commit is contained in:
commit
ad1e330977
@ -19,7 +19,6 @@ package testing
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@ -47,7 +46,7 @@ func RunTestsOnYAMLData(t *testing.T, tests []TestCase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func decodeYAML(t *testing.T, path string, codec runtime.Codec) runtime.Object {
|
func decodeYAML(t *testing.T, path string, codec runtime.Codec) runtime.Object {
|
||||||
content, err := ioutil.ReadFile(path)
|
content, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -72,7 +71,7 @@ func getCodecForGV(codecs serializer.CodecFactory, gv schema.GroupVersion) (runt
|
|||||||
}
|
}
|
||||||
|
|
||||||
func matchOutputFile(t *testing.T, actual []byte, expectedFilePath string) {
|
func matchOutputFile(t *testing.T, actual []byte, expectedFilePath string) {
|
||||||
expected, err := ioutil.ReadFile(expectedFilePath)
|
expected, err := os.ReadFile(expectedFilePath)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
t.Fatalf("couldn't read test data: %v", err)
|
t.Fatalf("couldn't read test data: %v", err)
|
||||||
}
|
}
|
||||||
@ -97,7 +96,7 @@ func matchOutputFile(t *testing.T, actual []byte, expectedFilePath string) {
|
|||||||
if err := os.MkdirAll(filepath.Dir(expectedFilePath), 0755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(expectedFilePath), 0755); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(expectedFilePath, actual, 0644); err != nil {
|
if err := os.WriteFile(expectedFilePath, actual, 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
t.Error("wrote expected test data... verify, commit, and rerun tests")
|
t.Error("wrote expected test data... verify, commit, and rerun tests")
|
||||||
|
@ -18,7 +18,7 @@ package testing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ func GetRoundtripTestCases(t *testing.T, scheme *runtime.Scheme, codecs serializ
|
|||||||
|
|
||||||
for gk, versions := range versionsForKind {
|
for gk, versions := range versionsForKind {
|
||||||
testdir := filepath.Join("testdata", gk.Kind, "roundtrip")
|
testdir := filepath.Join("testdata", gk.Kind, "roundtrip")
|
||||||
dirs, err := ioutil.ReadDir(testdir)
|
dirs, err := os.ReadDir(testdir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to read testdir %s: %v", testdir, err)
|
t.Fatalf("failed to read testdir %s: %v", testdir, err)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
package configz
|
package configz
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
@ -39,7 +39,7 @@ func TestConfigz(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ func TestConfigz(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err = ioutil.ReadAll(resp.Body)
|
body, err = io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ func TestConfigz(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err = ioutil.ReadAll(resp.Body)
|
body, err = io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
@ -57,7 +57,7 @@ func TestResetHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
resetHandler.ServeHTTP(rec, req)
|
resetHandler.ServeHTTP(rec, req)
|
||||||
body, err := ioutil.ReadAll(rec.Result().Body)
|
body, err := io.ReadAll(rec.Result().Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error reading response body")
|
t.Fatalf("Error reading response body")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user