Projects STRLCPY syft Commits f07581f5
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    internal/file/tar_file_traversal.go
    skipped 31 lines
    32 32   }
    33 33   
    34 34   // we have a file we want to extract....
    35  - tempfilePrefix := filepath.Base(filepath.Clean(file.Name())) + "-"
    36  - tempFile, err := os.CreateTemp(dir, tempfilePrefix)
     35 + tempFilePrefix := filepath.Base(filepath.Clean(file.Name())) + "-"
     36 + tempFile, err := os.CreateTemp(dir, tempFilePrefix)
    37 37   if err != nil {
    38 38   return fmt.Errorf("unable to create temp file: %w", err)
    39 39   }
    40  - // we shouldn't try and keep the tempfile open as the returned result may have several files, which takes up
     40 + // we shouldn't try and keep the tempFile open as the returned result may have several files, which takes up
    41 41   // resources (leading to "too many open files"). Instead we'll return a file opener to the caller which
    42 42   // provides a ReadCloser. It is up to the caller to handle closing the file explicitly.
    43 43   defer tempFile.Close()
    skipped 22 lines
  • ■ ■ ■ ■ ■
    internal/file/zip_file_helpers_test.go
    1 1  package file
    2 2   
    3 3  import (
    4  - "io/ioutil"
    5 4   "os"
    6 5   "os/exec"
    7 6   "path"
    skipped 65 lines
    73 72  func setupZipFileTest(t testing.TB, sourceDirPath string, zip64 bool) string {
    74 73   t.Helper()
    75 74   
    76  - archivePrefix, err := ioutil.TempFile("", "syft-ziputil-archive-TEST-")
    77  - if err != nil {
    78  - t.Fatalf("unable to create tempfile: %+v", err)
    79  - }
    80  - 
    81  - t.Cleanup(
    82  - assertNoError(t,
    83  - func() error {
    84  - return os.Remove(archivePrefix.Name())
    85  - },
    86  - ),
    87  - )
    88  - 
    89  - destinationArchiveFilePath := archivePrefix.Name() + ".zip"
     75 + archivePrefix := path.Join(t.TempDir(), "syft-ziputil-archive-TEST-")
     76 + destinationArchiveFilePath := archivePrefix + ".zip"
    90 77   t.Logf("archive path: %s", destinationArchiveFilePath)
    91 78   createZipArchive(t, sourceDirPath, destinationArchiveFilePath, zip64)
    92  - 
    93  - t.Cleanup(
    94  - assertNoError(t,
    95  - func() error {
    96  - return os.Remove(destinationArchiveFilePath)
    97  - },
    98  - ),
    99  - )
    100 79   
    101 80   cwd, err := os.Getwd()
    102 81   if err != nil {
    skipped 18 lines
  • ■ ■ ■ ■ ■
    internal/file/zip_file_traversal_test.go
    skipped 8 lines
    9 9   "errors"
    10 10   "fmt"
    11 11   "io"
    12  - "io/ioutil"
    13 12   "os"
    14 13   "path"
    15 14   "path/filepath"
    skipped 33 lines
    49 48   sourceDirPath := path.Join(goldenRootDir, "zip-source")
    50 49   archiveFilePath := setupZipFileTest(t, sourceDirPath, false)
    51 50   
    52  - unzipDestinationDir, err := ioutil.TempDir("", "syft-ziputil-contents-TEST-")
    53  - t.Cleanup(assertNoError(t, func() error {
    54  - return os.RemoveAll(unzipDestinationDir)
    55  - }))
    56  - if err != nil {
    57  - t.Fatalf("unable to create tempdir: %+v", err)
    58  - }
     51 + unzipDestinationDir := t.TempDir()
    59 52   
    60 53   t.Logf("content path: %s", unzipDestinationDir)
    61 54   
    skipped 108 lines
    170 163   archivePath := prepZipSourceFixture(t)
    171 164   
    172 165   // create a temp file
    173  - tmpFile, err := ioutil.TempFile("", "syft-ziputil-prependZipSourceFixtureWithString-")
     166 + tmpFile, err := os.CreateTemp(tb.TempDir(), "syft-ziputil-prependZipSourceFixtureWithString-")
    174 167   if err != nil {
    175 168   t.Fatalf("unable to create tempfile: %+v", err)
    176 169   }
    skipped 32 lines
    209 202   
    210 203  func prepZipSourceFixture(t testing.TB) string {
    211 204   t.Helper()
    212  - archivePrefix, err := ioutil.TempFile("", "syft-ziputil-prepZipSourceFixture-")
    213  - if err != nil {
    214  - t.Fatalf("unable to create tempfile: %+v", err)
    215  - }
    216  - 
    217  - t.Cleanup(func() {
    218  - assert.NoError(t, os.Remove(archivePrefix.Name()))
    219  - })
     205 + archivePrefix := path.Join(t.TempDir(), "syft-ziputil-prepZipSourceFixture-")
    220 206   
    221 207   // the zip utility will add ".zip" to the end of the given name
    222  - archivePath := archivePrefix.Name() + ".zip"
    223  - 
    224  - t.Cleanup(func() {
    225  - assert.NoError(t, os.Remove(archivePath))
    226  - })
     208 + archivePath := archivePrefix + ".zip"
    227 209   
    228 210   t.Logf("archive path: %s", archivePath)
    229 211   
    230  - createZipArchive(t, "zip-source", archivePrefix.Name(), false)
     212 + createZipArchive(t, "zip-source", archivePrefix, false)
    231 213   
    232 214   return archivePath
    233 215  }
    skipped 101 lines
  • ■ ■ ■ ■ ■ ■
    syft/cpe/cpe_test.go
    skipped 2 lines
    3 3  import (
    4 4   "encoding/json"
    5 5   "fmt"
    6  - "io/ioutil"
     6 + "os"
    7 7   "strings"
    8 8   "testing"
    9 9   
    skipped 70 lines
    80 80  }
    81 81   
    82 82  func Test_CPEParser(t *testing.T) {
    83  - testCases := []struct {
     83 + var testCases []struct {
    84 84   CPEString string `json:"cpe-string"`
    85 85   CPEUrl string `json:"cpe-url"`
    86 86   WFN CPE `json:"wfn"`
    87  - }{}
    88  - out, err := ioutil.ReadFile("test-fixtures/cpe-data.json")
     87 + }
     88 + out, err := os.ReadFile("test-fixtures/cpe-data.json")
    89 89   require.NoError(t, err)
    90 90   require.NoError(t, json.Unmarshal(out, &testCases))
    91 91   
    skipped 137 lines
  • ■ ■ ■ ■ ■ ■
    syft/linux/identify_release_test.go
    1 1  package linux
    2 2   
    3 3  import (
    4  - "io/ioutil"
     4 + "io"
    5 5   "os"
    6 6   "testing"
    7 7   
    skipped 531 lines
    539 539   }
    540 540   defer fixture.Close()
    541 541   
    542  - b, err := ioutil.ReadAll(fixture)
     542 + b, err := io.ReadAll(fixture)
    543 543   if err != nil {
    544 544   t.Fatalf("unable to read fixture file: %+v", err)
    545 545   }
    skipped 4 lines
  • ■ ■ ■ ■ ■
    syft/pkg/cataloger/java/graalvm_native_image_cataloger_test.go
    skipped 5 lines
    6 6   "compress/gzip"
    7 7   "encoding/binary"
    8 8   "io"
    9  - "io/ioutil"
    10 9   "os"
    11 10   "path"
    12 11   "testing"
    skipped 23 lines
    36 35   t.Run(test.fixture, func(t *testing.T) {
    37 36   f, err := os.Open("test-fixtures/java-builds/packages/" + test.fixture)
    38 37   assert.NoError(t, err)
    39  - readerCloser := io.ReadCloser(ioutil.NopCloser(f))
     38 + readerCloser := io.NopCloser(f)
    40 39   reader, err := unionreader.GetUnionReader(readerCloser)
    41 40   assert.NoError(t, err)
    42 41   parsed := false
    skipped 64 lines
    107 106   for _, test := range tests {
    108 107   t.Run(path.Base(test.fixture), func(t *testing.T) {
    109 108   // Create a buffer to resemble a compressed SBOM in a native image.
    110  - sbom, err := ioutil.ReadFile(test.fixture)
     109 + sbom, err := os.ReadFile(test.fixture)
    111 110   assert.NoError(t, err)
    112 111   var b bytes.Buffer
    113 112   writebytes := bufio.NewWriter(&b)
    skipped 17 lines
  • ■ ■ ■ ■ ■
    syft/source/source_test.go
    skipped 897 lines
    898 898  func setupArchiveTest(t testing.TB, sourceDirPath string, layer2 bool) string {
    899 899   t.Helper()
    900 900   
    901  - archivePrefix, err := os.CreateTemp("", "syft-archive-TEST-")
     901 + archivePrefix, err := os.CreateTemp(t.TempDir(), "syft-archive-TEST-")
    902 902   require.NoError(t, err)
    903 903   
    904  - t.Cleanup(
    905  - assertNoError(t,
    906  - func() error {
    907  - return os.Remove(archivePrefix.Name())
    908  - },
    909  - ),
    910  - )
    911  - 
    912 904   destinationArchiveFilePath := archivePrefix.Name() + ".tar"
    913 905   t.Logf("archive path: %s", destinationArchiveFilePath)
    914 906   createArchive(t, sourceDirPath, destinationArchiveFilePath, layer2)
    915  - 
    916  - t.Cleanup(
    917  - assertNoError(t,
    918  - func() error {
    919  - return os.Remove(destinationArchiveFilePath)
    920  - },
    921  - ),
    922  - )
    923 907   
    924 908   cwd, err := os.Getwd()
    925 909   require.NoError(t, err)
    skipped 12 lines
  • ■ ■ ■ ■ ■
    test/cli/cyclonedx_valid_test.go
    skipped 43 lines
    44 44   args := []string{
    45 45   test.subcommand, fixtureRef, "-q",
    46 46   }
    47  - for _, a := range test.args {
    48  - args = append(args, a)
    49  - }
     47 + args = append(args, test.args...)
    50 48   
    51 49   cmd, stdout, stderr := runSyft(t, nil, args...)
    52 50   for _, traitFn := range test.assertions {
    skipped 79 lines
  • ■ ■ ■ ■ ■
    test/cli/json_schema_test.go
    skipped 56 lines
    57 57   args := []string{
    58 58   test.subcommand, fixtureRef, "-q",
    59 59   }
    60  - for _, a := range test.args {
    61  - args = append(args, a)
    62  - }
     60 + args = append(args, test.args...)
    63 61   
    64 62   _, stdout, stderr := runSyft(t, nil, args...)
    65 63   
    skipped 29 lines
  • ■ ■ ■ ■ ■
    test/cli/spdx_json_schema_test.go
    skipped 49 lines
    50 50   args := []string{
    51 51   test.subcommand, fixtureRef, "-q",
    52 52   }
    53  - for _, a := range test.args {
    54  - args = append(args, a)
    55  - }
     53 + args = append(args, test.args...)
    56 54   
    57 55   _, stdout, _ := runSyft(t, nil, args...)
    58 56   
    skipped 28 lines
  • ■ ■ ■ ■ ■
    test/integration/encode_decode_cycle_test.go
    skipped 1 lines
    2 2   
    3 3  import (
    4 4   "bytes"
    5  - "fmt"
    6 5   "regexp"
    7 6   "testing"
    8 7   
    skipped 55 lines
    64 63   }
    65 64   
    66 65   for _, test := range tests {
    67  - t.Run(fmt.Sprintf("%s", test.formatOption), func(t *testing.T) {
     66 + t.Run(string(test.formatOption), func(t *testing.T) {
    68 67   for _, image := range images {
    69 68   originalSBOM, _ := catalogFixtureImage(t, image, source.SquashedScope, nil)
    70 69   
    skipped 34 lines
Please wait...
Page is in error, reload to recover