Skip to content

Commit

Permalink
chore: remove deprecated functions/methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hhsnopek committed Nov 8, 2022
1 parent 09e49a6 commit 7dcdb92
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 58 deletions.
3 changes: 1 addition & 2 deletions compose_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -220,7 +219,7 @@ func (dc *LocalDockerCompose) validate() error {
for _, abs := range dc.absComposeFilePaths {
c := compose{}

yamlFile, err := ioutil.ReadFile(abs)
yamlFile, err := os.ReadFile(abs)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -356,7 +355,7 @@ func Test_GetLogsFromFailedContainer(t *testing.T) {
t.Fatal(logErr)
}

b, err := ioutil.ReadAll(logs)
b, err := io.ReadAll(logs)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"os/exec"
Expand Down Expand Up @@ -542,7 +541,7 @@ func (c *DockerContainer) CopyFileToContainer(ctx context.Context, hostFilePath
return c.CopyDirToContainer(ctx, hostFilePath, containerFilePath, fileMode)
}

fileContent, err := ioutil.ReadFile(hostFilePath)
fileContent, err := os.ReadFile(hostFilePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -1225,7 +1224,7 @@ func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pul
defer pull.Close()

// download of docker image finishes at EOF of the pull request
_, err = ioutil.ReadAll(pull)
_, err = io.ReadAll(pull)
return err
}

Expand Down
50 changes: 24 additions & 26 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

// Import mysql into the scope of this package (required)
"io"
"io/ioutil"
"math/rand"
"net/http"
"os"
Expand All @@ -26,7 +25,6 @@ import (
"github.com/go-redis/redis/v8"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gotest.tools/v3/env"
"gotest.tools/v3/fs"

"github.com/docker/docker/errdefs"
Expand Down Expand Up @@ -1163,7 +1161,7 @@ func prepareLocalRegistryWithAuth(t *testing.T) {
assert.NoError(t, registryC.Terminate(context.Background()))
})

ctx, cancel := context.WithCancel(context.Background())
_, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
}

Expand Down Expand Up @@ -1249,7 +1247,7 @@ func Test_BuildContainerFromDockerfileWithBuildArgs(t *testing.T) {
t.Fatal(err)
}

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1287,7 +1285,7 @@ func Test_BuildContainerFromDockerfileWithBuildLog(t *testing.T) {
terminateContainerOnEnd(t, ctx, c)

_ = w.Close()
out, _ := ioutil.ReadAll(r)
out, _ := io.ReadAll(r)
os.Stdout = rescueStdout
temp := strings.Split(string(out), "\n")

Expand Down Expand Up @@ -1455,16 +1453,16 @@ func TestEntrypoint(t *testing.T) {

func TestReadTCPropsFile(t *testing.T) {
t.Run("HOME is not set", func(t *testing.T) {
env.Patch(t, "HOME", "")
t.Setenv("HOME", "")

config := configureTC()

assert.Empty(t, config, "TC props file should not exist")
})

t.Run("HOME is not set - TESTCONTAINERS_ env is set", func(t *testing.T) {
env.Patch(t, "HOME", "")
env.Patch(t, "TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "true")
t.Setenv("HOME", "")
t.Setenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "true")

config := configureTC()

Expand All @@ -1476,7 +1474,7 @@ func TestReadTCPropsFile(t *testing.T) {

t.Run("HOME does not contain TC props file", func(t *testing.T) {
tmpDir := fs.NewDir(t, os.TempDir())
env.Patch(t, "HOME", tmpDir.Path())
t.Setenv("HOME", tmpDir.Path())

config := configureTC()

Expand All @@ -1485,8 +1483,8 @@ func TestReadTCPropsFile(t *testing.T) {

t.Run("HOME does not contain TC props file - TESTCONTAINERS_ env is set", func(t *testing.T) {
tmpDir := fs.NewDir(t, os.TempDir())
env.Patch(t, "HOME", tmpDir.Path())
env.Patch(t, "TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "true")
t.Setenv("HOME", tmpDir.Path())
t.Setenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "true")

config := configureTC()
expected := TestContainersConfig{}
Expand Down Expand Up @@ -1692,11 +1690,11 @@ func TestReadTCPropsFile(t *testing.T) {
for i, tt := range tests {
t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) {
tmpDir := fs.NewDir(t, os.TempDir())
env.Patch(t, "HOME", tmpDir.Path())
t.Setenv("HOME", tmpDir.Path())
for k, v := range tt.env {
env.Patch(t, k, v)
t.Setenv(k, v)
}
if err := ioutil.WriteFile(tmpDir.Join(".testcontainers.properties"), []byte(tt.content), 0o600); err != nil {
if err := os.WriteFile(tmpDir.Join(".testcontainers.properties"), []byte(tt.content), 0o600); err != nil {
t.Errorf("Failed to create the file: %v", err)
return
}
Expand Down Expand Up @@ -1800,7 +1798,7 @@ func TestContainerCreationWithBindAndVolume(t *testing.T) {
}

// Create the volume.
vol, err := dockerCli.VolumeCreate(ctx, volume.VolumeCreateBody{
vol, err := dockerCli.VolumeCreate(ctx, volume.CreateOptions{
Driver: "local",
})
if err != nil {
Expand Down Expand Up @@ -2112,13 +2110,13 @@ func TestDockerCreateContainerWithFiles(t *testing.T) {
for _, f := range tc.files {
require.NoError(t, err)

hostFileData, err := ioutil.ReadFile(f.HostFilePath)
hostFileData, err := os.ReadFile(f.HostFilePath)
require.NoError(t, err)

fd, err := nginxC.CopyFileFromContainer(ctx, f.ContainerFilePath)
require.NoError(t, err)
defer fd.Close()
containerFileData, err := ioutil.ReadAll(fd)
containerFileData, err := io.ReadAll(fd)
require.NoError(t, err)

require.Equal(t, hostFileData, containerFileData)
Expand Down Expand Up @@ -2206,7 +2204,7 @@ func TestDockerContainerCopyToContainer(t *testing.T) {

copiedFileName := "hello_copy.sh"

fileContent, err := ioutil.ReadFile("./testresources/hello.sh")
fileContent, err := os.ReadFile("./testresources/hello.sh")
if err != nil {
t.Fatal(err)
}
Expand All @@ -2221,7 +2219,7 @@ func TestDockerContainerCopyToContainer(t *testing.T) {
}

func TestDockerContainerCopyFileFromContainer(t *testing.T) {
fileContent, err := ioutil.ReadFile("./testresources/hello.sh")
fileContent, err := os.ReadFile("./testresources/hello.sh")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2255,7 +2253,7 @@ func TestDockerContainerCopyFileFromContainer(t *testing.T) {
t.Fatal(err)
}

fileContentFromContainer, err := ioutil.ReadAll(reader)
fileContentFromContainer, err := io.ReadAll(reader)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2293,7 +2291,7 @@ func TestDockerContainerCopyEmptyFileFromContainer(t *testing.T) {
t.Fatal(err)
}

fileContentFromContainer, err := ioutil.ReadAll(reader)
fileContentFromContainer, err := io.ReadAll(reader)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2477,7 +2475,7 @@ func TestContainerWithUserID(t *testing.T) {
t.Fatal(err)
}
defer r.Close()
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2506,7 +2504,7 @@ func TestContainerWithNoUserID(t *testing.T) {
t.Fatal(err)
}
defer r.Close()
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2572,14 +2570,14 @@ func assertExtractedFiles(t *testing.T, ctx context.Context, container Container
tmpDir := filepath.Join(t.TempDir())

// compare the bytes of each file in the source with the bytes from the copied-from-container file
srcFiles, err := ioutil.ReadDir(hostFilePath)
srcFiles, err := os.ReadDir(hostFilePath)
require.NoError(t, err)

for _, srcFile := range srcFiles {
if srcFile.IsDir() {
continue
}
srcBytes, err := ioutil.ReadFile(filepath.Join(hostFilePath, srcFile.Name()))
srcBytes, err := os.ReadFile(filepath.Join(hostFilePath, srcFile.Name()))
if err != nil {
require.NoError(t, err)
}
Expand All @@ -2602,7 +2600,7 @@ func assertExtractedFiles(t *testing.T, ctx context.Context, container Container
require.NoError(t, err)
}

untarBytes, err := ioutil.ReadFile(targetPath)
untarBytes, err := os.ReadFile(targetPath)
if err != nil {
require.NoError(t, err)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/features/wait/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ req := testcontainers.ContainerRequest{
WaitingFor: wait.NewHTTPStrategy("/ping").
WithStartupTimeout(time.Second * 10).WithPort("80/tcp").
WithResponseMatcher(func(body io.Reader) bool {
data, _ := ioutil.ReadAll(body)
data, _ := io.ReadAll(body)
return bytes.Equal(data, []byte("pong"))
}).
WithStatusCodeMatcher(func(status int) bool {
Expand Down
11 changes: 5 additions & 6 deletions file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -67,7 +66,7 @@ func Test_TarDir(t *testing.T) {
t.Fatal(err)
}

srcFiles, err := ioutil.ReadDir(src)
srcFiles, err := os.ReadDir(src)
if err != nil {
log.Fatal(err)
}
Expand All @@ -76,12 +75,12 @@ func Test_TarDir(t *testing.T) {
if srcFile.IsDir() {
continue
}
srcBytes, err := ioutil.ReadFile(filepath.Join(src, srcFile.Name()))
srcBytes, err := os.ReadFile(filepath.Join(src, srcFile.Name()))
if err != nil {
t.Fatal(err)
}

untarBytes, err := ioutil.ReadFile(filepath.Join(tmpDir, "testresources", srcFile.Name()))
untarBytes, err := os.ReadFile(filepath.Join(tmpDir, "testresources", srcFile.Name()))
if err != nil {
t.Fatal(err)
}
Expand All @@ -90,7 +89,7 @@ func Test_TarDir(t *testing.T) {
}

func Test_TarFile(t *testing.T) {
b, err := ioutil.ReadFile(filepath.Join(".", "testresources", "Dockerfile"))
b, err := os.ReadFile(filepath.Join(".", "testresources", "Dockerfile"))
if err != nil {
t.Fatal(err)
}
Expand All @@ -106,7 +105,7 @@ func Test_TarFile(t *testing.T) {
t.Fatal(err)
}

untarBytes, err := ioutil.ReadFile(filepath.Join(tmpDir, "Docker.file"))
untarBytes, err := os.ReadFile(filepath.Join(tmpDir, "Docker.file"))
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions logconsumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -326,7 +326,7 @@ func TestContainerLogsShouldBeWithoutStreamHeader(t *testing.T) {
t.Fatal(err)
}
defer r.Close()
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions wait/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"strconv"
Expand Down Expand Up @@ -189,7 +188,7 @@ func (ws *HTTPStrategy) WaitUntilReady(ctx context.Context, target StrategyTarge
// cache the body into a byte-slice so that it can be iterated over multiple times
var body []byte
if ws.Body != nil {
body, err = ioutil.ReadAll(ws.Body)
body, err = io.ReadAll(ws.Body)
if err != nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions wait/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"crypto/x509"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -48,7 +47,7 @@ func TestHTTPStrategyWaitUntilReady(t *testing.T) {
}

capath := workdir + "/testdata/root.pem"
cafile, err := ioutil.ReadFile(capath)
cafile, err := os.ReadFile(capath)
if err != nil {
t.Errorf("can't load ca file: %v", err)
return
Expand All @@ -70,7 +69,7 @@ func TestHTTPStrategyWaitUntilReady(t *testing.T) {
WaitingFor: wait.NewHTTPStrategy("/ping").WithTLS(true, tlsconfig).
WithStartupTimeout(time.Second * 10).WithPort("6443/tcp").
WithResponseMatcher(func(body io.Reader) bool {
data, _ := ioutil.ReadAll(body)
data, _ := io.ReadAll(body)
return bytes.Equal(data, []byte("pong"))
}).
WithStatusCodeMatcher(func(status int) bool {
Expand Down

0 comments on commit 7dcdb92

Please sign in to comment.