mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 07:26:34 +01:00
Pr 1825 (#1865)
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:
co-authored by
guoguangwu
parent
d676e5e781
commit
f07581f504
@@ -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))
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user