Skip to content

Commit

Permalink
cmd/gorebuild: report files missing from posted archive better
Browse files Browse the repository at this point in the history
The "missing from posted archive" case was checking the wrong variable
and could never trigger. Fortunately, it's fairly harmless, as missing
files would still be caught by gorebuild thanks to check hitting a nil
pointer dereference trying to compare the missing file.

Check the right variable to fix the panic, and print the intended text.

For golang/go#57120.
For golang/go#58884.

Change-Id: I4560a9cc6c53bca37283c004826d728e175a1ff1
Reviewed-on: https://go-review.googlesource.com/c/build/+/556075
Reviewed-by: Michael Pratt <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Auto-Submit: Dmitri Shuralyov <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
dmitshur authored and gopherbot committed Jan 19, 2024
1 parent 911ff43 commit f1550ea
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/gorebuild/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func DiffArchive[File1, File2 any](log *Log,
if !okr && !okp { // duplicate name
continue
}
if !okr {
if !okp {
log.Printf("%s: missing from posted archive", name)
match = false
continue
Expand Down
59 changes: 59 additions & 0 deletions cmd/gorebuild/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main_test

import (
"testing"

gorebuild "golang.org/x/build/cmd/gorebuild"
)

func TestDiffArchive(t *testing.T) {
type match bool // A named type for readability of test cases below.
for _, tc := range [...]struct {
name string
a, b map[string]string
want match
}{
{
name: "empty",
a: map[string]string{},
b: map[string]string{},
want: match(true),
},
{
name: "equal",
a: map[string]string{"file1": "content 1", "file2": "content 2"},
b: map[string]string{"file1": "content 1", "file2": "content 2"},
want: match(true),
},
{
name: "different content",
a: map[string]string{"file1": "content 1", "file2": "content 2"},
b: map[string]string{"file1": "content 3", "file2": "content 4"},
want: match(false),
},
{
name: "missing file", // file2 in a, but missing in b.
a: map[string]string{"file1": "", "file2": ""},
b: map[string]string{"file1": ""},
want: match(false),
},
{
name: "unexpected file", // file3 not in a, but unexpectedly there in b.
a: map[string]string{"file1": "", "file2": ""},
b: map[string]string{"file1": "", "file2": "", "file3": ""},
want: match(false),
},
} {
t.Run(tc.name, func(t *testing.T) {
var log gorebuild.Log
got := gorebuild.DiffArchive(&log, tc.a, tc.b, func(_ *gorebuild.Log, a, b string) bool { return a == b })
if got != bool(tc.want) {
t.Errorf("got match = %v, want %v", got, tc.want)
}
})
}
}

0 comments on commit f1550ea

Please sign in to comment.