-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |