Skip to content

Commit

Permalink
More ioutil removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
robshakir committed Jul 20, 2024
1 parent 6eac287 commit 62f7945
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions demo/optical/opticaldemo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -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 != "" {
Expand Down
14 changes: 7 additions & 7 deletions ytypes/schema_tests/diff_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package validate

import (
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions ytypes/schema_tests/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 62f7945

Please sign in to comment.