Skip to content

chore: remove refs to deprecated io/ioutil #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions internal/context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package context

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

Expand Down Expand Up @@ -74,7 +73,7 @@ func TestGetCurrentContainerID(t *testing.T) {
var filepaths []string
// Create temporary files with test content
for _, key := range fileKeys {
file, err := ioutil.TempFile("", key)
file, err := os.CreateTemp("", key)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -114,7 +113,7 @@ func TestGetCurrentContainerIDMountInfo(t *testing.T) {
var filepaths []string
// Create temporary files with test content
for _, key := range fileKeys {
file, err := ioutil.TempFile("", key)
file, err := os.CreateTemp("", key)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/dockerclient/docker_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dockerclient

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

Expand Down Expand Up @@ -236,7 +235,7 @@ func TestTlsEnabled(t *testing.T) {
}
// Create temporary files
for key := range filepaths {
file, err := ioutil.TempFile("", key)
file, err := os.CreateTemp("", key)
if err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand All @@ -21,7 +21,7 @@ import (
)

func TestGenerateFromEvents(t *testing.T) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
containerID := "8dfafdbc3a40"
var counter atomic.Int32

Expand Down Expand Up @@ -112,22 +112,22 @@ func TestGenerateFromEvents(t *testing.T) {
}
client.SkipServerVersionCheck = true

tmplFile, err := ioutil.TempFile(os.TempDir(), "docker-gen-tmpl")
tmplFile, err := os.CreateTemp(os.TempDir(), "docker-gen-tmpl")
if err != nil {
t.Errorf("Failed to create temp file: %v\n", err)
}
defer func() {
tmplFile.Close()
os.Remove(tmplFile.Name())
}()
err = ioutil.WriteFile(tmplFile.Name(), []byte("{{range $key, $value := .}}{{$value.ID}}.{{$value.Env.COUNTER}}{{end}}"), 0644)
err = os.WriteFile(tmplFile.Name(), []byte("{{range $key, $value := .}}{{$value.ID}}.{{$value.Env.COUNTER}}{{end}}"), 0644)
if err != nil {
t.Errorf("Failed to write to temp file: %v\n", err)
}

var destFiles []*os.File
for i := 0; i < 4; i++ {
destFile, err := ioutil.TempFile(os.TempDir(), "docker-gen-out")
destFile, err := os.CreateTemp(os.TempDir(), "docker-gen-out")
if err != nil {
t.Errorf("Failed to create temp file: %v\n", err)
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestGenerateFromEvents(t *testing.T) {
expectedCounters := []int{1, 5, 6, 7}

for i, counter := range expectedCounters {
value, _ = ioutil.ReadFile(destFiles[i].Name())
value, _ = os.ReadFile(destFiles[i].Name())
expected = fmt.Sprintf("%s.%d", containerID, counter)
if string(value) != expected {
t.Errorf("expected: %s. got: %s", expected, value)
Expand Down
4 changes: 2 additions & 2 deletions internal/template/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"reflect"
"strings"
)
Expand Down Expand Up @@ -104,7 +104,7 @@ func arrayClosest(values []string, input string) string {
// dirList returns a list of files in the specified path
func dirList(path string) ([]string, error) {
names := []string{}
files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
log.Printf("Template error: %v", err)
return names, nil
Expand Down
5 changes: 2 additions & 3 deletions internal/template/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package template
import (
"bytes"
"encoding/json"
"io/ioutil"
"os"
"path"
"reflect"
Expand Down Expand Up @@ -258,7 +257,7 @@ func TestWhenFalse(t *testing.T) {
}

func TestDirList(t *testing.T) {
dir, err := ioutil.TempDir("", "dirList")
dir, err := os.MkdirTemp("", "dirList")
if err != nil {
t.Fatal(err)
}
Expand All @@ -271,7 +270,7 @@ func TestDirList(t *testing.T) {
}
// Create temporary files
for key := range files {
file, err := ioutil.TempFile(dir, key)
file, err := os.CreateTemp(dir, key)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -172,7 +171,7 @@ func GenerateFile(config config.Config, containers context.Context) bool {
}

if config.Dest != "" {
dest, err := ioutil.TempFile(filepath.Dir(config.Dest), "docker-gen")
dest, err := os.CreateTemp(filepath.Dir(config.Dest), "docker-gen")
defer func() {
dest.Close()
os.Remove(dest.Name())
Expand Down Expand Up @@ -202,7 +201,7 @@ func GenerateFile(config config.Config, containers context.Context) bool {
if err := dest.Chown(int(fi.Sys().(*syscall.Stat_t).Uid), int(fi.Sys().(*syscall.Stat_t).Gid)); err != nil {
log.Fatalf("Unable to chown temp file: %s\n", err)
}
oldContents, err = ioutil.ReadFile(config.Dest)
oldContents, err = os.ReadFile(config.Dest)
if err != nil {
log.Fatalf("Unable to compare current file contents: %s: %s\n", config.Dest, err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package utils

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

Expand Down Expand Up @@ -29,7 +28,7 @@ func TestSplitKeyValueSlice(t *testing.T) {
}

func TestPathExists(t *testing.T) {
file, err := ioutil.TempFile("", "test")
file, err := os.CreateTemp("", "test")
if err != nil {
t.Fatal(err)
}
Expand Down