Skip to content

Commit f1550ea

Browse files
dmitshurgopherbot
authored andcommitted
cmd/gorebuild: report files missing from posted archive better
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 <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
1 parent 911ff43 commit f1550ea

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

cmd/gorebuild/io.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ func DiffArchive[File1, File2 any](log *Log,
438438
if !okr && !okp { // duplicate name
439439
continue
440440
}
441-
if !okr {
441+
if !okp {
442442
log.Printf("%s: missing from posted archive", name)
443443
match = false
444444
continue

cmd/gorebuild/main_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main_test
6+
7+
import (
8+
"testing"
9+
10+
gorebuild "golang.org/x/build/cmd/gorebuild"
11+
)
12+
13+
func TestDiffArchive(t *testing.T) {
14+
type match bool // A named type for readability of test cases below.
15+
for _, tc := range [...]struct {
16+
name string
17+
a, b map[string]string
18+
want match
19+
}{
20+
{
21+
name: "empty",
22+
a: map[string]string{},
23+
b: map[string]string{},
24+
want: match(true),
25+
},
26+
{
27+
name: "equal",
28+
a: map[string]string{"file1": "content 1", "file2": "content 2"},
29+
b: map[string]string{"file1": "content 1", "file2": "content 2"},
30+
want: match(true),
31+
},
32+
{
33+
name: "different content",
34+
a: map[string]string{"file1": "content 1", "file2": "content 2"},
35+
b: map[string]string{"file1": "content 3", "file2": "content 4"},
36+
want: match(false),
37+
},
38+
{
39+
name: "missing file", // file2 in a, but missing in b.
40+
a: map[string]string{"file1": "", "file2": ""},
41+
b: map[string]string{"file1": ""},
42+
want: match(false),
43+
},
44+
{
45+
name: "unexpected file", // file3 not in a, but unexpectedly there in b.
46+
a: map[string]string{"file1": "", "file2": ""},
47+
b: map[string]string{"file1": "", "file2": "", "file3": ""},
48+
want: match(false),
49+
},
50+
} {
51+
t.Run(tc.name, func(t *testing.T) {
52+
var log gorebuild.Log
53+
got := gorebuild.DiffArchive(&log, tc.a, tc.b, func(_ *gorebuild.Log, a, b string) bool { return a == b })
54+
if got != bool(tc.want) {
55+
t.Errorf("got match = %v, want %v", got, tc.want)
56+
}
57+
})
58+
}
59+
}

0 commit comments

Comments
 (0)