From 417e60a0ea5b4e58dc4a576b433814b745d93c70 Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Fri, 14 Jun 2024 20:16:36 +0200 Subject: [PATCH] lint: drop ioutil to fix linting errors --- e2e/_suites/fleet/system_integration.go | 3 +-- .../kubernetes-autodiscover/autodiscover_test.go | 3 +-- internal/config/config.go | 3 +-- internal/curl/curl.go | 3 +-- internal/deploy/docker_client.go | 9 ++++----- internal/io/io.go | 16 ++++++++-------- internal/kibana/client.go | 4 ++-- internal/kubernetes/kubernetes.go | 3 +-- pkg/downloads/versions_test.go | 7 +++---- 9 files changed, 22 insertions(+), 29 deletions(-) diff --git a/e2e/_suites/fleet/system_integration.go b/e2e/_suites/fleet/system_integration.go index 493c95f6ee..16ddb50566 100644 --- a/e2e/_suites/fleet/system_integration.go +++ b/e2e/_suites/fleet/system_integration.go @@ -7,7 +7,6 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "time" @@ -222,7 +221,7 @@ func readJSONFile(file string) (*gabs.Container, error) { }).Info("Successfully Opened " + file) defer jsonFile.Close() - data, err := ioutil.ReadAll(jsonFile) + data, err := os.ReadAll(jsonFile) if err != nil { return nil, err } diff --git a/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go b/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go index 7da12e3657..a1c05d5e48 100644 --- a/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go +++ b/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go @@ -10,7 +10,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -349,7 +348,7 @@ func (m *podsManager) waitForEventsCondition(podName string, conditionFn func(ct return fmt.Errorf("failed to get pod name: %w", err) } - tmpDir, err := ioutil.TempDir(os.TempDir(), "test-") + tmpDir, err := os.MkdirTemp(os.TempDir(), "test-") if err != nil { return fmt.Errorf("failed to create temporary directory: %w", err) } diff --git a/internal/config/config.go b/internal/config/config.go index 7772c06869..0064d5ac2f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -6,7 +6,6 @@ package config import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -287,7 +286,7 @@ func extractProfileServiceConfig(op *OpConfig, box *packr.Box) error { "dir": dir, }).Trace("Extracting boxed file") - return ioutil.WriteFile(p, []byte(file.String()), 0644) + return os.WriteFile(p, []byte(file.String()), 0644) } if err := box.Walk(walkFn); err != nil { diff --git a/internal/curl/curl.go b/internal/curl/curl.go index 689a911911..d80fcf6709 100644 --- a/internal/curl/curl.go +++ b/internal/curl/curl.go @@ -8,7 +8,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net/http" "net/url" @@ -126,7 +125,7 @@ func request(r HTTPRequest) (string, error) { } defer resp.Body.Close() - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { log.WithFields(log.Fields{ "error": err, diff --git a/internal/deploy/docker_client.go b/internal/deploy/docker_client.go index 6e5cda8f73..003900a70b 100644 --- a/internal/deploy/docker_client.go +++ b/internal/deploy/docker_client.go @@ -14,7 +14,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -63,7 +62,7 @@ func buildTarForDeployment(file *os.File) (bytes.Buffer, error) { return bytes.Buffer{}, fmt.Errorf("could not build TAR header: %v", err) } - b, err := ioutil.ReadFile(file.Name()) + b, err := os.ReadFile(file.Name()) if err != nil { return bytes.Buffer{}, err } @@ -128,7 +127,7 @@ func CopyFileToContainer(ctx context.Context, containerName string, srcPath stri } } else { writer := bufio.NewWriter(&buffer) - b, err := ioutil.ReadFile(file.Name()) + b, err := os.ReadFile(file.Name()) if err != nil { return err } @@ -249,7 +248,7 @@ func ExecCommandIntoContainerWithEnv(ctx context.Context, container string, user return "", ctx.Err() } - stdout, err := ioutil.ReadAll(&outBuf) + stdout, err := io.ReadAll(&outBuf) if err != nil { log.WithFields(log.Fields{ "container": containerName, @@ -261,7 +260,7 @@ func ExecCommandIntoContainerWithEnv(ctx context.Context, container string, user }).Error("Could not parse stdout from container") return "", err } - stderr, err := ioutil.ReadAll(&errBuf) + stderr, err := io.ReadAll(&errBuf) if err != nil { log.WithFields(log.Fields{ "container": containerName, diff --git a/internal/io/io.go b/internal/io/io.go index ce8fb4854c..18de4ef304 100644 --- a/internal/io/io.go +++ b/internal/io/io.go @@ -7,7 +7,7 @@ package io import ( "errors" "io" - "io/ioutil" + "io/fs" "os" "path/filepath" @@ -40,7 +40,7 @@ func CopyDir(src string, dst string) error { return err } - entries, err := ioutil.ReadDir(src) + entries, err := os.ReadDir(src) if err != nil { return err } @@ -56,7 +56,7 @@ func CopyDir(src string, dst string) error { } } else { // Skip symlinks. - if entry.Mode()&os.ModeSymlink != 0 { + if entry.Type()&os.ModeSymlink != 0 { continue } @@ -166,13 +166,13 @@ func FindFiles(pattern string) []string { } // ReadDir lists the contents of a directory -func ReadDir(path string) ([]os.FileInfo, error) { - files, err := ioutil.ReadDir(path) +func ReadDir(path string) ([]fs.DirEntry, error) { + files, err := os.ReadDir(path) if err != nil { log.WithFields(log.Fields{ "path": path, }).Warn("Could not read file system") - return []os.FileInfo{}, err + return []fs.DirEntry{}, err } return files, nil @@ -180,7 +180,7 @@ func ReadDir(path string) ([]os.FileInfo, error) { // ReadFile returns the byte array representing a file func ReadFile(path string) ([]byte, error) { - bytes, err := ioutil.ReadFile(path) + bytes, err := os.ReadFile(path) if err != nil { log.WithFields(log.Fields{ "path": path, @@ -193,7 +193,7 @@ func ReadFile(path string) ([]byte, error) { // WriteFile writes bytes into target func WriteFile(bytes []byte, target string) error { - err := ioutil.WriteFile(target, bytes, 0755) + err := os.WriteFile(target, bytes, 0755) if err != nil { log.WithFields(log.Fields{ "target": target, diff --git a/internal/kibana/client.go b/internal/kibana/client.go index c4d78251e8..39ea9a2e02 100644 --- a/internal/kibana/client.go +++ b/internal/kibana/client.go @@ -8,7 +8,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "net/http" "net/url" @@ -113,7 +113,7 @@ func (c *Client) sendRequest(ctx context.Context, method, resourcePath string, b } defer resp.Body.Close() - body, err = ioutil.ReadAll(resp.Body) + body, err = io.ReadAll(resp.Body) if err != nil { return resp.StatusCode, nil, errors.Wrap(err, "could not read response body") } diff --git a/internal/kubernetes/kubernetes.go b/internal/kubernetes/kubernetes.go index e4ed43706b..0eb68a8363 100644 --- a/internal/kubernetes/kubernetes.go +++ b/internal/kubernetes/kubernetes.go @@ -8,7 +8,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -159,7 +158,7 @@ func (c *Cluster) Initialize(ctx context.Context, kindConfigPath string) error { } log.Infof("Using %s", kindVersion) - c.tmpDir, err = ioutil.TempDir(os.TempDir(), "test-") + c.tmpDir, err = os.MkdirTemp(os.TempDir(), "test-") if err != nil { log.WithError(err).Fatal("Failed to create temporary directory") } diff --git a/pkg/downloads/versions_test.go b/pkg/downloads/versions_test.go index 396b3ae0f6..1d3dbf9f04 100644 --- a/pkg/downloads/versions_test.go +++ b/pkg/downloads/versions_test.go @@ -6,7 +6,6 @@ package downloads import ( "context" - "io/ioutil" "os" "path" "testing" @@ -32,19 +31,19 @@ var commitsJSON *gabs.Container var snapshotsJSON *gabs.Container func init() { - nextTokenParamContent, err := ioutil.ReadFile(path.Join(testResourcesBasePath, "gcp", "nextPageParam.json")) + nextTokenParamContent, err := os.ReadFile(path.Join(testResourcesBasePath, "gcp", "nextPageParam.json")) if err != nil { os.Exit(1) } nextTokenParamJSON, _ = gabs.ParseJSON([]byte(nextTokenParamContent)) - commitsContent, err := ioutil.ReadFile(path.Join(testResourcesBasePath, "gcp", "commits.json")) + commitsContent, err := os.ReadFile(path.Join(testResourcesBasePath, "gcp", "commits.json")) if err != nil { os.Exit(1) } commitsJSON, _ = gabs.ParseJSON([]byte(commitsContent)) - snapshotsContent, err := ioutil.ReadFile(path.Join(testResourcesBasePath, "gcp", "snapshots.json")) + snapshotsContent, err := os.ReadFile(path.Join(testResourcesBasePath, "gcp", "snapshots.json")) if err != nil { os.Exit(1) }