Skip to content

Commit

Permalink
chore(deps): replace deprecated ioutil with os and io in tests (#11577)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
dandawg authored Jan 31, 2025
1 parent 9c5b72c commit cd66b69
Show file tree
Hide file tree
Showing 27 changed files with 83 additions and 91 deletions.
4 changes: 2 additions & 2 deletions backend/src/apiserver/server/api_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package server

import (
"io/ioutil"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -377,7 +377,7 @@ func TestValidateRunMetric_InvalidNodeIDs(t *testing.T) {
}

func loadYaml(t *testing.T, path string) string {
res, err := ioutil.ReadFile(path)
res, err := os.ReadFile(path)
if err != nil {
t.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/apiserver/server/pipeline_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package server
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -614,7 +614,7 @@ func getMockServer(t *testing.T) *httptest.Server {
// Send response to be tested
file, err := os.Open("test" + req.URL.String())
assert.Nil(t, err)
bytes, err := ioutil.ReadAll(file)
bytes, err := io.ReadAll(file)
assert.Nil(t, err)

rw.WriteHeader(http.StatusOK)
Expand Down
5 changes: 2 additions & 3 deletions backend/src/apiserver/server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"compress/gzip"
"errors"
"io"
"io/ioutil"
"strings"

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

decompressedFile, err := ioutil.ReadAll(tarReader)
decompressedFile, err := io.ReadAll(tarReader)
if err != nil {
return nil, util.NewInvalidInputErrorWithDetails(err, "Error reading pipeline YAML from the tarball file")
}
Expand Down Expand Up @@ -141,7 +140,7 @@ func DecompressPipelineZip(compressedFile []byte) ([]byte, error) {
if err != nil {
return nil, util.NewInvalidInputErrorWithDetails(err, "Error extracting pipeline from the zip file. Failed to read the content")
}
decompressedFile, err := ioutil.ReadAll(rc)
decompressedFile, err := io.ReadAll(rc)
if err != nil {
return nil, util.NewInvalidInputErrorWithDetails(err, "Error reading pipeline YAML from the zip file")
}
Expand Down
39 changes: 19 additions & 20 deletions backend/src/apiserver/server/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package server

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -47,67 +46,67 @@ func TestLoadFile_LargeDoc(t *testing.T) {
}

func TestDecompressPipelineTarball(t *testing.T) {
tarballByte, _ := ioutil.ReadFile("test/arguments_tarball/arguments.tar.gz")
tarballByte, _ := os.ReadFile("test/arguments_tarball/arguments.tar.gz")
pipelineFile, err := DecompressPipelineTarball(tarballByte)
assert.Nil(t, err)

expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
assert.Equal(t, expectedPipelineFile, pipelineFile)
}

func TestDecompressPipelineTarball_MalformattedTarball(t *testing.T) {
tarballByte, _ := ioutil.ReadFile("test/malformatted_tarball.tar.gz")
tarballByte, _ := os.ReadFile("test/malformatted_tarball.tar.gz")
_, err := DecompressPipelineTarball(tarballByte)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "Not a valid tarball file")
}

func TestDecompressPipelineTarball_NonYamlTarball(t *testing.T) {
tarballByte, _ := ioutil.ReadFile("test/non_yaml_tarball/non_yaml_tarball.tar.gz")
tarballByte, _ := os.ReadFile("test/non_yaml_tarball/non_yaml_tarball.tar.gz")
_, err := DecompressPipelineTarball(tarballByte)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "Expecting a pipeline.yaml file inside the tarball")
}

func TestDecompressPipelineTarball_EmptyTarball(t *testing.T) {
tarballByte, _ := ioutil.ReadFile("test/empty_tarball/empty.tar.gz")
tarballByte, _ := os.ReadFile("test/empty_tarball/empty.tar.gz")
_, err := DecompressPipelineTarball(tarballByte)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "Not a valid tarball file")
}

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

expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
assert.Equal(t, expectedPipelineFile, pipelineFile)
}

func TestDecompressPipelineZip_MalformattedZip(t *testing.T) {
zipByte, _ := ioutil.ReadFile("test/malformatted_zip.zip")
zipByte, _ := os.ReadFile("test/malformatted_zip.zip")
_, err := DecompressPipelineZip(zipByte)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "Not a valid zip file")
}

func TestDecompressPipelineZip_MalformedZip2(t *testing.T) {
zipByte, _ := ioutil.ReadFile("test/malformed_zip2.zip")
zipByte, _ := os.ReadFile("test/malformed_zip2.zip")
_, err := DecompressPipelineZip(zipByte)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "Not a valid zip file")
}

func TestDecompressPipelineZip_NonYamlZip(t *testing.T) {
zipByte, _ := ioutil.ReadFile("test/non_yaml_zip/non_yaml_file.zip")
zipByte, _ := os.ReadFile("test/non_yaml_zip/non_yaml_file.zip")
_, err := DecompressPipelineZip(zipByte)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "Expecting a pipeline.yaml file inside the zip")
}

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

expectedFileBytes, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
expectedFileBytes, _ := os.ReadFile("test/arguments-parameters.yaml")
assert.Equal(t, expectedFileBytes, fileBytes)
}

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

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

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

expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
assert.Equal(t, expectedPipelineFile, pipelineFile)
}

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

expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
assert.Equal(t, expectedPipelineFile, pipelineFile)
}

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

expectedPipelineFile, _ := ioutil.ReadFile("test/pipeline_plus_component/pipeline.yaml")
expectedPipelineFile, _ := os.ReadFile("test/pipeline_plus_component/pipeline.yaml")
assert.Equal(t, expectedPipelineFile, pipelineFile)
}

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

expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
assert.Equal(t, expectedPipelineFile, pipelineFile)
}

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

expectedPipelineFile, _ := ioutil.ReadFile("test/arguments-parameters.yaml")
expectedPipelineFile, _ := os.ReadFile("test/arguments-parameters.yaml")
assert.Equal(t, expectedPipelineFile, pipelineFile)
}

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

expectedPipelineFile, _ := ioutil.ReadFile("test/pipeline_plus_component/pipeline.yaml")
expectedPipelineFile, _ := os.ReadFile("test/pipeline_plus_component/pipeline.yaml")
assert.Equal(t, expectedPipelineFile, pipelineFile)
}

Expand Down
4 changes: 2 additions & 2 deletions backend/src/apiserver/server/visualization_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -120,7 +120,7 @@ func (s *VisualizationServer) generateVisualizationFromRequest(request *go_clien
return nil, fmt.Errorf(resp.Status)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, util.Wrap(err, "Unable to parse visualization response")
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/apiserver/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package template

import (
"encoding/json"
"io/ioutil"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestModelToCRDTrigger_Cron(t *testing.T) {
}

func loadYaml(t *testing.T, path string) string {
res, err := ioutil.ReadFile(path)
res, err := os.ReadFile(path)
if err != nil {
t.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/cache/server/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"

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

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return nil, fmt.Errorf("Could not read request body: %v", err)
Expand Down
3 changes: 1 addition & 2 deletions backend/src/common/client/api_server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api_server

import (
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
Expand Down Expand Up @@ -38,7 +37,7 @@ var SATokenVolumeProjectionAuth runtime.ClientAuthInfoWriter = runtime.ClientAut
projectedPath = saDefaultTokenPath
}

content, err := ioutil.ReadFile(projectedPath)
content, err := os.ReadFile(projectedPath)
if err != nil {
return fmt.Errorf("Failed to read projected SA token at %s: %w", projectedPath, err)
}
Expand Down
3 changes: 1 addition & 2 deletions backend/src/common/util/tgz.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"bytes"
"compress/gzip"
"io"
"io/ioutil"
"strings"
)

Expand Down Expand Up @@ -77,7 +76,7 @@ func ExtractTgz(tgzContent string) (map[string]string, error) {
if hdr == nil {
continue
}
fileContent, err := ioutil.ReadAll(tr)
fileContent, err := io.ReadAll(tr)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions backend/src/v2/cmd/compiler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"

"github.com/golang/glog"
Expand Down Expand Up @@ -92,7 +91,7 @@ func init() {
}

func loadJob(path string) (*pipelinespec.PipelineJob, error) {
bytes, err := ioutil.ReadFile(path)
bytes, err := os.ReadFile(path)
if err != nil {
return nil, err
}
Expand All @@ -104,7 +103,7 @@ func loadJob(path string) (*pipelinespec.PipelineJob, error) {
}

func loadSpec(path string) (*pipelinespec.PipelineJob, error) {
bytes, err := ioutil.ReadFile(path)
bytes, err := os.ReadFile(path)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions backend/src/v2/cmd/driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -275,7 +274,7 @@ func writeFile(path string, data []byte) (err error) {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return err
}
return ioutil.WriteFile(path, data, 0o644)
return os.WriteFile(path, data, 0o644)
}

func newMlmdClient() (*metadata.Client, error) {
Expand Down
10 changes: 5 additions & 5 deletions backend/src/v2/compiler/argocompiler/argo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package argocompiler_test
import (
"flag"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -80,12 +80,12 @@ func Test_argo_compiler(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(tt.argoYAMLPath, got, 0x664)
err = os.WriteFile(tt.argoYAMLPath, got, 0x664)
if err != nil {
t.Fatal(err)
}
}
argoYAML, err := ioutil.ReadFile(tt.argoYAMLPath)
argoYAML, err := os.ReadFile(tt.argoYAMLPath)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func Test_argo_compiler(t *testing.T) {

func load(t *testing.T, path string, platformSpecPath string) (*pipelinespec.PipelineJob, *pipelinespec.SinglePlatformSpec) {
t.Helper()
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
t.Error(err)
}
Expand All @@ -136,7 +136,7 @@ func load(t *testing.T, path string, platformSpecPath string) (*pipelinespec.Pip

platformSpec := &pipelinespec.PlatformSpec{}
if platformSpecPath != "" {
content, err = ioutil.ReadFile(platformSpecPath)
content, err = os.ReadFile(platformSpecPath)
if err != nil {
t.Error(err)
}
Expand Down
Loading

0 comments on commit cd66b69

Please sign in to comment.