Consolidate artifact declarations

This commit is contained in:
2026-10-06 17:29:41 +00:00
parent 3e9b5c1b99
commit 0eec4a30ed
9 changed files with 175 additions and 76 deletions

View File

@@ -0,0 +1,42 @@
package artifact
import (
"reflect"
"testing"
)
func TestNormalizeTargetsPreservesOrderAndFirstOccurrence(t *testing.T) {
targets := []Target{
{OS: "linux", Arch: "amd64"},
{OS: "windows", Arch: "arm64"},
{OS: "linux", Arch: "amd64"},
}
want := []Target{{OS: "linux", Arch: "amd64"}, {OS: "windows", Arch: "arm64"}}
if got := NormalizeTargets(targets); !reflect.DeepEqual(got, want) {
t.Fatalf("NormalizeTargets() = %#v, want %#v", got, want)
}
}
func TestExpectedBuildUsesSharedNamesInTargetOrder(t *testing.T) {
targets := []Target{{OS: "windows", Arch: "arm64"}, {OS: "linux", Arch: "amd64"}}
want := []Declaration{
{Target: targets[0], Filename: "app-v1.2.3-windows-arm64.exe"},
{Target: targets[1], Filename: "app-v1.2.3-linux-amd64"},
}
if got := ExpectedBuild("app", "v1.2.3", targets); !reflect.DeepEqual(got, want) {
t.Fatalf("ExpectedBuild() = %#v, want %#v", got, want)
}
}
func TestValidComponentPreservesBuildAndReceiptRules(t *testing.T) {
for _, value := range []string{"", "path/name", `path\name`, "line\nbreak", "line\rbreak"} {
if ValidComponent(value) {
t.Errorf("ValidComponent(%q) = true, want false", value)
}
}
for _, value := range []string{"app", "..", "nul\x00byte"} {
if !ValidComponent(value) {
t.Errorf("ValidComponent(%q) = false, want true", value)
}
}
}