Projects STRLCPY syft Commits 630c18e0
🤬
  • Print package list when extra packages found (#1791)

    The tests in test/cli/packages_cmd_test.go are hard to debug when different
    packages are found in different environments. For example, CI runs and M1 macs
    have been observed to have different package counts. Therefore, if the test is
    about to fail, log a sorted list of the packages that were found, so that it is
    easy to compare failures of these tests.
    
    Signed-off-by: Will Murphy <[email protected]>
  • Loading...
  • William Murphy committed with GitHub 12 months ago
    630c18e0
    1 parent 1860bab2
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    test/cli/trait_assertions_test.go
    skipped 1 lines
    2 2   
    3 3  import (
    4 4   "encoding/json"
     5 + "fmt"
    5 6   "os"
    6 7   "os/exec"
    7 8   "path/filepath"
    8 9   "regexp"
     10 + "sort"
    9 11   "strings"
    10 12   "testing"
    11 13   
    skipped 92 lines
    104 106  func assertPackageCount(length uint) traitAssertion {
    105 107   return func(tb testing.TB, stdout, _ string, _ int) {
    106 108   tb.Helper()
     109 + type NameAndVersion struct {
     110 + Name string `json:"name"`
     111 + Version string `json:"version"`
     112 + }
    107 113   type partial struct {
    108  - Artifacts []interface{} `json:"artifacts"`
     114 + Artifacts []NameAndVersion `json:"artifacts"`
    109 115   }
    110 116   var data partial
    111 117   
    skipped 3 lines
    115 121   
    116 122   if uint(len(data.Artifacts)) != length {
    117 123   tb.Errorf("expected package count of %d, but found %d", length, len(data.Artifacts))
     124 + debugArtifacts := make([]string, len(data.Artifacts))
     125 + for i, a := range data.Artifacts {
     126 + debugArtifacts[i] = fmt.Sprintf("%s:%s", a.Name, a.Version)
     127 + }
     128 + sort.Strings(debugArtifacts)
     129 + for i, a := range debugArtifacts {
     130 + tb.Errorf("package %d: %s", i+1, a)
     131 + }
    118 132   
    119 133   }
    120 134   }
    skipped 65 lines
Please wait...
Page is in error, reload to recover