| package main |
|
|
| import ( |
| "os" |
| "path/filepath" |
| "testing" |
|
|
| "gopkg.in/yaml.v3" |
| ) |
|
|
| |
| type GoReleaserConfig struct { |
| Builds []struct { |
| GOOS []string `yaml:"goos"` |
| GOARCH []string `yaml:"goarch"` |
| } `yaml:"builds"` |
| } |
|
|
| |
| func TestBinaryPermutations(t *testing.T) { |
| |
| repoRoot := filepath.Join("..", "..", ".goreleaser.yml") |
| data, err := os.ReadFile(repoRoot) |
| if err != nil { |
| t.Fatalf("failed to read .goreleaser.yml at %s: %v", repoRoot, err) |
| } |
|
|
| var cfg GoReleaserConfig |
| if err := yaml.Unmarshal(data, &cfg); err != nil { |
| t.Fatalf("failed to parse .goreleaser.yml: %v", err) |
| } |
|
|
| if len(cfg.Builds) == 0 { |
| t.Fatal("no builds configured in .goreleaser.yml") |
| } |
|
|
| build := cfg.Builds[0] |
|
|
| |
| expectedOS := map[string]bool{ |
| "linux": true, |
| "darwin": true, |
| "windows": true, |
| } |
|
|
| expectedArch := map[string]bool{ |
| "amd64": true, |
| "arm64": true, |
| } |
|
|
| |
| for os := range expectedOS { |
| found := false |
| for _, configOS := range build.GOOS { |
| if configOS == os { |
| found = true |
| break |
| } |
| } |
| if !found { |
| t.Errorf("OS %q not found in goreleaser config", os) |
| } |
| } |
|
|
| |
| for arch := range expectedArch { |
| found := false |
| for _, configArch := range build.GOARCH { |
| if configArch == arch { |
| found = true |
| break |
| } |
| } |
| if !found { |
| t.Errorf("Architecture %q not found in goreleaser config", arch) |
| } |
| } |
|
|
| |
| totalExpected := len(expectedOS) * len(expectedArch) |
| totalConfigured := len(build.GOOS) * len(build.GOARCH) |
|
|
| if totalConfigured != totalExpected { |
| t.Errorf("expected %d binaries (3 OS × 2 arch), but config produces %d", |
| totalExpected, totalConfigured) |
| } |
|
|
| t.Logf("✓ Binary matrix verified: %d OS × %d arch = %d total binaries", |
| len(build.GOOS), len(build.GOARCH), totalConfigured) |
| } |
|
|
| |
| func TestExpectedBinaryNames(t *testing.T) { |
| expectedBinaries := []string{ |
| "pinchtab-linux-amd64", |
| "pinchtab-linux-arm64", |
| "pinchtab-darwin-amd64", |
| "pinchtab-darwin-arm64", |
| "pinchtab-windows-amd64.exe", |
| "pinchtab-windows-arm64.exe", |
| } |
|
|
| if len(expectedBinaries) != 6 { |
| t.Errorf("expected 6 binaries, got %d", len(expectedBinaries)) |
| } |
|
|
| t.Logf("Expected binary names (%d total):", len(expectedBinaries)) |
| for _, bin := range expectedBinaries { |
| t.Logf(" ✓ %s", bin) |
| } |
| } |
|
|