Skip to content

Commit

Permalink
Update golang syntax to pass linter
Browse files Browse the repository at this point in the history
Syntax was deprecated by golang

Signed-off-by: Dave Riddle <driddle@vmware.com>
  • Loading branch information
joyvuu-dave committed Nov 18, 2022
1 parent b466ac4 commit 1c714dd
Show file tree
Hide file tree
Showing 41 changed files with 110 additions and 133 deletions.
3 changes: 1 addition & 2 deletions cmd/sonobuoy/app/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package app

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

Expand Down Expand Up @@ -213,7 +212,7 @@ func NewCmdGen() *cobra.Command {
func genManifest(genflags *genFlags) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
if len(genflags.genFile) > 0 {
b, err := ioutil.ReadFile(genflags.genFile)
b, err := os.ReadFile(genflags.genFile)
if err != nil {
errlog.LogError(err)
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions cmd/sonobuoy/app/gen_plugin_def_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package app
import (
"bytes"
"flag"
"io/ioutil"
"os"
"testing"

"github.com/vmware-tanzu/sonobuoy/pkg/plugin/manifest"
Expand Down Expand Up @@ -143,9 +143,9 @@ func TestPluginGenDef(t *testing.T) {
}

if *update {
ioutil.WriteFile(tC.expectFile, []byte(manifest), 0666)
os.WriteFile(tC.expectFile, []byte(manifest), 0666)
} else {
fileData, err := ioutil.ReadFile(tC.expectFile)
fileData, err := os.ReadFile(tC.expectFile)
if err != nil {
t.Fatalf("Failed to read golden file %v: %v", tC.expectFile, err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/sonobuoy/app/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.
package app

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

Expand All @@ -35,7 +34,7 @@ sigStorageRegistry: test-fake-registry.corp/fake-user
`

func sampleE2eRegistryConfig() (string, error) {
configFile, err := ioutil.TempFile("", "e2eRegistryConfig.yaml")
configFile, err := os.CreateTemp("", "e2eRegistryConfig.yaml")
if err != nil {
return "", err
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/sonobuoy/app/pluginList.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package app
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -169,7 +168,7 @@ func (p *pluginList) loadPluginsFromFilesystem(str, renameAs string) error {
// into the directory. A plugin must have the '.yaml' extension to be considered.
// It returns the first error encountered and stops processing.
func (p *pluginList) loadPluginsDir(dirpath string) error {
files, err := ioutil.ReadDir(dirpath)
files, err := os.ReadDir(dirpath)
if err != nil {
return errors.Wrapf(err, "failed to read directory %q", dirpath)
}
Expand Down Expand Up @@ -213,7 +212,7 @@ func (p *pluginList) loadSinglePluginFromFile(filepath, renameAs string) error {
// loadSinglePlugin reads the data from the reader and loads the plugin.
func (p *pluginList) loadSinglePlugin(r io.ReadCloser, renameAs string) error {
defer r.Close()
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return errors.Wrap(err, "failed to read data for plugin")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/sonobuoy/app/pluginList_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package app

import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/vmware-tanzu/sonobuoy/pkg/plugin/manifest"
Expand All @@ -30,7 +30,7 @@ import (
func TestSetPluginList(t *testing.T) {
serveFile := func(filepath string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
b, err := ioutil.ReadFile(filepath)
b, err := os.ReadFile(filepath)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/sonobuoy/app/sonobuoyconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package app

import (
"encoding/json"
"io/ioutil"
"os"
"reflect"

"github.com/pkg/errors"
Expand Down Expand Up @@ -48,7 +48,7 @@ func (c *SonobuoyConfig) Set(str string) error {
return errors.New("if a custom config file is set, it must be set before other flags that modify configuration fields")
}

bytes, err := ioutil.ReadFile(str)
bytes, err := os.ReadFile(str)
if err != nil {
return errors.Wrap(err, "couldn't open config file")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/sonobuoy/app/splat.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package app
import (
"archive/tar"
"compress/gzip"
"io/ioutil"
"io"
"os"
"path/filepath"

Expand Down Expand Up @@ -96,7 +96,7 @@ func addFileToTarball(tarWriter *tar.Writer, filename string) error {
return err
}

fileContent, err := ioutil.ReadAll(file)
fileContent, err := io.ReadAll(file)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/sonobuoy/app/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package app
import (
"bytes"
"io"
"io/ioutil"
"os"
"testing"

"github.com/vmware-tanzu/sonobuoy/pkg/plugin"
Expand Down Expand Up @@ -89,9 +89,9 @@ func TestPrintStatus(t *testing.T) {
}

if *update {
ioutil.WriteFile(tc.expectFile, b.Bytes(), 0666)
os.WriteFile(tc.expectFile, b.Bytes(), 0666)
} else {
fileData, err := ioutil.ReadFile(tc.expectFile)
fileData, err := os.ReadFile(tc.expectFile)
if err != nil {
t.Fatalf("Failed to read golden file %v: %v", tc.expectFile, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/backplane/ca/ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package ca

import (
"fmt"
"io/ioutil"
"io"
"math/big"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestServer(t *testing.T) {
t.Fatalf("expected client error to be null, got %v", err)
}
defer resp.Body.Close()
respBody, err := ioutil.ReadAll(resp.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("couldn't read body: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"sort"
"strings"

Expand Down Expand Up @@ -314,7 +314,7 @@ func generateSecret(w io.Writer, cfg *GenConfig) error {
return nil
}

sshKeyData, err := ioutil.ReadFile(cfg.SSHKeyPath)
sshKeyData, err := os.ReadFile(cfg.SSHKeyPath)
if err != nil {
return errors.Wrapf(err, "unable to read SSH key file: %v", cfg.SSHKeyPath)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
Expand Down Expand Up @@ -499,9 +499,9 @@ func TestGenerateManifestGolden(t *testing.T) {
}

if *update {
ioutil.WriteFile(tc.goldenFile, manifest, 0666)
os.WriteFile(tc.goldenFile, manifest, 0666)
} else {
fileData, err := ioutil.ReadFile(tc.goldenFile)
fileData, err := os.ReadFile(tc.goldenFile)
if err != nil {
t.Fatalf("Failed to read golden file %v: %v", tc.goldenFile, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/preflight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package client
import (
"context"
"fmt"
"io/ioutil"
"io"
"strings"
"testing"

Expand All @@ -36,7 +36,7 @@ import (
func TestVersionCheck(t *testing.T) {
testHook := &testhook.Hook{}
logrus.AddHook(testHook)
logrus.SetOutput(ioutil.Discard)
logrus.SetOutput(io.Discard)

serverAtVersion := func(major, minor, git string) *fakeServerVersionInterface {
return &fakeServerVersionInterface{
Expand Down
5 changes: 2 additions & 3 deletions pkg/client/results/junit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -39,7 +38,7 @@ func TestJUnitProcessReader(t *testing.T) {
}
itemFromFile := func(t *testing.T, path string) Item {
i := Item{}
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
t.Fatalf("Failed to read test file %v: %v", path, err)
}
Expand Down Expand Up @@ -95,7 +94,7 @@ func TestJUnitProcessReader(t *testing.T) {
t.Fatalf("Failed to marshal expected Item for debug: %v", err)
}
t.Logf("Updating goldenfile %v", tc.expectItemFromFile)
ioutil.WriteFile(tc.expectItemFromFile, b, 0666)
os.WriteFile(tc.expectItemFromFile, b, 0666)
return
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/client/results/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package results
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -213,7 +212,7 @@ func PostProcessPlugin(p plugin.Interface, dir string) (Item, []error) {
func processNodesWithProcessor(p plugin.Interface, baseDir, dir string, processor postProcessor, selector fileSelector) ([]Item, error) {
pdir := path.Join(baseDir, PluginsDir, p.GetName())

nodeDirs, err := ioutil.ReadDir(dir)
nodeDirs, err := os.ReadDir(dir)
if err != nil && !os.IsNotExist(err) {
return []Item{}, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/results/processing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package results
import (
"encoding/json"
"flag"
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -218,11 +218,11 @@ func TestPostProcessPluginGolden(t *testing.T) {
if err != nil {
t.Fatalf("Failed to marshal item: %v", err)
}
ioutil.WriteFile(expectResults(tc.key), itemBytes, 0666)
os.WriteFile(expectResults(tc.key), itemBytes, 0666)
} else {
// Read in golden file and unmarshal. Easier to debug differences in the items than
// comparing the bytes directly.
fileData, err := ioutil.ReadFile(expectResults(tc.key))
fileData, err := os.ReadFile(expectResults(tc.key))
if err != nil {
t.Fatalf("Failed to read golden file %v: %v", expectResults(tc.key), err)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/client/results/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -47,7 +46,7 @@ func (v *version) String() string {

func MustGetReader(path string, t *testing.T) *results.Reader {
t.Helper()
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("Failed to read tarball data: %v", err)
}
Expand Down Expand Up @@ -345,7 +344,7 @@ func TestExtractBytes(t *testing.T) {

func ExampleNewReaderFromBytes() {
path := "testdata/results-0.8.tar.gz"
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/client/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -277,7 +276,7 @@ func tarCmd(path string) []string {
}

func drainReader(r io.Reader) error {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return errors.Wrap(err, "failed to drain the tar reader")
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/client/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"text/tabwriter"
Expand Down Expand Up @@ -228,9 +227,9 @@ func loadManifestFromFile(f string) ([]byte, error) {
return nil, fmt.Errorf("nothing on stdin to read")
}

return ioutil.ReadAll(os.Stdin)
return io.ReadAll(os.Stdin)
} else {
return ioutil.ReadFile(f)
return os.ReadFile(f)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package config
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -56,7 +56,7 @@ func LoadConfig(pathsToTry ...string) (*Config, error) {
defer jsonFile.Close()
logrus.Tracef("Loading config from file: %v", fpath)

b, err := ioutil.ReadAll(jsonFile)
b, err := io.ReadAll(jsonFile)
if err != nil {
return nil, errors.Wrapf(err, "read config file %q", fpath)
}
Expand Down
Loading

0 comments on commit 1c714dd

Please sign in to comment.