Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
lint: drop ioutil to fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kruskall committed Jun 14, 2024
1 parent 5bc73d1 commit 417e60a
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 29 deletions.
3 changes: 1 addition & 2 deletions e2e/_suites/fleet/system_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions e2e/_suites/kubernetes-autodiscover/autodiscover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/curl/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions internal/deploy/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions internal/io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package io
import (
"errors"
"io"
"io/ioutil"
"io/fs"
"os"
"path/filepath"

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -166,21 +166,21 @@ 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
}

// 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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions internal/kibana/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"

Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 1 addition & 2 deletions internal/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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")
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/downloads/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package downloads

import (
"context"
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -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)
}
Expand Down

0 comments on commit 417e60a

Please sign in to comment.