From 1b74b04e7dee8be3c18f5c204770d7771fc65215 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Wed, 5 Apr 2023 11:00:13 +0300 Subject: [PATCH] refactor: replace deprecated ioutil with io and os (#423) Co-authored-by: Patrik --- dockertest.go | 3 +-- dockertest_test.go | 11 ++++------- examples/FakeGoogleCloudStorage.md | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/dockertest.go b/dockertest.go index 54cdcd70..86d07e1b 100644 --- a/dockertest.go +++ b/dockertest.go @@ -6,7 +6,6 @@ package dockertest import ( "fmt" "io" - "io/ioutil" "net" "os" "path/filepath" @@ -340,7 +339,7 @@ func (d *Pool) BuildAndRunWithBuildOptions(buildOpts *BuildOptions, runOpts *Run err := d.Client.BuildImage(dc.BuildImageOptions{ Name: runOpts.Name, Dockerfile: buildOpts.Dockerfile, - OutputStream: ioutil.Discard, + OutputStream: io.Discard, ContextDir: buildOpts.ContextDir, BuildArgs: buildOpts.BuildArgs, Platform: buildOpts.Platform, diff --git a/dockertest_test.go b/dockertest_test.go index eb7647ae..254ba3ae 100644 --- a/dockertest_test.go +++ b/dockertest_test.go @@ -7,7 +7,6 @@ import ( "bytes" "database/sql" "fmt" - "io/ioutil" "log" "net/http" "os" @@ -199,11 +198,10 @@ func TestContainerWithPortBinding(t *testing.T) { func TestBuildImage(t *testing.T) { // Create Dockerfile in temp dir - dir, _ := ioutil.TempDir("", "dockertest") - defer os.RemoveAll(dir) + dir := t.TempDir() dockerfilePath := dir + "/Dockerfile" - ioutil.WriteFile(dockerfilePath, + os.WriteFile(dockerfilePath, []byte("FROM postgres:9.5"), 0o644, ) @@ -217,11 +215,10 @@ func TestBuildImage(t *testing.T) { func TestBuildImageWithBuildArg(t *testing.T) { // Create Dockerfile in temp dir - dir, _ := ioutil.TempDir("", "dockertest") - defer os.RemoveAll(dir) + dir := t.TempDir() dockerfilePath := dir + "/Dockerfile" - ioutil.WriteFile(dockerfilePath, + os.WriteFile(dockerfilePath, []byte((`FROM busybox ARG foo RUN echo -n $foo > /build-time-value diff --git a/examples/FakeGoogleCloudStorage.md b/examples/FakeGoogleCloudStorage.md index 6e0bbe29..54dda1ed 100644 --- a/examples/FakeGoogleCloudStorage.md +++ b/examples/FakeGoogleCloudStorage.md @@ -18,7 +18,7 @@ package main import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -198,7 +198,7 @@ func readFile(client *storage.Client, bucketName, fileName string) ([]byte, erro return nil, err } defer reader.Close() - return ioutil.ReadAll(reader) + return io.ReadAll(reader) } func deleteFile(client *storage.Client, bucketName, fileName string) error {