Check effective release target membership

This commit is contained in:
2026-10-07 14:44:36 +00:00
parent 8d416558a3
commit ea223fcf98
2 changed files with 35 additions and 8 deletions

View File

@@ -2,6 +2,7 @@ package scripts
import (
"encoding/json"
"maps"
"os"
"os/exec"
"path/filepath"
@@ -147,6 +148,27 @@ func TestReleaseKitProfileDeclaresProductAndDeliverySettings(t *testing.T) {
}
}
func TestReleaseKitTargetMembership(t *testing.T) {
want := []string{"linux/amd64", "linux/arm64"}
for _, test := range []struct {
name string
targets []string
match bool
}{
{"missing amd64", []string{"linux/arm64", "linux/arm64"}, false},
{"missing arm64", []string{"linux/amd64", "linux/amd64"}, false},
{"additional target", []string{"linux/amd64", "linux/arm64", "darwin/arm64"}, false},
{"reordered", []string{"linux/arm64", "linux/amd64"}, true},
{"repeated", []string{"linux/amd64", "linux/arm64", "linux/amd64"}, true},
} {
t.Run(test.name, func(t *testing.T) {
if got := sameMembers(test.targets, want); got != test.match {
t.Fatalf("target membership for %q = %t, want %t", test.targets, got, test.match)
}
})
}
}
type releaseTestLayout struct {
repo string
caller string
@@ -257,15 +279,15 @@ func hasAdjacentArguments(args []string, first, second string) bool {
}
func sameMembers(got, want []string) bool {
if len(got) != len(want) {
return false
}
gotSet := make(map[string]struct{}, len(got))
for _, value := range got {
if !containsArgument(want, value) {
return false
}
gotSet[value] = struct{}{}
}
return true
wantSet := make(map[string]struct{}, len(want))
for _, value := range want {
wantSet[value] = struct{}{}
}
return maps.Equal(gotSet, wantSet)
}
func hasKey(values map[string]string, key string) bool {