2026-09-23 15:03:20 +00:00
|
|
|
package scripts
|
|
|
|
|
|
|
|
|
|
import (
|
2026-10-07 13:58:07 +00:00
|
|
|
"encoding/json"
|
2026-10-07 14:44:36 +00:00
|
|
|
"maps"
|
2026-09-23 15:03:20 +00:00
|
|
|
"os"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2026-10-07 13:58:07 +00:00
|
|
|
func TestReleaseKitProfileDeclaresProductAndDeliverySettings(t *testing.T) {
|
|
|
|
|
data, err := os.ReadFile("../releasekit.json")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
var raw map[string]json.RawMessage
|
|
|
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
var deliveryFields map[string]json.RawMessage
|
|
|
|
|
if err := json.Unmarshal(raw["delivery"], &deliveryFields); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if _, exists := deliveryFields["token"]; exists {
|
|
|
|
|
t.Fatal("profile must not contain a credential value")
|
|
|
|
|
}
|
|
|
|
|
var profile struct {
|
2026-10-07 14:50:41 +00:00
|
|
|
Product string `json:"product"`
|
|
|
|
|
Remote string `json:"remote"`
|
|
|
|
|
Checks []json.RawMessage `json:"checks"`
|
2026-10-07 13:58:07 +00:00
|
|
|
Build struct {
|
|
|
|
|
MainPackage string `json:"main_package"`
|
|
|
|
|
BinaryName string `json:"binary_name"`
|
|
|
|
|
Targets []string `json:"targets"`
|
|
|
|
|
} `json:"build"`
|
|
|
|
|
Delivery struct {
|
|
|
|
|
BaseURL string `json:"base_url"`
|
|
|
|
|
Owner string `json:"owner"`
|
|
|
|
|
Repository string `json:"repository"`
|
|
|
|
|
TokenEnv string `json:"token_env"`
|
2026-11-10 16:02:17 +00:00
|
|
|
Forge string `json:"forge"`
|
2026-10-07 13:58:07 +00:00
|
|
|
} `json:"delivery"`
|
|
|
|
|
}
|
|
|
|
|
if err := json.Unmarshal(data, &profile); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-10-07 14:50:41 +00:00
|
|
|
if len(profile.Checks) != 0 {
|
|
|
|
|
t.Fatal("profile must not define additional checks")
|
|
|
|
|
}
|
2026-10-07 13:58:07 +00:00
|
|
|
if profile.Product != "Audita" || profile.Remote != "origin" {
|
|
|
|
|
t.Fatalf("product=%q remote=%q", profile.Product, profile.Remote)
|
|
|
|
|
}
|
|
|
|
|
if profile.Build.MainPackage != "./cmd/audita" || profile.Build.BinaryName != "audita" {
|
|
|
|
|
t.Fatalf("build=%+v", profile.Build)
|
|
|
|
|
}
|
|
|
|
|
if !sameMembers(profile.Build.Targets, []string{"linux/amd64", "linux/arm64"}) {
|
|
|
|
|
t.Fatalf("build targets=%q", profile.Build.Targets)
|
|
|
|
|
}
|
2026-11-10 16:02:17 +00:00
|
|
|
if profile.Delivery.BaseURL != "https://gitea.maximumdirect.net" || profile.Delivery.Owner != "eric" || profile.Delivery.Repository != "audita" || profile.Delivery.TokenEnv != "RELEASEKIT_GITEA_TOKEN" || profile.Delivery.Forge != "gitea" {
|
2026-10-07 13:58:07 +00:00
|
|
|
t.Fatalf("delivery=%+v", profile.Delivery)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-07 14:44:36 +00:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-07 13:58:07 +00:00
|
|
|
func sameMembers(got, want []string) bool {
|
2026-10-07 14:44:36 +00:00
|
|
|
gotSet := make(map[string]struct{}, len(got))
|
2026-10-07 13:58:07 +00:00
|
|
|
for _, value := range got {
|
2026-10-07 14:44:36 +00:00
|
|
|
gotSet[value] = struct{}{}
|
|
|
|
|
}
|
|
|
|
|
wantSet := make(map[string]struct{}, len(want))
|
|
|
|
|
for _, value := range want {
|
|
|
|
|
wantSet[value] = struct{}{}
|
2026-10-07 13:58:07 +00:00
|
|
|
}
|
2026-10-07 14:44:36 +00:00
|
|
|
return maps.Equal(gotSet, wantSet)
|
2026-10-07 13:58:07 +00:00
|
|
|
}
|