Skip to content

Commit e457c55

Browse files
committed
fix: replace deprecated ioutil calls
1 parent 80ae98e commit e457c55

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

Diff for: internal/cmd/root_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"bytes"
2121
"flag"
2222
"fmt"
23-
"io/ioutil"
2423
"os"
2524
"path"
2625
"strings"
@@ -229,7 +228,7 @@ func createFakeStdIn(t *testing.T) (oldStdIn *os.File, tmpFile *os.File) {
229228
}
230229
func createFakeStdInWithString(t *testing.T, inputString string) (oldStdIn *os.File, tmpFile *os.File) {
231230
content := []byte(inputString)
232-
tmpFile, err := ioutil.TempFile("", "tempfile")
231+
tmpFile, err := os.CreateTemp("", "tempfile")
233232
if err != nil {
234233
t.Error(err)
235234
}
@@ -322,7 +321,7 @@ func TestConfigOssi_skip_update_check(t *testing.T) {
322321
}
323322

324323
func setupConfig(t *testing.T) (tempDir string) {
325-
tempDir, err := ioutil.TempDir("", "config-test")
324+
tempDir, err := os.MkdirTemp("", "config-test")
326325
assert.NoError(t, err)
327326
return tempDir
328327
}
@@ -387,7 +386,7 @@ func setupTestOSSIConfigFileValues(t *testing.T, tempDir string) {
387386

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

393392
type ossiFactoryMock struct {
@@ -403,12 +402,12 @@ type mockOssiServer struct {
403402
auditPackagesErr error
404403
}
405404

406-
//noinspection GoUnusedParameter
405+
// noinspection GoUnusedParameter
407406
func (s mockOssiServer) AuditPackages(purls []string) ([]ossIndexTypes.Coordinate, error) {
408407
return s.auditPackagesResults, s.auditPackagesErr
409408
}
410409

411-
//noinspection GoUnusedParameter
410+
// noinspection GoUnusedParameter
412411
func (s mockOssiServer) Audit(purls []string) (results map[string]ossIndexTypes.Coordinate, err error) {
413412
results = make(map[string]ossIndexTypes.Coordinate)
414413

Diff for: internal/cmd/sleuth_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/sonatype-nexus-community/nancy/internal/customerrors"
2626
"github.com/sonatype-nexus-community/nancy/types"
2727
"github.com/stretchr/testify/assert"
28-
"io/ioutil"
2928
"os"
3029
"strings"
3130
"testing"
@@ -102,7 +101,7 @@ func TestConfigOssi_exclude_vulnerabilities_file_not_found_does_not_matter(t *te
102101
}
103102

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

132131
func TestConfigOssi_exclude_vulnerabilities_does_not_need_to_be_passed_if_default_value_is_used(t *testing.T) {
133132
defaultFileName := ".nancy-ignore"
134-
err := ioutil.WriteFile(defaultFileName, []byte("DEF-111\nDEF-222"), 0644)
133+
err := os.WriteFile(defaultFileName, []byte("DEF-111\nDEF-222"), 0644)
135134
if err != nil {
136135
t.Fatal(err)
137136
}

Diff for: packages/dep_int_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/Flaque/filet"
2222
"github.com/golang/dep"
2323
"github.com/stretchr/testify/require"
24-
"io/ioutil"
2524
"log"
2625
"os"
2726
"testing"
@@ -84,25 +83,25 @@ func doGoPathSimulatedSetup(t *testing.T) (string, string, error) {
8483
if e != nil {
8584
t.Error(e)
8685
}
87-
lockBytes, e := ioutil.ReadFile("testdata/Gopkg.lock")
86+
lockBytes, e := os.ReadFile("testdata/Gopkg.lock")
8887
if e != nil {
8988
t.Error(e)
9089
}
91-
e = ioutil.WriteFile(fmt.Sprint(projectDir, "/Gopkg.lock"), lockBytes, 0644)
90+
e = os.WriteFile(fmt.Sprint(projectDir, "/Gopkg.lock"), lockBytes, 0644)
9291
if e != nil {
9392
t.Error(e)
9493
}
9594

96-
tomlBytes, e := ioutil.ReadFile("testdata/Gopkg.toml")
95+
tomlBytes, e := os.ReadFile("testdata/Gopkg.toml")
9796
if e != nil {
9897
t.Error(e)
9998
}
100-
e = ioutil.WriteFile(fmt.Sprint(projectDir, "/Gopkg.toml"), tomlBytes, 0644)
99+
e = os.WriteFile(fmt.Sprint(projectDir, "/Gopkg.toml"), tomlBytes, 0644)
101100
if e != nil {
102101
t.Error(e)
103102
}
104103

105-
files, e := ioutil.ReadDir(projectDir)
104+
files, e := os.ReadDir(projectDir)
106105
if e != nil {
107106
t.Error(e)
108107
}

Diff for: parse/parse.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"bufio"
2121
"encoding/json"
2222
"io"
23-
"io/ioutil"
2423
"strings"
2524

2625
"github.com/sonatype-nexus-community/nancy/types"
@@ -46,7 +45,7 @@ func GoList(stdIn *bufio.Scanner) (deps types.ProjectList, err error) {
4645
func GoListAgnostic(stdIn io.Reader) (deps types.ProjectList, err error) {
4746
// stdIn should never be massive, so taking this approach over reading from a stream
4847
// multiple times
49-
johnnyFiveNeedInput, err := ioutil.ReadAll(stdIn)
48+
johnnyFiveNeedInput, err := io.ReadAll(stdIn)
5049
if err != nil {
5150
return
5251
}

Diff for: settings/appsettings.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package settings
1919
import (
2020
ossIndexTypes "github.com/sonatype-nexus-community/go-sona-types/ossindex/types"
2121
"gopkg.in/yaml.v3"
22-
"io/ioutil"
2322
"os"
2423
"path"
2524
"path/filepath"
@@ -39,7 +38,7 @@ func (upd *UpdateCheck) WriteToDisk() error {
3938
return err
4039
}
4140

42-
err = ioutil.WriteFile(upd.FileUsed, enc, 0600)
41+
err = os.WriteFile(upd.FileUsed, enc, 0600)
4342
return err
4443
}
4544

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

5453
upd.FileUsed = appSettingsPath
5554

56-
content, err := ioutil.ReadFile(appSettingsPath) // #nosec
55+
content, err := os.ReadFile(appSettingsPath) // #nosec
5756
if err != nil {
5857
return err
5958
}

0 commit comments

Comments
 (0)