Skip to content

Commit 3383cb8

Browse files
committed
fix: release-branch final-commit tester
1 parent f1f3b5c commit 3383cb8

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

libevm/tooling/release/release_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,11 @@ func testReleaseBranch(t *testing.T, targetBranch string) {
219219
)
220220
require.NoErrorf(t, err, "object.DiffTree(commits = [%v, %v])", last.Hash, penultimate.Hash)
221221

222-
allowedFileModifications := map[string]struct{}{
223-
"version.libevm.go": {},
224-
"version.libevm_test.go": {},
225-
}
226-
for _, name := range changedFilesByName(t, lastCommitDiffs) {
227-
if _, ok := allowedFileModifications[name]; !ok {
228-
t.Errorf("Last commit on release branch modified disallowed file %q", name)
229-
}
222+
allowedFileModifications := map[string]bool{
223+
"version.libevm.go": true,
224+
"version.libevm_test.go": true,
230225
}
226+
testFinalCommitChanges(t, lastCommitDiffs, allowedFileModifications)
231227
})
232228
})
233229
}
@@ -345,22 +341,26 @@ func treeFromCommit(t *testing.T, c *object.Commit) *object.Tree {
345341
return tree
346342
}
347343

348-
func changedFilesByName(t *testing.T, changes object.Changes) []string {
349-
t.Helper()
350-
351-
var files []string
344+
func testFinalCommitChanges(t *testing.T, changes object.Changes, allowed map[string]bool) {
352345
for _, c := range changes {
353346
from, to, err := c.Files()
354347
require.NoErrorf(t, err, "%T.Files()", c)
355-
require.NotNilf(t, from, "file %q inserted", to.Name)
356-
require.NotNilf(t, to, "file %q deleted", from.Name)
357-
require.Equalf(t, from.Name, to.Name, "file renamed; expect modified file's name to equal original")
358-
359-
// [object.File.Name] is documented as being either the name or a path,
360-
// depending on how it was generated. We only need to protect against
361-
// accidental changes to the wrong files, so it's sufficient to just
362-
// check the names.
363-
files = append(files, filepath.Base(from.Name))
348+
// We have a guarantee that at most one of `from` or `to` is nil,
349+
// but not both. Usage of `x.Name` MUST be guarded by the if
350+
// statement to avoid a panic.
351+
switch {
352+
case from == nil:
353+
t.Errorf("Created %q", to.Name)
354+
case to == nil:
355+
t.Errorf("Deleted %q", from.Name)
356+
case from.Name != to.Name:
357+
t.Errorf("Renamed %q to %q", from.Name, to.Name)
358+
case !allowed[filepath.Base(from.Name)]:
359+
// [object.File.Name] is documented as being either the name or a path,
360+
// depending on how it was generated. We only need to protect against
361+
// accidental changes to the wrong files, so it's sufficient to just
362+
// check the names.
363+
t.Errorf("Modified disallowed file %q", filepath.Base(from.Name))
364+
}
364365
}
365-
return files
366366
}

0 commit comments

Comments
 (0)