chore: code cleanup

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>

---------

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Co-authored-by: guoguangwu <guoguangwu@magic-shield.com>
This commit is contained in:
Christopher Angelo Phillips
2023-06-05 17:01:00 +00:00
committed by GitHub
co-authored by guoguangwu
parent d676e5e781
commit f07581f504
11 changed files with 23 additions and 86 deletions
+4 -4
View File
@@ -3,7 +3,7 @@ package cpe
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
@@ -80,12 +80,12 @@ func Test_normalizeCpeField(t *testing.T) {
}
func Test_CPEParser(t *testing.T) {
testCases := []struct {
var testCases []struct {
CPEString string `json:"cpe-string"`
CPEUrl string `json:"cpe-url"`
WFN CPE `json:"wfn"`
}{}
out, err := ioutil.ReadFile("test-fixtures/cpe-data.json")
}
out, err := os.ReadFile("test-fixtures/cpe-data.json")
require.NoError(t, err)
require.NoError(t, json.Unmarshal(out, &testCases))
+2 -2
View File
@@ -1,7 +1,7 @@
package linux
import (
"io/ioutil"
"io"
"os"
"testing"
@@ -539,7 +539,7 @@ func retrieveFixtureContentsAsString(fixturePath string, t *testing.T) string {
}
defer fixture.Close()
b, err := ioutil.ReadAll(fixture)
b, err := io.ReadAll(fixture)
if err != nil {
t.Fatalf("unable to read fixture file: %+v", err)
}
@@ -6,7 +6,6 @@ import (
"compress/gzip"
"encoding/binary"
"io"
"io/ioutil"
"os"
"path"
"testing"
@@ -36,7 +35,7 @@ func TestParseNativeImage(t *testing.T) {
t.Run(test.fixture, func(t *testing.T) {
f, err := os.Open("test-fixtures/java-builds/packages/" + test.fixture)
assert.NoError(t, err)
readerCloser := io.ReadCloser(ioutil.NopCloser(f))
readerCloser := io.NopCloser(f)
reader, err := unionreader.GetUnionReader(readerCloser)
assert.NoError(t, err)
parsed := false
@@ -107,7 +106,7 @@ func TestParseNativeImageSbom(t *testing.T) {
for _, test := range tests {
t.Run(path.Base(test.fixture), func(t *testing.T) {
// Create a buffer to resemble a compressed SBOM in a native image.
sbom, err := ioutil.ReadFile(test.fixture)
sbom, err := os.ReadFile(test.fixture)
assert.NoError(t, err)
var b bytes.Buffer
writebytes := bufio.NewWriter(&b)
+1 -17
View File
@@ -898,29 +898,13 @@ func createArchive(t testing.TB, sourceDirPath, destinationArchivePath string, l
func setupArchiveTest(t testing.TB, sourceDirPath string, layer2 bool) string {
t.Helper()
archivePrefix, err := os.CreateTemp("", "syft-archive-TEST-")
archivePrefix, err := os.CreateTemp(t.TempDir(), "syft-archive-TEST-")
require.NoError(t, err)
t.Cleanup(
assertNoError(t,
func() error {
return os.Remove(archivePrefix.Name())
},
),
)
destinationArchiveFilePath := archivePrefix.Name() + ".tar"
t.Logf("archive path: %s", destinationArchiveFilePath)
createArchive(t, sourceDirPath, destinationArchiveFilePath, layer2)
t.Cleanup(
assertNoError(t,
func() error {
return os.Remove(destinationArchiveFilePath)
},
),
)
cwd, err := os.Getwd()
require.NoError(t, err)