Skip to content

Commit cd66b69

Browse files
authored
chore(deps): replace deprecated ioutil with os and io in tests (kubeflow#11577)
* updated backend tests Signed-off-by: Daniel Dowler <[email protected]> * backend switched from ioutil to os and io Signed-off-by: Daniel Dowler <[email protected]> --------- Signed-off-by: Daniel Dowler <[email protected]>
1 parent 9c5b72c commit cd66b69

File tree

27 files changed

+83
-91
lines changed

27 files changed

+83
-91
lines changed

backend/src/apiserver/server/api_util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package server
1616

1717
import (
18-
"io/ioutil"
18+
"os"
1919
"strings"
2020
"testing"
2121

@@ -377,7 +377,7 @@ func TestValidateRunMetric_InvalidNodeIDs(t *testing.T) {
377377
}
378378

379379
func loadYaml(t *testing.T, path string) string {
380-
res, err := ioutil.ReadFile(path)
380+
res, err := os.ReadFile(path)
381381
if err != nil {
382382
t.Error(err)
383383
}

backend/src/apiserver/server/pipeline_server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package server
1717
import (
1818
"context"
1919
"encoding/json"
20-
"io/ioutil"
20+
"io"
2121
"net/http"
2222
"net/http/httptest"
2323
"os"
@@ -614,7 +614,7 @@ func getMockServer(t *testing.T) *httptest.Server {
614614
// Send response to be tested
615615
file, err := os.Open("test" + req.URL.String())
616616
assert.Nil(t, err)
617-
bytes, err := ioutil.ReadAll(file)
617+
bytes, err := io.ReadAll(file)
618618
assert.Nil(t, err)
619619

620620
rw.WriteHeader(http.StatusOK)

backend/src/apiserver/server/util.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"compress/gzip"
2323
"errors"
2424
"io"
25-
"io/ioutil"
2625
"strings"
2726

2827
"github.com/kubeflow/pipelines/backend/src/common/util"
@@ -108,7 +107,7 @@ func DecompressPipelineTarball(compressedFile []byte) ([]byte, error) {
108107
}
109108
}
110109

111-
decompressedFile, err := ioutil.ReadAll(tarReader)
110+
decompressedFile, err := io.ReadAll(tarReader)
112111
if err != nil {
113112
return nil, util.NewInvalidInputErrorWithDetails(err, "Error reading pipeline YAML from the tarball file")
114113
}
@@ -141,7 +140,7 @@ func DecompressPipelineZip(compressedFile []byte) ([]byte, error) {
141140
if err != nil {
142141
return nil, util.NewInvalidInputErrorWithDetails(err, "Error extracting pipeline from the zip file. Failed to read the content")
143142
}
144-
decompressedFile, err := ioutil.ReadAll(rc)
143+
decompressedFile, err := io.ReadAll(rc)
145144
if err != nil {
146145
return nil, util.NewInvalidInputErrorWithDetails(err, "Error reading pipeline YAML from the zip file")
147146
}

backend/src/apiserver/server/util_test.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package server
1616

1717
import (
18-
"io/ioutil"
1918
"os"
2019
"strings"
2120
"testing"
@@ -47,67 +46,67 @@ func TestLoadFile_LargeDoc(t *testing.T) {
4746
}
4847

4948
func TestDecompressPipelineTarball(t *testing.T) {
50-
tarballByte, _ := ioutil.ReadFile("test/arguments_tarball/arguments.tar.gz")
49+
tarballByte, _ := os.ReadFile("test/arguments_tarball/arguments.tar.gz")
5150
pipelineFile, err := DecompressPipelineTarball(tarballByte)
5251
assert.Nil(t, err)
5352

54-
expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
53+
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
5554
assert.Equal(t, expectedPipelineFile, pipelineFile)
5655
}
5756

5857
func TestDecompressPipelineTarball_MalformattedTarball(t *testing.T) {
59-
tarballByte, _ := ioutil.ReadFile("test/malformatted_tarball.tar.gz")
58+
tarballByte, _ := os.ReadFile("test/malformatted_tarball.tar.gz")
6059
_, err := DecompressPipelineTarball(tarballByte)
6160
assert.NotNil(t, err)
6261
assert.Contains(t, err.Error(), "Not a valid tarball file")
6362
}
6463

6564
func TestDecompressPipelineTarball_NonYamlTarball(t *testing.T) {
66-
tarballByte, _ := ioutil.ReadFile("test/non_yaml_tarball/non_yaml_tarball.tar.gz")
65+
tarballByte, _ := os.ReadFile("test/non_yaml_tarball/non_yaml_tarball.tar.gz")
6766
_, err := DecompressPipelineTarball(tarballByte)
6867
assert.NotNil(t, err)
6968
assert.Contains(t, err.Error(), "Expecting a pipeline.yaml file inside the tarball")
7069
}
7170

7271
func TestDecompressPipelineTarball_EmptyTarball(t *testing.T) {
73-
tarballByte, _ := ioutil.ReadFile("test/empty_tarball/empty.tar.gz")
72+
tarballByte, _ := os.ReadFile("test/empty_tarball/empty.tar.gz")
7473
_, err := DecompressPipelineTarball(tarballByte)
7574
assert.NotNil(t, err)
7675
assert.Contains(t, err.Error(), "Not a valid tarball file")
7776
}
7877

7978
func TestDecompressPipelineZip(t *testing.T) {
80-
zipByte, _ := ioutil.ReadFile("test/arguments_zip/arguments-parameters.zip")
79+
zipByte, _ := os.ReadFile("test/arguments_zip/arguments-parameters.zip")
8180
pipelineFile, err := DecompressPipelineZip(zipByte)
8281
assert.Nil(t, err)
8382

84-
expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
83+
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
8584
assert.Equal(t, expectedPipelineFile, pipelineFile)
8685
}
8786

8887
func TestDecompressPipelineZip_MalformattedZip(t *testing.T) {
89-
zipByte, _ := ioutil.ReadFile("test/malformatted_zip.zip")
88+
zipByte, _ := os.ReadFile("test/malformatted_zip.zip")
9089
_, err := DecompressPipelineZip(zipByte)
9190
assert.NotNil(t, err)
9291
assert.Contains(t, err.Error(), "Not a valid zip file")
9392
}
9493

9594
func TestDecompressPipelineZip_MalformedZip2(t *testing.T) {
96-
zipByte, _ := ioutil.ReadFile("test/malformed_zip2.zip")
95+
zipByte, _ := os.ReadFile("test/malformed_zip2.zip")
9796
_, err := DecompressPipelineZip(zipByte)
9897
assert.NotNil(t, err)
9998
assert.Contains(t, err.Error(), "Not a valid zip file")
10099
}
101100

102101
func TestDecompressPipelineZip_NonYamlZip(t *testing.T) {
103-
zipByte, _ := ioutil.ReadFile("test/non_yaml_zip/non_yaml_file.zip")
102+
zipByte, _ := os.ReadFile("test/non_yaml_zip/non_yaml_file.zip")
104103
_, err := DecompressPipelineZip(zipByte)
105104
assert.NotNil(t, err)
106105
assert.Contains(t, err.Error(), "Expecting a pipeline.yaml file inside the zip")
107106
}
108107

109108
func TestDecompressPipelineZip_EmptyZip(t *testing.T) {
110-
zipByte, _ := ioutil.ReadFile("test/empty_tarball/empty.zip")
109+
zipByte, _ := os.ReadFile("test/empty_tarball/empty.zip")
111110
_, err := DecompressPipelineZip(zipByte)
112111
assert.NotNil(t, err)
113112
assert.Contains(t, err.Error(), "Not a valid zip file")
@@ -118,7 +117,7 @@ func TestReadPipelineFile_YAML(t *testing.T) {
118117
fileBytes, err := ReadPipelineFile("arguments-parameters.yaml", file, common.MaxFileLength)
119118
assert.Nil(t, err)
120119

121-
expectedFileBytes, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
120+
expectedFileBytes, _ := os.ReadFile("test/arguments-parameters.yaml")
122121
assert.Equal(t, expectedFileBytes, fileBytes)
123122
}
124123

@@ -127,7 +126,7 @@ func TestReadPipelineFile_JSON(t *testing.T) {
127126
fileBytes, err := ReadPipelineFile("v2-hello-world.json", file, common.MaxFileLength)
128127
assert.Nil(t, err)
129128

130-
expectedFileBytes, _ := ioutil.ReadFile("test/v2-hello-world.json")
129+
expectedFileBytes, _ := os.ReadFile("test/v2-hello-world.json")
131130
assert.Equal(t, expectedFileBytes, fileBytes)
132131
}
133132

@@ -136,7 +135,7 @@ func TestReadPipelineFile_Zip(t *testing.T) {
136135
pipelineFile, err := ReadPipelineFile("arguments-parameters.zip", file, common.MaxFileLength)
137136
assert.Nil(t, err)
138137

139-
expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
138+
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
140139
assert.Equal(t, expectedPipelineFile, pipelineFile)
141140
}
142141

@@ -145,7 +144,7 @@ func TestReadPipelineFile_Zip_AnyExtension(t *testing.T) {
145144
pipelineFile, err := ReadPipelineFile("arguments-parameters.pipeline", file, common.MaxFileLength)
146145
assert.Nil(t, err)
147146

148-
expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
147+
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
149148
assert.Equal(t, expectedPipelineFile, pipelineFile)
150149
}
151150

@@ -154,7 +153,7 @@ func TestReadPipelineFile_MultifileZip(t *testing.T) {
154153
pipelineFile, err := ReadPipelineFile("pipeline_plus_component.ai-hub-package", file, common.MaxFileLength)
155154
assert.Nil(t, err)
156155

157-
expectedPipelineFile, _ := ioutil.ReadFile("test/pipeline_plus_component/pipeline.yaml")
156+
expectedPipelineFile, _ := os.ReadFile("test/pipeline_plus_component/pipeline.yaml")
158157
assert.Equal(t, expectedPipelineFile, pipelineFile)
159158
}
160159

@@ -163,7 +162,7 @@ func TestReadPipelineFile_Tarball(t *testing.T) {
163162
pipelineFile, err := ReadPipelineFile("arguments.tar.gz", file, common.MaxFileLength)
164163
assert.Nil(t, err)
165164

166-
expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
165+
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
167166
assert.Equal(t, expectedPipelineFile, pipelineFile)
168167
}
169168

@@ -172,7 +171,7 @@ func TestReadPipelineFile_Tarball_AnyExtension(t *testing.T) {
172171
pipelineFile, err := ReadPipelineFile("arguments.pipeline", file, common.MaxFileLength)
173172
assert.Nil(t, err)
174173

175-
expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
174+
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
176175
assert.Equal(t, expectedPipelineFile, pipelineFile)
177176
}
178177

@@ -181,7 +180,7 @@ func TestReadPipelineFile_MultifileTarball(t *testing.T) {
181180
pipelineFile, err := ReadPipelineFile("pipeline_plus_component.ai-hub-package", file, common.MaxFileLength)
182181
assert.Nil(t, err)
183182

184-
expectedPipelineFile, _ := ioutil.ReadFile("test/pipeline_plus_component/pipeline.yaml")
183+
expectedPipelineFile, _ := os.ReadFile("test/pipeline_plus_component/pipeline.yaml")
185184
assert.Equal(t, expectedPipelineFile, pipelineFile)
186185
}
187186

backend/src/apiserver/server/visualization_server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"context"
1919
"encoding/json"
2020
"fmt"
21-
"io/ioutil"
21+
"io"
2222
"net/http"
2323
"net/url"
2424
"strings"
@@ -120,7 +120,7 @@ func (s *VisualizationServer) generateVisualizationFromRequest(request *go_clien
120120
return nil, fmt.Errorf(resp.Status)
121121
}
122122
defer resp.Body.Close()
123-
body, err := ioutil.ReadAll(resp.Body)
123+
body, err := io.ReadAll(resp.Body)
124124
if err != nil {
125125
return nil, util.Wrap(err, "Unable to parse visualization response")
126126
}

backend/src/apiserver/template/template_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package template
1616

1717
import (
1818
"encoding/json"
19-
"io/ioutil"
19+
"os"
2020
"strings"
2121
"testing"
2222
"time"
@@ -255,7 +255,7 @@ func TestModelToCRDTrigger_Cron(t *testing.T) {
255255
}
256256

257257
func loadYaml(t *testing.T, path string) string {
258-
res, err := ioutil.ReadFile(path)
258+
res, err := os.ReadFile(path)
259259
if err != nil {
260260
t.Error(err)
261261
}

backend/src/cache/server/admission.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"encoding/json"
1919
"errors"
2020
"fmt"
21-
"io/ioutil"
21+
"io"
2222
"log"
2323
"net/http"
2424

@@ -73,7 +73,7 @@ func doServeAdmitFunc(w http.ResponseWriter, r *http.Request, admit admitFunc, c
7373
return nil, fmt.Errorf("Invalid method %q, only POST requests are allowed", r.Method)
7474
}
7575

76-
body, err := ioutil.ReadAll(r.Body)
76+
body, err := io.ReadAll(r.Body)
7777
if err != nil {
7878
w.WriteHeader(http.StatusBadRequest)
7979
return nil, fmt.Errorf("Could not read request body: %v", err)

backend/src/common/client/api_server/util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package api_server
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"net/http"
76
"os"
87
"time"
@@ -38,7 +37,7 @@ var SATokenVolumeProjectionAuth runtime.ClientAuthInfoWriter = runtime.ClientAut
3837
projectedPath = saDefaultTokenPath
3938
}
4039

41-
content, err := ioutil.ReadFile(projectedPath)
40+
content, err := os.ReadFile(projectedPath)
4241
if err != nil {
4342
return fmt.Errorf("Failed to read projected SA token at %s: %w", projectedPath, err)
4443
}

backend/src/common/util/tgz.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"bytes"
2020
"compress/gzip"
2121
"io"
22-
"io/ioutil"
2322
"strings"
2423
)
2524

@@ -77,7 +76,7 @@ func ExtractTgz(tgzContent string) (map[string]string, error) {
7776
if hdr == nil {
7877
continue
7978
}
80-
fileContent, err := ioutil.ReadAll(tr)
79+
fileContent, err := io.ReadAll(tr)
8180
if err != nil {
8281
return nil, err
8382
}

backend/src/v2/cmd/compiler/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package main
1616
import (
1717
"flag"
1818
"fmt"
19-
"io/ioutil"
2019
"os"
2120

2221
"github.com/golang/glog"
@@ -92,7 +91,7 @@ func init() {
9291
}
9392

9493
func loadJob(path string) (*pipelinespec.PipelineJob, error) {
95-
bytes, err := ioutil.ReadFile(path)
94+
bytes, err := os.ReadFile(path)
9695
if err != nil {
9796
return nil, err
9897
}
@@ -104,7 +103,7 @@ func loadJob(path string) (*pipelinespec.PipelineJob, error) {
104103
}
105104

106105
func loadSpec(path string) (*pipelinespec.PipelineJob, error) {
107-
bytes, err := ioutil.ReadFile(path)
106+
bytes, err := os.ReadFile(path)
108107
if err != nil {
109108
return nil, err
110109
}

0 commit comments

Comments
 (0)