github.com/windmeup/goreleaser@v1.21.95/internal/pipe/aur/aur_test.go (about) 1 package aur 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 "github.com/windmeup/goreleaser/internal/artifact" 11 "github.com/windmeup/goreleaser/internal/client" 12 "github.com/windmeup/goreleaser/internal/git" 13 "github.com/windmeup/goreleaser/internal/golden" 14 "github.com/windmeup/goreleaser/internal/skips" 15 "github.com/windmeup/goreleaser/internal/testctx" 16 "github.com/windmeup/goreleaser/internal/testlib" 17 "github.com/windmeup/goreleaser/pkg/config" 18 "github.com/windmeup/goreleaser/pkg/context" 19 ) 20 21 func TestContinueOnError(t *testing.T) { 22 require.True(t, Pipe{}.ContinueOnError()) 23 } 24 25 func TestDescription(t *testing.T) { 26 require.NotEmpty(t, Pipe{}.String()) 27 } 28 29 func createTemplateData() templateData { 30 return templateData{ 31 Name: "test-bin", 32 Desc: "Some desc", 33 Homepage: "https://example.com", 34 Conflicts: []string{"nope"}, 35 Depends: []string{"nope"}, 36 Arches: []string{"x86_64", "i686", "aarch64", "armv6h", "armv7h"}, 37 Rel: "1", 38 Provides: []string{"test"}, 39 OptDepends: []string{"nfpm"}, 40 Backup: []string{ 41 "/etc/mypkg.conf", 42 "/var/share/mypkg", 43 }, 44 Maintainers: []string{ 45 "Ciclano <ciclano@example.com>", 46 "Cicrano <cicrano@example.com>", 47 }, 48 Contributors: []string{ 49 "Fulano <fulano@example.com>", 50 "Beltrano <beltrano@example.com>", 51 }, 52 License: "MIT", 53 Version: "0.1.3", 54 Package: `# bin 55 install -Dm755 "./goreleaser" "${pkgdir}/usr/bin/goreleaser" 56 57 # license 58 install -Dm644 "./LICENSE.md" "${pkgdir}/usr/share/licenses/goreleaser/LICENSE" 59 60 # completions 61 mkdir -p "${pkgdir}/usr/share/bash-completion/completions/" 62 mkdir -p "${pkgdir}/usr/share/zsh/site-functions/" 63 mkdir -p "${pkgdir}/usr/share/fish/vendor_completions.d/" 64 install -Dm644 "./completions/goreleaser.bash" "${pkgdir}/usr/share/bash-completion/completions/goreleaser" 65 install -Dm644 "./completions/goreleaser.zsh" "${pkgdir}/usr/share/zsh/site-functions/_goreleaser" 66 install -Dm644 "./completions/goreleaser.fish" "${pkgdir}/usr/share/fish/vendor_completions.d/goreleaser.fish" 67 68 # man pages 69 install -Dm644 "./manpages/goreleaser.1.gz" "${pkgdir}/usr/share/man/man1/goreleaser.1.gz"`, 70 ReleasePackages: []releasePackage{ 71 { 72 Arch: "x86_64", 73 DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz", 74 SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", 75 Format: "tar.gz", 76 }, 77 { 78 Arch: "armv6h", 79 DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm6.tar.gz", 80 SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", 81 Format: "tar.gz", 82 }, 83 { 84 Arch: "aarch64", 85 DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm64.tar.gz", 86 SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", 87 Format: "tar.gz", 88 }, 89 { 90 Arch: "i686", 91 DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_386.tar.gz", 92 SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", 93 Format: "tar.gz", 94 }, 95 { 96 Arch: "armv7h", 97 DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_arm7.tar.gz", 98 SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", 99 Format: "tar.gz", 100 }, 101 }, 102 } 103 } 104 105 func TestFullAur(t *testing.T) { 106 data := createTemplateData() 107 pkg, err := applyTemplate(testctx.NewWithCfg(config.Project{ 108 ProjectName: "foo", 109 }), aurTemplateData, data) 110 require.NoError(t, err) 111 112 golden.RequireEqual(t, []byte(pkg)) 113 } 114 115 func TestAurSimple(t *testing.T) { 116 pkg, err := applyTemplate(testctx.New(), aurTemplateData, createTemplateData()) 117 require.NoError(t, err) 118 require.Contains(t, pkg, `# Maintainer: Ciclano <ciclano@example.com>`) 119 require.Contains(t, pkg, `# Maintainer: Cicrano <cicrano@example.com>`) 120 require.Contains(t, pkg, `# Contributor: Fulano <fulano@example.com>`) 121 require.Contains(t, pkg, `# Contributor: Beltrano <beltrano@example.com>`) 122 require.Contains(t, pkg, `pkgname='test-bin'`) 123 require.Contains(t, pkg, `url='https://example.com'`) 124 require.Contains(t, pkg, `source_x86_64=("${pkgname}_${pkgver}_x86_64.tar.gz::https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz")`) 125 require.Contains(t, pkg, `sha256sums_x86_64=('1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67')`) 126 require.Contains(t, pkg, `pkgver=0.1.3`) 127 } 128 129 func TestFullSrcInfo(t *testing.T) { 130 data := createTemplateData() 131 data.License = "MIT" 132 pkg, err := applyTemplate(testctx.NewWithCfg(config.Project{ 133 ProjectName: "foo", 134 }), srcInfoTemplate, data) 135 require.NoError(t, err) 136 137 golden.RequireEqual(t, []byte(pkg)) 138 } 139 140 func TestSrcInfoSimple(t *testing.T) { 141 pkg, err := applyTemplate(testctx.New(), srcInfoTemplate, createTemplateData()) 142 require.NoError(t, err) 143 require.Contains(t, pkg, `pkgbase = test-bin`) 144 require.Contains(t, pkg, `pkgname = test-bin`) 145 require.Contains(t, pkg, `url = https://example.com`) 146 require.Contains(t, pkg, `source_x86_64 = https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz`) 147 require.Contains(t, pkg, `sha256sums_x86_64 = 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67`) 148 require.Contains(t, pkg, `pkgver = 0.1.3`) 149 } 150 151 func TestFullPipe(t *testing.T) { 152 type testcase struct { 153 prepare func(ctx *context.Context) 154 expectedRunError string 155 expectedRunErrorCheck func(testing.TB, error) 156 expectedPublishError string 157 expectedPublishErrorIs error 158 expectedPublishErrorCheck func(testing.TB, error) 159 } 160 for name, tt := range map[string]testcase{ 161 "default": { 162 prepare: func(ctx *context.Context) { 163 ctx.TokenType = context.TokenTypeGitHub 164 ctx.Config.AURs[0].Homepage = "https://github.com/goreleaser" 165 }, 166 }, 167 "with-more-opts": { 168 prepare: func(ctx *context.Context) { 169 ctx.TokenType = context.TokenTypeGitHub 170 ctx.Config.AURs[0].Homepage = "https://github.com/goreleaser" 171 ctx.Config.AURs[0].Maintainers = []string{"me"} 172 ctx.Config.AURs[0].Contributors = []string{"me as well"} 173 ctx.Config.AURs[0].Depends = []string{"curl", "bash"} 174 ctx.Config.AURs[0].OptDepends = []string{"wget: stuff", "foo: bar"} 175 ctx.Config.AURs[0].Provides = []string{"git", "svn"} 176 ctx.Config.AURs[0].Conflicts = []string{"libcurl", "cvs", "blah"} 177 }, 178 }, 179 "default-gitlab": { 180 prepare: func(ctx *context.Context) { 181 ctx.TokenType = context.TokenTypeGitLab 182 ctx.Config.AURs[0].Homepage = "https://gitlab.com/goreleaser" 183 }, 184 }, 185 "invalid-name-template": { 186 prepare: func(ctx *context.Context) { 187 ctx.Config.AURs[0].Name = "{{ .Asdsa }" 188 }, 189 expectedRunErrorCheck: testlib.RequireTemplateError, 190 }, 191 "invalid-package-template": { 192 prepare: func(ctx *context.Context) { 193 ctx.Config.AURs[0].Package = "{{ .Asdsa }" 194 }, 195 expectedRunErrorCheck: testlib.RequireTemplateError, 196 }, 197 "invalid-commit-template": { 198 prepare: func(ctx *context.Context) { 199 ctx.Config.AURs[0].CommitMessageTemplate = "{{ .Asdsa }" 200 }, 201 expectedPublishErrorCheck: testlib.RequireTemplateError, 202 }, 203 "invalid-key-template": { 204 prepare: func(ctx *context.Context) { 205 ctx.Config.AURs[0].PrivateKey = "{{ .Asdsa }" 206 }, 207 expectedPublishErrorCheck: testlib.RequireTemplateError, 208 }, 209 "no-key": { 210 prepare: func(ctx *context.Context) { 211 ctx.Config.AURs[0].PrivateKey = "" 212 }, 213 expectedPublishError: `private_key is empty`, 214 }, 215 "key-not-found": { 216 prepare: func(ctx *context.Context) { 217 ctx.Config.AURs[0].PrivateKey = "testdata/nope" 218 }, 219 expectedPublishErrorIs: os.ErrNotExist, 220 }, 221 "invalid-git-url-template": { 222 prepare: func(ctx *context.Context) { 223 ctx.Config.AURs[0].GitURL = "{{ .Asdsa }" 224 }, 225 expectedPublishErrorCheck: testlib.RequireTemplateError, 226 }, 227 "no-git-url": { 228 prepare: func(ctx *context.Context) { 229 ctx.Config.AURs[0].GitURL = "" 230 }, 231 expectedPublishError: `url is empty`, 232 }, 233 "invalid-ssh-cmd-template": { 234 prepare: func(ctx *context.Context) { 235 ctx.Config.AURs[0].GitSSHCommand = "{{ .Asdsa }" 236 }, 237 expectedPublishErrorCheck: testlib.RequireTemplateError, 238 }, 239 "invalid-commit-author-template": { 240 prepare: func(ctx *context.Context) { 241 ctx.Config.AURs[0].CommitAuthor.Name = "{{ .Asdsa }" 242 }, 243 expectedPublishErrorCheck: testlib.RequireTemplateError, 244 }, 245 } { 246 t.Run(name, func(t *testing.T) { 247 url := testlib.GitMakeBareRepository(t) 248 key := testlib.MakeNewSSHKey(t, "") 249 250 folder := t.TempDir() 251 ctx := testctx.NewWithCfg( 252 config.Project{ 253 Dist: folder, 254 ProjectName: name, 255 AURs: []config.AUR{ 256 { 257 Name: name, 258 IDs: []string{"foo"}, 259 PrivateKey: key, 260 License: "MIT", 261 GitURL: url, 262 Description: "A run pipe test fish food and FOO={{ .Env.FOO }}", 263 }, 264 }, 265 Env: []string{"FOO=foo_is_bar"}, 266 }, 267 testctx.WithCurrentTag("v1.0.1-foo"), 268 testctx.WithSemver(1, 0, 1, "foo"), 269 testctx.WithVersion("1.0.1-foo"), 270 ) 271 272 tt.prepare(ctx) 273 ctx.Artifacts.Add(&artifact.Artifact{ 274 Name: "should-be-ignored.tar.gz", 275 Path: "doesnt matter", 276 Goos: "linux", 277 Goarch: "amd64", 278 Goamd64: "v3", 279 Type: artifact.UploadableArchive, 280 Extra: map[string]interface{}{ 281 artifact.ExtraID: "bar", 282 artifact.ExtraFormat: "tar.gz", 283 artifact.ExtraBinaries: []string{"bar"}, 284 }, 285 }) 286 ctx.Artifacts.Add(&artifact.Artifact{ 287 Name: "bar_bin.tar.gz", 288 Path: "doesnt matter", 289 Goos: "linux", 290 Goarch: "amd64", 291 Goamd64: "v1", 292 Type: artifact.UploadableArchive, 293 Extra: map[string]interface{}{ 294 artifact.ExtraID: "bar", 295 artifact.ExtraFormat: "tar.gz", 296 artifact.ExtraBinaries: []string{"bar"}, 297 }, 298 }) 299 path := filepath.Join(folder, "bin.tar.gz") 300 ctx.Artifacts.Add(&artifact.Artifact{ 301 Name: "bin.tar.gz", 302 Path: path, 303 Goos: "linux", 304 Goarch: "amd64", 305 Goamd64: "v1", 306 Type: artifact.UploadableArchive, 307 Extra: map[string]interface{}{ 308 artifact.ExtraID: "foo", 309 artifact.ExtraFormat: "tar.gz", 310 artifact.ExtraBinaries: []string{"name"}, 311 }, 312 }) 313 314 f, err := os.Create(path) 315 require.NoError(t, err) 316 require.NoError(t, f.Close()) 317 client := client.NewMock() 318 319 require.NoError(t, Pipe{}.Default(ctx)) 320 321 if tt.expectedRunError != "" { 322 require.EqualError(t, runAll(ctx, client), tt.expectedRunError) 323 return 324 } 325 if tt.expectedRunErrorCheck != nil { 326 tt.expectedRunErrorCheck(t, runAll(ctx, client)) 327 return 328 } 329 require.NoError(t, runAll(ctx, client)) 330 331 if tt.expectedPublishError != "" { 332 require.EqualError(t, Pipe{}.Publish(ctx), tt.expectedPublishError) 333 return 334 } 335 336 if tt.expectedPublishErrorIs != nil { 337 require.ErrorIs(t, Pipe{}.Publish(ctx), tt.expectedPublishErrorIs) 338 return 339 } 340 341 if tt.expectedPublishErrorCheck != nil { 342 tt.expectedPublishErrorCheck(t, Pipe{}.Publish(ctx)) 343 return 344 } 345 346 require.NoError(t, Pipe{}.Publish(ctx)) 347 348 requireEqualRepoFiles(t, folder, name, url) 349 }) 350 } 351 } 352 353 func TestRunPipe(t *testing.T) { 354 url := testlib.GitMakeBareRepository(t) 355 key := testlib.MakeNewSSHKey(t, "") 356 357 folder := t.TempDir() 358 ctx := testctx.NewWithCfg( 359 config.Project{ 360 Dist: folder, 361 ProjectName: "foo", 362 AURs: []config.AUR{ 363 { 364 License: "MIT", 365 Description: "A run pipe test aur and FOO={{ .Env.FOO }}", 366 Homepage: "https://github.com/goreleaser", 367 IDs: []string{"foo"}, 368 GitURL: url, 369 PrivateKey: key, 370 }, 371 }, 372 GitHubURLs: config.GitHubURLs{ 373 Download: "https://github.com", 374 }, 375 Release: config.Release{ 376 GitHub: config.Repo{ 377 Owner: "test", 378 Name: "test", 379 }, 380 }, 381 Env: []string{"FOO=foo_is_bar"}, 382 }, 383 testctx.GitHubTokenType, 384 testctx.WithCurrentTag("v1.0.1"), 385 testctx.WithSemver(1, 0, 1, ""), 386 testctx.WithVersion("1.0.1"), 387 ) 388 389 for _, a := range []struct { 390 name string 391 goos string 392 goarch string 393 goarm string 394 }{ 395 { 396 name: "bin", 397 goos: "darwin", 398 goarch: "amd64", 399 }, 400 { 401 name: "bin", 402 goos: "darwin", 403 goarch: "arm64", 404 }, 405 { 406 name: "bin", 407 goos: "windows", 408 goarch: "arm64", 409 }, 410 { 411 name: "bin", 412 goos: "windows", 413 goarch: "amd64", 414 }, 415 { 416 name: "bin", 417 goos: "linux", 418 goarch: "386", 419 }, 420 { 421 name: "bin", 422 goos: "linux", 423 goarch: "amd64", 424 }, 425 { 426 name: "arm64", 427 goos: "linux", 428 goarch: "arm64", 429 }, 430 { 431 name: "armv5", 432 goos: "linux", 433 goarch: "arm", 434 goarm: "5", 435 }, 436 { 437 name: "armv6", 438 goos: "linux", 439 goarch: "arm", 440 goarm: "6", 441 }, 442 { 443 name: "armv7", 444 goos: "linux", 445 goarch: "arm", 446 goarm: "7", 447 }, 448 } { 449 path := filepath.Join(folder, fmt.Sprintf("%s.tar.gz", a.name)) 450 ctx.Artifacts.Add(&artifact.Artifact{ 451 Name: fmt.Sprintf("%s.tar.gz", a.name), 452 Path: path, 453 Goos: a.goos, 454 Goarch: a.goarch, 455 Goarm: a.goarm, 456 Goamd64: "v1", 457 Type: artifact.UploadableArchive, 458 Extra: map[string]interface{}{ 459 artifact.ExtraID: "foo", 460 artifact.ExtraFormat: "tar.gz", 461 artifact.ExtraBinaries: []string{"foo"}, 462 }, 463 }) 464 f, err := os.Create(path) 465 require.NoError(t, err) 466 require.NoError(t, f.Close()) 467 } 468 469 client := client.NewMock() 470 471 require.NoError(t, Pipe{}.Default(ctx)) 472 require.NoError(t, runAll(ctx, client)) 473 require.NoError(t, Pipe{}.Publish(ctx)) 474 475 requireEqualRepoFiles(t, folder, "foo", url) 476 } 477 478 func TestRunPipeNoBuilds(t *testing.T) { 479 ctx := testctx.NewWithCfg(config.Project{ 480 ProjectName: "foo", 481 AURs: []config.AUR{{}}, 482 }, testctx.GitHubTokenType) 483 client := client.NewMock() 484 require.NoError(t, Pipe{}.Default(ctx)) 485 require.Equal(t, ErrNoArchivesFound, runAll(ctx, client)) 486 require.False(t, client.CreatedFile) 487 } 488 489 func TestRunPipeBinaryRelease(t *testing.T) { 490 url := testlib.GitMakeBareRepository(t) 491 key := testlib.MakeNewSSHKey(t, "") 492 folder := t.TempDir() 493 ctx := testctx.NewWithCfg( 494 config.Project{ 495 Dist: folder, 496 ProjectName: "foo", 497 AURs: []config.AUR{{ 498 GitURL: url, 499 PrivateKey: key, 500 }}, 501 }, 502 testctx.WithVersion("1.2.1"), 503 testctx.WithCurrentTag("v1.2.1"), 504 testctx.WithSemver(1, 2, 1, ""), 505 ) 506 507 path := filepath.Join(folder, "dist/foo_linux_amd64/foo") 508 ctx.Artifacts.Add(&artifact.Artifact{ 509 Name: "foo_linux_amd64", 510 Path: path, 511 Goos: "linux", 512 Goarch: "amd64", 513 Goamd64: "v1", 514 Type: artifact.UploadableBinary, 515 Extra: map[string]interface{}{ 516 artifact.ExtraID: "foo", 517 artifact.ExtraFormat: "binary", 518 artifact.ExtraBinary: "foo", 519 }, 520 }) 521 522 require.NoError(t, Pipe{}.Default(ctx)) 523 require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) 524 f, err := os.Create(path) 525 require.NoError(t, err) 526 require.NoError(t, f.Close()) 527 528 client := client.NewMock() 529 require.NoError(t, runAll(ctx, client)) 530 require.NoError(t, Pipe{}.Publish(ctx)) 531 532 requireEqualRepoFiles(t, folder, "foo", url) 533 } 534 535 func TestRunPipeNoUpload(t *testing.T) { 536 folder := t.TempDir() 537 testPublish := func(tb testing.TB, modifier func(ctx *context.Context)) { 538 tb.Helper() 539 ctx := testctx.NewWithCfg( 540 config.Project{ 541 Dist: folder, 542 ProjectName: "foo", 543 Release: config.Release{}, 544 AURs: []config.AUR{{}}, 545 }, 546 testctx.GitHubTokenType, 547 testctx.WithCurrentTag("v1.0.1"), 548 testctx.WithSemver(1, 0, 1, ""), 549 ) 550 551 path := filepath.Join(folder, "whatever.tar.gz") 552 f, err := os.Create(path) 553 require.NoError(t, err) 554 require.NoError(t, f.Close()) 555 ctx.Artifacts.Add(&artifact.Artifact{ 556 Name: "bin", 557 Path: path, 558 Goos: "linux", 559 Goarch: "amd64", 560 Goamd64: "v1", 561 Type: artifact.UploadableArchive, 562 Extra: map[string]interface{}{ 563 artifact.ExtraID: "foo", 564 artifact.ExtraFormat: "tar.gz", 565 artifact.ExtraBinaries: []string{"foo"}, 566 }, 567 }) 568 569 modifier(ctx) 570 571 require.NoError(t, Pipe{}.Default(ctx)) 572 client := client.NewMock() 573 require.NoError(t, runAll(ctx, client)) 574 t.Log(Pipe{}.Publish(ctx)) 575 testlib.AssertSkipped(t, Pipe{}.Publish(ctx)) 576 require.False(t, client.CreatedFile) 577 } 578 579 t.Run("skip upload true", func(t *testing.T) { 580 testPublish(t, func(ctx *context.Context) { 581 ctx.Config.AURs[0].SkipUpload = "true" 582 ctx.Semver.Prerelease = "" 583 }) 584 }) 585 t.Run("skip upload auto", func(t *testing.T) { 586 testPublish(t, func(ctx *context.Context) { 587 ctx.Config.AURs[0].SkipUpload = "auto" 588 ctx.Semver.Prerelease = "beta1" 589 }) 590 }) 591 } 592 593 func TestRunEmptyTokenType(t *testing.T) { 594 folder := t.TempDir() 595 ctx := testctx.NewWithCfg( 596 config.Project{ 597 Dist: folder, 598 ProjectName: "foo", 599 Release: config.Release{}, 600 AURs: []config.AUR{ 601 {}, 602 }, 603 }, 604 testctx.WithGitInfo(context.GitInfo{CurrentTag: "v1.0.1"}), 605 testctx.WithSemver(1, 0, 1, ""), 606 ) 607 path := filepath.Join(folder, "whatever.tar.gz") 608 f, err := os.Create(path) 609 require.NoError(t, err) 610 require.NoError(t, f.Close()) 611 ctx.Artifacts.Add(&artifact.Artifact{ 612 Name: "bin", 613 Path: path, 614 Goos: "linux", 615 Goarch: "amd64", 616 Type: artifact.UploadableArchive, 617 Extra: map[string]interface{}{ 618 artifact.ExtraID: "foo", 619 artifact.ExtraFormat: "tar.gz", 620 artifact.ExtraBinaries: []string{"foo"}, 621 }, 622 }) 623 client := client.NewMock() 624 require.NoError(t, runAll(ctx, client)) 625 } 626 627 func TestDefault(t *testing.T) { 628 t.Run("empty", func(t *testing.T) { 629 ctx := testctx.NewWithCfg(config.Project{ 630 ProjectName: "myproject", 631 AURs: []config.AUR{{}}, 632 }, testctx.GitHubTokenType) 633 require.NoError(t, Pipe{}.Default(ctx)) 634 require.Equal(t, config.AUR{ 635 Name: "myproject-bin", 636 Conflicts: []string{"myproject"}, 637 Provides: []string{"myproject"}, 638 Rel: "1", 639 CommitMessageTemplate: defaultCommitMsg, 640 Goamd64: "v1", 641 CommitAuthor: config.CommitAuthor{ 642 Name: "goreleaserbot", 643 Email: "bot@goreleaser.com", 644 }, 645 }, ctx.Config.AURs[0]) 646 }) 647 648 t.Run("name-without-bin-suffix", func(t *testing.T) { 649 ctx := testctx.NewWithCfg(config.Project{ 650 ProjectName: "myproject", 651 AURs: []config.AUR{ 652 { 653 Name: "foo", 654 }, 655 }, 656 }, testctx.GitHubTokenType) 657 require.NoError(t, Pipe{}.Default(ctx)) 658 require.Equal(t, config.AUR{ 659 Name: "foo-bin", 660 Conflicts: []string{"myproject"}, 661 Provides: []string{"myproject"}, 662 Rel: "1", 663 CommitMessageTemplate: defaultCommitMsg, 664 Goamd64: "v1", 665 CommitAuthor: config.CommitAuthor{ 666 Name: "goreleaserbot", 667 Email: "bot@goreleaser.com", 668 }, 669 }, ctx.Config.AURs[0]) 670 }) 671 672 t.Run("partial", func(t *testing.T) { 673 ctx := testctx.NewWithCfg(config.Project{ 674 ProjectName: "myproject", 675 AURs: []config.AUR{ 676 { 677 Conflicts: []string{"somethingelse"}, 678 Goamd64: "v3", 679 }, 680 }, 681 }, testctx.GitHubTokenType) 682 require.NoError(t, Pipe{}.Default(ctx)) 683 require.Equal(t, config.AUR{ 684 Name: "myproject-bin", 685 Conflicts: []string{"somethingelse"}, 686 Provides: []string{"myproject"}, 687 Rel: "1", 688 CommitMessageTemplate: defaultCommitMsg, 689 Goamd64: "v3", 690 CommitAuthor: config.CommitAuthor{ 691 Name: "goreleaserbot", 692 Email: "bot@goreleaser.com", 693 }, 694 }, ctx.Config.AURs[0]) 695 }) 696 } 697 698 func TestSkip(t *testing.T) { 699 t.Run("skip", func(t *testing.T) { 700 require.True(t, Pipe{}.Skip(testctx.New())) 701 }) 702 t.Run("skip flag", func(t *testing.T) { 703 ctx := testctx.NewWithCfg(config.Project{ 704 AURs: []config.AUR{ 705 {}, 706 }, 707 }, testctx.Skip(skips.AUR)) 708 require.True(t, Pipe{}.Skip(ctx)) 709 }) 710 t.Run("dont skip", func(t *testing.T) { 711 ctx := testctx.NewWithCfg(config.Project{ 712 AURs: []config.AUR{ 713 {}, 714 }, 715 }) 716 require.False(t, Pipe{}.Skip(ctx)) 717 }) 718 } 719 720 func requireEqualRepoFiles(tb testing.TB, folder, name, url string) { 721 tb.Helper() 722 dir := tb.TempDir() 723 _, err := git.Run(testctx.New(), "-C", dir, "clone", url, "repo") 724 require.NoError(tb, err) 725 726 for reponame, ext := range map[string]string{ 727 "PKGBUILD": ".pkgbuild", 728 ".SRCINFO": ".srcinfo", 729 } { 730 path := filepath.Join(folder, "aur", name+"-bin"+ext) 731 bts, err := os.ReadFile(path) 732 require.NoError(tb, err) 733 golden.RequireEqualExt(tb, bts, ext) 734 735 bts, err = os.ReadFile(filepath.Join(dir, "repo", reponame)) 736 require.NoError(tb, err) 737 golden.RequireEqualExt(tb, bts, ext) 738 } 739 }