From 62f79457de6931b7625966b00a97076efcce1fc1 Mon Sep 17 00:00:00 2001 From: Rob Shakir Date: Fri, 19 Jul 2024 19:50:53 -0700 Subject: [PATCH] More `ioutil` removal. --- demo/optical/opticaldemo_test.go | 6 +++--- ytypes/schema_tests/diff_benchmark_test.go | 14 +++++++------- ytypes/schema_tests/validate_test.go | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/demo/optical/opticaldemo_test.go b/demo/optical/opticaldemo_test.go index 3b31cfe1b..dc6567ee6 100644 --- a/demo/optical/opticaldemo_test.go +++ b/demo/optical/opticaldemo_test.go @@ -15,7 +15,7 @@ package main import ( - "io/ioutil" + "os" "path/filepath" "testing" @@ -62,9 +62,9 @@ func TestOpticalDemoJSON(t *testing.T) { }} for _, tt := range tests { - want, err := ioutil.ReadFile(filepath.Join(TestRoot, "testdata", tt.wantFile)) + want, err := os.ReadFile(filepath.Join(TestRoot, "testdata", tt.wantFile)) if err != nil { - t.Errorf("ioutil.ReadFile(%s/testdata/%s): could not open file: %v", TestRoot, tt.wantFile, err) + t.Errorf("os.ReadFile(%s/testdata/%s): could not open file: %v", TestRoot, tt.wantFile, err) continue } if diff := pretty.Compare(tt.got, string(want)); diff != "" { diff --git a/ytypes/schema_tests/diff_benchmark_test.go b/ytypes/schema_tests/diff_benchmark_test.go index cf23d0c05..991407823 100644 --- a/ytypes/schema_tests/diff_benchmark_test.go +++ b/ytypes/schema_tests/diff_benchmark_test.go @@ -15,7 +15,7 @@ package validate import ( - "io/ioutil" + "os" "path/filepath" "testing" @@ -27,25 +27,25 @@ func BenchmarkDiff(b *testing.B) { jsonFileA := "interfaceBenchmarkA.json" jsonFileB := "interfaceBenchmarkB.json" - jsonA, err := ioutil.ReadFile(filepath.Join(testRoot, "testdata", jsonFileA)) + jsonA, err := os.ReadFile(filepath.Join(testRoot, "testdata", jsonFileA)) if err != nil { - b.Errorf("ioutil.ReadFile(%s): could not open file: %v", jsonFileA, err) + b.Errorf("os.ReadFile(%s): could not open file: %v", jsonFileA, err) return } deviceA := &oc.Device{} if err := oc.Unmarshal(jsonA, deviceA); err != nil { - b.Errorf("ioutil.ReadFile(%s): could unmarschal: %v", jsonFileA, err) + b.Errorf("os.ReadFile(%s): could unmarschal: %v", jsonFileA, err) return } - jsonB, err := ioutil.ReadFile(filepath.Join(testRoot, "testdata", jsonFileB)) + jsonB, err := os.ReadFile(filepath.Join(testRoot, "testdata", jsonFileB)) if err != nil { - b.Errorf("ioutil.ReadFile(%s): could not open file: %v", jsonFileB, err) + b.Errorf("os.ReadFile(%s): could not open file: %v", jsonFileB, err) return } deviceB := &oc.Device{} if err := oc.Unmarshal(jsonB, deviceB); err != nil { - b.Errorf("ioutil.ReadFile(%s): could unmarschal: %v", jsonFileB, err) + b.Errorf("os.ReadFile(%s): could unmarschal: %v", jsonFileB, err) return } _, err = ygot.Diff(deviceA, deviceB) diff --git a/ytypes/schema_tests/validate_test.go b/ytypes/schema_tests/validate_test.go index 117644cd3..321fb7cfe 100644 --- a/ytypes/schema_tests/validate_test.go +++ b/ytypes/schema_tests/validate_test.go @@ -19,7 +19,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "os" "path/filepath" "sort" "strings" @@ -733,17 +733,17 @@ func TestUnmarshal(t *testing.T) { for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { - j, err := ioutil.ReadFile(filepath.Join(testRoot, "testdata", tt.jsonFilePath)) + j, err := os.ReadFile(filepath.Join(testRoot, "testdata", tt.jsonFilePath)) if err != nil { - t.Errorf("%s: ioutil.ReadFile(%s): could not open file: %v", tt.desc, tt.jsonFilePath, err) + t.Errorf("%s: os.ReadFile(%s): could not open file: %v", tt.desc, tt.jsonFilePath, err) return } wantj := j if tt.outjsonFilePath != "" { - rj, err := ioutil.ReadFile(filepath.Join(testRoot, "testdata", tt.outjsonFilePath)) + rj, err := os.ReadFile(filepath.Join(testRoot, "testdata", tt.outjsonFilePath)) if err != nil { - t.Errorf("%s: ioutil.ReadFile(%s): could not open file: %v", tt.desc, tt.outjsonFilePath, err) + t.Errorf("%s: os.ReadFile(%s): could not open file: %v", tt.desc, tt.outjsonFilePath, err) } wantj = rj }