Fix errors caught by go vet in compliance package
`go test` implicitly runs `go vet` and fails the tests if vet errors are found. Fix all the issues found by vet. Test: go test build/make/tools/compliance/... Change-Id: If0684cf124ece4931af440008cd44a61c22de475
This commit is contained in:
parent
35f79c37aa
commit
179ec3e55e
20 changed files with 35 additions and 35 deletions
|
@ -69,12 +69,12 @@ func main() {
|
|||
} else {
|
||||
dir, err := filepath.Abs(filepath.Dir(*outputFile))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot determine path to %q: %w\n", *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "cannot determine path to %q: %s\n", *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fi, err := os.Stat(dir)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot read directory %q of %q: %w\n", dir, *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "cannot read directory %q of %q: %s\n", dir, *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !fi.IsDir() {
|
||||
|
@ -102,7 +102,7 @@ func main() {
|
|||
if *outputFile != "-" {
|
||||
err := os.WriteFile(*outputFile, ofile.(*bytes.Buffer).Bytes(), 0666)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "could not write output to %q: %w\n", *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "could not write output to %q: %s\n", *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -275,7 +275,7 @@ func Test(t *testing.T) {
|
|||
|
||||
err := billOfMaterials(&ctx, rootFiles...)
|
||||
if err != nil {
|
||||
t.Fatalf("bom: error = %w, stderr = %v", err, stderr)
|
||||
t.Fatalf("bom: error = %v, stderr = %v", err, stderr)
|
||||
return
|
||||
}
|
||||
if stderr.Len() > 0 {
|
||||
|
|
|
@ -1217,7 +1217,7 @@ func Test_graphviz(t *testing.T) {
|
|||
outList := strings.Split(stdout.String(), "\n")
|
||||
outLine := 0
|
||||
if outList[outLine] != "strict digraph {" {
|
||||
t.Errorf("dumpgraph: got 1st line %v, want strict digraph {")
|
||||
t.Errorf("dumpgraph: got 1st line %v, want strict digraph {", outList[outLine])
|
||||
}
|
||||
outLine++
|
||||
if strings.HasPrefix(strings.TrimLeft(outList[outLine], " \t"), "rankdir") {
|
||||
|
|
|
@ -3305,7 +3305,7 @@ func Test_graphviz(t *testing.T) {
|
|||
outList := strings.Split(stdout.String(), "\n")
|
||||
outLine := 0
|
||||
if outList[outLine] != "strict digraph {" {
|
||||
t.Errorf("dumpresolutions: got 1st line %v, want strict digraph {")
|
||||
t.Errorf("dumpresolutions: got 1st line %v, want strict digraph {", outList[outLine])
|
||||
}
|
||||
outLine++
|
||||
if strings.HasPrefix(strings.TrimLeft(outList[outLine], " \t"), "rankdir") {
|
||||
|
|
|
@ -74,12 +74,12 @@ func main() {
|
|||
} else {
|
||||
dir, err := filepath.Abs(filepath.Dir(*outputFile))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot determine path to %q: %w\n", *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "cannot determine path to %q: %s\n", *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fi, err := os.Stat(dir)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot read directory %q of %q: %w\n", dir, *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "cannot read directory %q of %q: %s\n", dir, *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !fi.IsDir() {
|
||||
|
@ -107,7 +107,7 @@ func main() {
|
|||
if *outputFile != "-" {
|
||||
err := os.WriteFile(*outputFile, ofile.(*bytes.Buffer).Bytes(), 0666)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "could not write output to %q: %w\n", *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "could not write output to %q: %s\n", *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -139,13 +139,13 @@ func htmlNotice(ctx *context, files ...string) error {
|
|||
}
|
||||
|
||||
fmt.Fprintln(ctx.stdout, "<!DOCTYPE html>")
|
||||
fmt.Fprintln(ctx.stdout, "<html><head>\n")
|
||||
fmt.Fprintln(ctx.stdout, "<html><head>")
|
||||
fmt.Fprintln(ctx.stdout, "<style type=\"text/css\">")
|
||||
fmt.Fprintln(ctx.stdout, "body { padding: 2px; margin: 0; }")
|
||||
fmt.Fprintln(ctx.stdout, "ul { list-style-type: none; margin: 0; padding: 0; }")
|
||||
fmt.Fprintln(ctx.stdout, "li { padding-left: 1em; }")
|
||||
fmt.Fprintln(ctx.stdout, ".file-list { margin-left: 1em; }")
|
||||
fmt.Fprintln(ctx.stdout, "</style>\n")
|
||||
fmt.Fprintln(ctx.stdout, "</style>")
|
||||
if 0 < len(ctx.title) {
|
||||
fmt.Fprintf(ctx.stdout, "<title>%s</title>\n", html.EscapeString(ctx.title))
|
||||
}
|
||||
|
|
|
@ -560,7 +560,7 @@ func Test(t *testing.T) {
|
|||
|
||||
err := htmlNotice(&ctx, rootFiles...)
|
||||
if err != nil {
|
||||
t.Fatalf("htmlnotice: error = %w, stderr = %v", err, stderr)
|
||||
t.Fatalf("htmlnotice: error = %v, stderr = %v", err, stderr)
|
||||
return
|
||||
}
|
||||
if stderr.Len() > 0 {
|
||||
|
|
|
@ -66,12 +66,12 @@ func main() {
|
|||
} else {
|
||||
dir, err := filepath.Abs(filepath.Dir(*outputFile))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot determine path to %q: %w\n", *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "cannot determine path to %q: %s\n", *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fi, err := os.Stat(dir)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot read directory %q of %q: %w\n", dir, *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "cannot read directory %q of %q: %s\n", dir, *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !fi.IsDir() {
|
||||
|
@ -99,7 +99,7 @@ func main() {
|
|||
if *outputFile != "-" {
|
||||
err := os.WriteFile(*outputFile, ofile.(*bytes.Buffer).Bytes(), 0666)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "could not write output to %q: %w\n", *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "could not write output to %q: %s\n", *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ func Test(t *testing.T) {
|
|||
|
||||
err := shippedLibs(&ctx, rootFiles...)
|
||||
if err != nil {
|
||||
t.Fatalf("shippedLibs: error = %w, stderr = %v", err, stderr)
|
||||
t.Fatalf("shippedLibs: error = %v, stderr = %v", err, stderr)
|
||||
return
|
||||
}
|
||||
if stderr.Len() > 0 {
|
||||
|
|
|
@ -69,12 +69,12 @@ func main() {
|
|||
} else {
|
||||
dir, err := filepath.Abs(filepath.Dir(*outputFile))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot determine path to %q: %w\n", *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "cannot determine path to %q: %s\n", *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fi, err := os.Stat(dir)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot read directory %q of %q: %w\n", dir, *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "cannot read directory %q of %q: %s\n", dir, *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !fi.IsDir() {
|
||||
|
@ -102,7 +102,7 @@ func main() {
|
|||
if *outputFile != "-" {
|
||||
err := os.WriteFile(*outputFile, ofile.(*bytes.Buffer).Bytes(), 0666)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "could not write output to %q: %w\n", *outputFile, err)
|
||||
fmt.Fprintf(os.Stderr, "could not write output to %q: %s\n", *outputFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -474,7 +474,7 @@ func Test(t *testing.T) {
|
|||
|
||||
err := textNotice(&ctx, rootFiles...)
|
||||
if err != nil {
|
||||
t.Fatalf("textnotice: error = %w, stderr = %v", err, stderr)
|
||||
t.Fatalf("textnotice: error = %v, stderr = %v", err, stderr)
|
||||
return
|
||||
}
|
||||
if stderr.Len() > 0 {
|
||||
|
|
|
@ -363,7 +363,7 @@ func TestConditionSet(t *testing.T) {
|
|||
}
|
||||
actualConditions := actual.AsList()
|
||||
if len(actualConditions) != len(expectedConditions) {
|
||||
t.Errorf("len(MatchingAny(%d).AsList()): got %d, want %d",
|
||||
t.Errorf("len(MatchingAny(%s).AsList()): got %d, want %d",
|
||||
data, len(actualNames), len(expectedNames))
|
||||
} else {
|
||||
for i := 0; i < len(actualNames); i++ {
|
||||
|
@ -452,7 +452,7 @@ func TestConditionSet(t *testing.T) {
|
|||
for i := 0; i < len(actualConditions); i++ {
|
||||
if actualConditions[i] != expectedConditions[i] {
|
||||
t.Errorf("actual.AsList()[%d]: got %s, want %s",
|
||||
i, actualConditions[i], expectedConditions[i])
|
||||
i, actualConditions[i].Name(), expectedConditions[i].Name())
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -552,7 +552,7 @@ func TestConditionSet(t *testing.T) {
|
|||
for i := 0; i < len(actualConditions); i++ {
|
||||
if actualConditions[i] != expectedConditions[i] {
|
||||
t.Errorf("actual.AsList()[%d}: got %s, want %s",
|
||||
i, actualConditions[i], expectedConditions[i])
|
||||
i, actualConditions[i].Name(), expectedConditions[i].Name())
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -226,7 +226,7 @@ func TestPolicy_edgeConditions(t *testing.T) {
|
|||
fs[tt.edge.dep] = []byte(meta[tt.edge.dep])
|
||||
lg, err := ReadLicenseGraph(&fs, stderr, []string{tt.edge.target})
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error reading graph: %w", err)
|
||||
t.Errorf("unexpected error reading graph: %s", err)
|
||||
return
|
||||
}
|
||||
edge := lg.Edges()[0]
|
||||
|
|
|
@ -332,7 +332,7 @@ func TestResolveBottomUpConditions(t *testing.T) {
|
|||
stderr := &bytes.Buffer{}
|
||||
lg, err := toGraph(stderr, tt.roots, tt.edges)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected test data error: got %w, want no error", err)
|
||||
t.Errorf("unexpected test data error: got %s, want no error", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -643,7 +643,7 @@ func TestResolveTopDownConditions(t *testing.T) {
|
|||
stderr := &bytes.Buffer{}
|
||||
lg, err := toGraph(stderr, tt.roots, tt.edges)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected test data error: got %w, want no error", err)
|
||||
t.Errorf("unexpected test data error: got %s, want no error", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -457,7 +457,7 @@ func TestResolveNotices(t *testing.T) {
|
|||
stderr := &bytes.Buffer{}
|
||||
lg, err := toGraph(stderr, tt.roots, tt.edges)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected test data error: got %w, want no error", err)
|
||||
t.Errorf("unexpected test data error: got %s, want no error", err)
|
||||
return
|
||||
}
|
||||
expectedRs := toResolutionSet(lg, tt.expectedResolutions)
|
||||
|
|
|
@ -76,7 +76,7 @@ func TestResolveSourcePrivacy(t *testing.T) {
|
|||
stderr := &bytes.Buffer{}
|
||||
lg, err := toGraph(stderr, tt.roots, tt.edges)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected test data error: got %w, want no error", err)
|
||||
t.Errorf("unexpected test data error: got %s, want no error", err)
|
||||
return
|
||||
}
|
||||
expectedRs := toResolutionSet(lg, tt.expectedResolutions)
|
||||
|
|
|
@ -286,7 +286,7 @@ func TestResolveSourceSharing(t *testing.T) {
|
|||
stderr := &bytes.Buffer{}
|
||||
lg, err := toGraph(stderr, tt.roots, tt.edges)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected test data error: got %w, want no error", err)
|
||||
t.Errorf("unexpected test data error: got %s, want no error", err)
|
||||
return
|
||||
}
|
||||
expectedRs := toResolutionSet(lg, tt.expectedResolutions)
|
||||
|
|
|
@ -99,7 +99,7 @@ func TestConflictingSharedPrivateSource(t *testing.T) {
|
|||
stderr := &bytes.Buffer{}
|
||||
lg, err := toGraph(stderr, tt.roots, tt.edges)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected test data error: got %w, want no error", err)
|
||||
t.Errorf("unexpected test data error: got %s, want no error", err)
|
||||
return
|
||||
}
|
||||
expectedConflicts := toConflictList(lg, tt.expectedConflicts)
|
||||
|
|
|
@ -108,7 +108,7 @@ func TestShippedNodes(t *testing.T) {
|
|||
stderr := &bytes.Buffer{}
|
||||
lg, err := toGraph(stderr, tt.roots, tt.edges)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected test data error: got %w, want no error", err)
|
||||
t.Errorf("unexpected test data error: got %s, want no error", err)
|
||||
return
|
||||
}
|
||||
t.Logf("graph:")
|
||||
|
|
|
@ -620,7 +620,7 @@ func TestWalkResolutionsForCondition(t *testing.T) {
|
|||
stderr := &bytes.Buffer{}
|
||||
lg, err := toGraph(stderr, tt.roots, tt.edges)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected test data error: got %w, want no error", err)
|
||||
t.Errorf("unexpected test data error: got %s, want no error", err)
|
||||
return
|
||||
}
|
||||
expectedRs := toResolutionSet(lg, tt.expectedResolutions)
|
||||
|
@ -1228,7 +1228,7 @@ func TestWalkActionsForCondition(t *testing.T) {
|
|||
stderr := &bytes.Buffer{}
|
||||
lg, err := toGraph(stderr, tt.roots, tt.edges)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected test data error: got %w, want no error", err)
|
||||
t.Errorf("unexpected test data error: got %s, want no error", err)
|
||||
return
|
||||
}
|
||||
expectedAs := toActionSet(lg, tt.expectedActions)
|
||||
|
|
|
@ -88,9 +88,9 @@ func TestReadLicenseGraph(t *testing.T) {
|
|||
lg, err := ReadLicenseGraph(tt.fs, stderr, tt.roots)
|
||||
if err != nil {
|
||||
if len(tt.expectedError) == 0 {
|
||||
t.Errorf("unexpected error: got %w, want no error", err)
|
||||
t.Errorf("unexpected error: got %s, want no error", err)
|
||||
} else if !strings.Contains(err.Error(), tt.expectedError) {
|
||||
t.Errorf("unexpected error: got %w, want %q", err, tt.expectedError)
|
||||
t.Errorf("unexpected error: got %s, want %q", err, tt.expectedError)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue