github.phpd.cn/goreleaser/goreleaser@v0.92.0/internal/pipe/defaults/defaults_test.go (about) 1 package defaults 2 3 import ( 4 "testing" 5 6 "github.com/goreleaser/goreleaser/internal/testlib" 7 "github.com/goreleaser/goreleaser/pkg/config" 8 "github.com/goreleaser/goreleaser/pkg/context" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestDescription(t *testing.T) { 14 assert.NotEmpty(t, Pipe{}.String()) 15 } 16 17 func TestFillBasicData(t *testing.T) { 18 _, back := testlib.Mktmp(t) 19 defer back() 20 testlib.GitInit(t) 21 testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git") 22 23 var ctx = &context.Context{ 24 Config: config.Project{}, 25 } 26 27 assert.NoError(t, Pipe{}.Run(ctx)) 28 assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner) 29 assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name) 30 assert.NotEmpty(t, ctx.Config.Builds) 31 assert.Equal(t, "goreleaser", ctx.Config.Builds[0].Binary) 32 assert.Equal(t, ".", ctx.Config.Builds[0].Main) 33 assert.Contains(t, ctx.Config.Builds[0].Goos, "darwin") 34 assert.Contains(t, ctx.Config.Builds[0].Goos, "linux") 35 assert.Contains(t, ctx.Config.Builds[0].Goarch, "386") 36 assert.Contains(t, ctx.Config.Builds[0].Goarch, "amd64") 37 assert.Equal(t, "tar.gz", ctx.Config.Archive.Format) 38 assert.Contains(t, ctx.Config.Brew.Install, "bin.install \"goreleaser\"") 39 assert.Empty(t, ctx.Config.Dockers) 40 assert.Equal(t, "https://github.com", ctx.Config.GitHubURLs.Download) 41 assert.NotEmpty(t, ctx.Config.Archive.NameTemplate) 42 assert.NotEmpty(t, ctx.Config.Builds[0].Ldflags) 43 assert.NotEmpty(t, ctx.Config.Archive.Files) 44 assert.NotEmpty(t, ctx.Config.Dist) 45 } 46 47 func TestFillPartial(t *testing.T) { 48 _, back := testlib.Mktmp(t) 49 defer back() 50 testlib.GitInit(t) 51 testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git") 52 53 var ctx = &context.Context{ 54 Config: config.Project{ 55 GitHubURLs: config.GitHubURLs{ 56 Download: "https://github.company.com", 57 }, 58 Dist: "disttt", 59 Release: config.Release{ 60 GitHub: config.Repo{ 61 Owner: "goreleaser", 62 Name: "test", 63 }, 64 }, 65 Archive: config.Archive{ 66 Files: []string{ 67 "glob/*", 68 }, 69 }, 70 Builds: []config.Build{ 71 {Binary: "testreleaser"}, 72 {Goos: []string{"linux"}}, 73 { 74 Binary: "another", 75 Ignore: []config.IgnoredBuild{ 76 {Goos: "darwin", Goarch: "amd64"}, 77 }, 78 }, 79 }, 80 Dockers: []config.Docker{ 81 {Image: "a/b"}, 82 }, 83 }, 84 } 85 assert.NoError(t, Pipe{}.Run(ctx)) 86 assert.Len(t, ctx.Config.Archive.Files, 1) 87 assert.Equal(t, `bin.install "testreleaser"`, ctx.Config.Brew.Install) 88 assert.NotEmpty(t, ctx.Config.Dockers[0].Binary) 89 assert.NotEmpty(t, ctx.Config.Dockers[0].Goos) 90 assert.NotEmpty(t, ctx.Config.Dockers[0].Goarch) 91 assert.NotEmpty(t, ctx.Config.Dockers[0].Dockerfile) 92 assert.Empty(t, ctx.Config.Dockers[0].Goarm) 93 assert.Equal(t, "disttt", ctx.Config.Dist) 94 assert.NotEqual(t, "https://github.com", ctx.Config.GitHubURLs.Download) 95 }