Skip to content

Commit

Permalink
fix: replace deprecated ioutil calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bhamail committed Sep 8, 2022
1 parent 80ae98e commit e457c55
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
11 changes: 5 additions & 6 deletions internal/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -229,7 +228,7 @@ func createFakeStdIn(t *testing.T) (oldStdIn *os.File, tmpFile *os.File) {
}
func createFakeStdInWithString(t *testing.T, inputString string) (oldStdIn *os.File, tmpFile *os.File) {
content := []byte(inputString)
tmpFile, err := ioutil.TempFile("", "tempfile")
tmpFile, err := os.CreateTemp("", "tempfile")
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -322,7 +321,7 @@ func TestConfigOssi_skip_update_check(t *testing.T) {
}

func setupConfig(t *testing.T) (tempDir string) {
tempDir, err := ioutil.TempDir("", "config-test")
tempDir, err := os.MkdirTemp("", "config-test")
assert.NoError(t, err)
return tempDir
}
Expand Down Expand Up @@ -387,7 +386,7 @@ func setupTestOSSIConfigFileValues(t *testing.T, tempDir string) {

const credentials = configuration.ViperKeyUsername + ": ossiUsernameValue\n" +
configuration.ViperKeyToken + ": ossiTokenValue"
assert.Nil(t, ioutil.WriteFile(cfgFile, []byte(credentials), 0644))
assert.Nil(t, os.WriteFile(cfgFile, []byte(credentials), 0644))
}

type ossiFactoryMock struct {
Expand All @@ -403,12 +402,12 @@ type mockOssiServer struct {
auditPackagesErr error
}

//noinspection GoUnusedParameter
// noinspection GoUnusedParameter
func (s mockOssiServer) AuditPackages(purls []string) ([]ossIndexTypes.Coordinate, error) {
return s.auditPackagesResults, s.auditPackagesErr
}

//noinspection GoUnusedParameter
// noinspection GoUnusedParameter
func (s mockOssiServer) Audit(purls []string) (results map[string]ossIndexTypes.Coordinate, err error) {
results = make(map[string]ossIndexTypes.Coordinate)

Expand Down
5 changes: 2 additions & 3 deletions internal/cmd/sleuth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/sonatype-nexus-community/nancy/internal/customerrors"
"github.com/sonatype-nexus-community/nancy/types"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -102,7 +101,7 @@ func TestConfigOssi_exclude_vulnerabilities_file_not_found_does_not_matter(t *te
}

func TestConfigOssi_exclude_vulnerabilities_passed_as_directory_does_not_matter(t *testing.T) {
dir, _ := ioutil.TempDir("", "prefix")
dir, _ := os.MkdirTemp("", "prefix")
validateConfigOssi(t, types.Configuration{CveList: types.CveListFlag{}, Formatter: defaultAuditLogFormatter},
[]string{sleuthCmd.Use, "--exclude-vulnerability-file=" + dir}...)
}
Expand Down Expand Up @@ -131,7 +130,7 @@ func TestConfigOssi_additional_exclude_vulnerabilities_with_empty_additional(t *

func TestConfigOssi_exclude_vulnerabilities_does_not_need_to_be_passed_if_default_value_is_used(t *testing.T) {
defaultFileName := ".nancy-ignore"
err := ioutil.WriteFile(defaultFileName, []byte("DEF-111\nDEF-222"), 0644)
err := os.WriteFile(defaultFileName, []byte("DEF-111\nDEF-222"), 0644)
if err != nil {
t.Fatal(err)
}
Expand Down
11 changes: 5 additions & 6 deletions packages/dep_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/Flaque/filet"
"github.com/golang/dep"
"github.com/stretchr/testify/require"
"io/ioutil"
"log"
"os"
"testing"
Expand Down Expand Up @@ -84,25 +83,25 @@ func doGoPathSimulatedSetup(t *testing.T) (string, string, error) {
if e != nil {
t.Error(e)
}
lockBytes, e := ioutil.ReadFile("testdata/Gopkg.lock")
lockBytes, e := os.ReadFile("testdata/Gopkg.lock")
if e != nil {
t.Error(e)
}
e = ioutil.WriteFile(fmt.Sprint(projectDir, "/Gopkg.lock"), lockBytes, 0644)
e = os.WriteFile(fmt.Sprint(projectDir, "/Gopkg.lock"), lockBytes, 0644)
if e != nil {
t.Error(e)
}

tomlBytes, e := ioutil.ReadFile("testdata/Gopkg.toml")
tomlBytes, e := os.ReadFile("testdata/Gopkg.toml")
if e != nil {
t.Error(e)
}
e = ioutil.WriteFile(fmt.Sprint(projectDir, "/Gopkg.toml"), tomlBytes, 0644)
e = os.WriteFile(fmt.Sprint(projectDir, "/Gopkg.toml"), tomlBytes, 0644)
if e != nil {
t.Error(e)
}

files, e := ioutil.ReadDir(projectDir)
files, e := os.ReadDir(projectDir)
if e != nil {
t.Error(e)
}
Expand Down
3 changes: 1 addition & 2 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bufio"
"encoding/json"
"io"
"io/ioutil"
"strings"

"github.com/sonatype-nexus-community/nancy/types"
Expand All @@ -46,7 +45,7 @@ func GoList(stdIn *bufio.Scanner) (deps types.ProjectList, err error) {
func GoListAgnostic(stdIn io.Reader) (deps types.ProjectList, err error) {
// stdIn should never be massive, so taking this approach over reading from a stream
// multiple times
johnnyFiveNeedInput, err := ioutil.ReadAll(stdIn)
johnnyFiveNeedInput, err := io.ReadAll(stdIn)
if err != nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions settings/appsettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package settings
import (
ossIndexTypes "github.com/sonatype-nexus-community/go-sona-types/ossindex/types"
"gopkg.in/yaml.v3"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand All @@ -39,7 +38,7 @@ func (upd *UpdateCheck) WriteToDisk() error {
return err
}

err = ioutil.WriteFile(upd.FileUsed, enc, 0600)
err = os.WriteFile(upd.FileUsed, enc, 0600)
return err
}

Expand All @@ -53,7 +52,7 @@ func (upd *UpdateCheck) Load() error {

upd.FileUsed = appSettingsPath

content, err := ioutil.ReadFile(appSettingsPath) // #nosec
content, err := os.ReadFile(appSettingsPath) // #nosec
if err != nil {
return err
}
Expand Down

0 comments on commit e457c55

Please sign in to comment.