Skip to content

Commit

Permalink
smoke: replaces the io/ioutil API which was deprecated in go 1.19
Browse files Browse the repository at this point in the history
Signed-off-by: Qinqi Qu <quqinqi@linux.alibaba.com>
  • Loading branch information
adamqqqplay authored and imeoer committed Oct 27, 2023
1 parent cb458bd commit 69ddef9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 15 deletions.
3 changes: 1 addition & 2 deletions contrib/nydusify/cmd/nydusify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main

import (
"encoding/json"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -50,7 +49,7 @@ func TestParseBackendConfig(t *testing.T) {
}`
require.True(t, json.Valid([]byte(configJSON)))

file, err := ioutil.TempFile("", "nydusify-backend-config-test.json")
file, err := os.CreateTemp("", "nydusify-backend-config-test.json")
require.NoError(t, err)
defer os.RemoveAll(file.Name())

Expand Down
4 changes: 2 additions & 2 deletions smoke/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package tests
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -231,7 +231,7 @@ func (a *APIV1TestSuite) visit(path string) error {
}
defer f.Close()

ioutil.ReadAll(f)
io.ReadAll(f)

return nil
}
Expand Down
3 changes: 1 addition & 2 deletions smoke/tests/blobcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -47,7 +46,7 @@ func (a *BlobCacheTestSuite) prepareTestEnv(t *testing.T) (*tool.Context, string
rootfsReader := rootFs.ToOCITar(t)

ociBlobDigester := digest.Canonical.Digester()
ociBlob, err := ioutil.TempFile(ctx.Env.BlobDir, "oci-blob-")
ociBlob, err := os.CreateTemp(ctx.Env.BlobDir, "oci-blob-")
require.NoError(t, err)

_, err = io.Copy(io.MultiWriter(ociBlobDigester.Hash(), ociBlob), rootfsReader)
Expand Down
3 changes: 1 addition & 2 deletions smoke/tests/tool/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package tool

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -86,7 +85,7 @@ func (ctx *Context) PrepareWorkDir(t *testing.T) {
if tempDir == "" {
tempDir = os.TempDir()
}
workDir, err := ioutil.TempDir(tempDir, "nydus-smoke-")
workDir, err := os.MkdirTemp(tempDir, "nydus-smoke-")
require.NoError(t, err)

blobDir := filepath.Join(workDir, "blobs")
Expand Down
9 changes: 4 additions & 5 deletions smoke/tests/tool/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"context"
"crypto/rand"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -121,7 +120,7 @@ func (l *Layer) Pack(t *testing.T, packOption converter.PackOption, blobDir stri
l.recordFileTree(t)

// Pack OCI tar to nydus native blob
blob, err := ioutil.TempFile(blobDir, "blob-")
blob, err := os.CreateTemp(blobDir, "blob-")
require.NoError(t, err)
defer blob.Close()
blobDigester := digest.Canonical.Digester()
Expand Down Expand Up @@ -160,7 +159,7 @@ func (l *Layer) PackRef(t *testing.T, ctx Context, blobDir string, compress bool
}

// Pack OCI blob to nydus zran blob
rafsBlob, err := ioutil.TempFile(blobDir, "rafs-blob-")
rafsBlob, err := os.CreateTemp(blobDir, "rafs-blob-")
require.NoError(t, err)
defer rafsBlob.Close()
rafsBlobDigester := digest.Canonical.Digester()
Expand All @@ -172,7 +171,7 @@ func (l *Layer) PackRef(t *testing.T, ctx Context, blobDir string, compress bool
require.NoError(t, err)

ociBlobDigester := digest.Canonical.Digester()
ociBlob, err := ioutil.TempFile(blobDir, "oci-blob-")
ociBlob, err := os.CreateTemp(blobDir, "oci-blob-")
require.NoError(t, err)

_, err = io.Copy(io.MultiWriter(twc, ociBlobDigester.Hash(), ociBlob), ociBlobReader)
Expand Down Expand Up @@ -250,7 +249,7 @@ func MergeLayers(t *testing.T, ctx Context, mergeOption converter.MergeOption, l
layers[idx].ReaderAt = ra
}

bootstrap, err := ioutil.TempFile(ctx.Env.WorkDir, "bootstrap-")
bootstrap, err := os.CreateTemp(ctx.Env.WorkDir, "bootstrap-")
require.NoError(t, err)
defer bootstrap.Close()
actualDigests, err := converter.Merge(context.Background(), layers, bootstrap, mergeOption)
Expand Down
3 changes: 1 addition & 2 deletions smoke/tests/tool/nydusd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -246,7 +245,7 @@ func (nydusd *Nydusd) MountByAPI(config NydusdConfig) error {
return err
}
defer f.Close()
rafsConfig, err := ioutil.ReadAll(f)
rafsConfig, err := io.ReadAll(f)
if err != nil {
return err
}
Expand Down

0 comments on commit 69ddef9

Please sign in to comment.