2017-01-14 18:29:01 +02:00
|
|
|
package defaults
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-10-15 21:46:21 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
2018-08-15 04:50:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2020-10-06 14:48:04 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-01-14 18:29:01 +02:00
|
|
|
)
|
|
|
|
|
2017-03-26 01:43:42 +02:00
|
|
|
func TestDescription(t *testing.T) {
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
2017-03-26 01:43:42 +02:00
|
|
|
}
|
|
|
|
|
2017-01-14 18:29:01 +02:00
|
|
|
func TestFillBasicData(t *testing.T) {
|
2020-12-12 18:27:35 +02:00
|
|
|
testlib.Mktmp(t)
|
2017-10-15 21:46:21 +02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
|
|
|
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := &context.Context{
|
2019-08-13 20:28:03 +02:00
|
|
|
TokenType: context.TokenTypeGitHub,
|
|
|
|
Config: config.Project{},
|
2017-01-14 18:29:01 +02:00
|
|
|
}
|
|
|
|
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
|
|
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
|
|
|
require.NotEmpty(t, ctx.Config.Builds)
|
|
|
|
require.Equal(t, "goreleaser", ctx.Config.Builds[0].Binary)
|
|
|
|
require.Equal(t, ".", ctx.Config.Builds[0].Main)
|
|
|
|
require.Contains(t, ctx.Config.Builds[0].Goos, "darwin")
|
|
|
|
require.Contains(t, ctx.Config.Builds[0].Goos, "linux")
|
|
|
|
require.Contains(t, ctx.Config.Builds[0].Goarch, "386")
|
|
|
|
require.Contains(t, ctx.Config.Builds[0].Goarch, "amd64")
|
|
|
|
require.Equal(t, "tar.gz", ctx.Config.Archives[0].Format)
|
|
|
|
require.Empty(t, ctx.Config.Dockers)
|
|
|
|
require.Equal(t, "https://github.com", ctx.Config.GitHubURLs.Download)
|
|
|
|
require.NotEmpty(t, ctx.Config.Archives[0].NameTemplate)
|
|
|
|
require.NotEmpty(t, ctx.Config.Builds[0].Ldflags)
|
|
|
|
require.NotEmpty(t, ctx.Config.Archives[0].Files)
|
|
|
|
require.NotEmpty(t, ctx.Config.Dist)
|
2017-01-14 18:38:48 +02:00
|
|
|
}
|
|
|
|
|
2017-05-01 14:59:18 +02:00
|
|
|
func TestFillPartial(t *testing.T) {
|
2020-12-12 18:27:35 +02:00
|
|
|
testlib.Mktmp(t)
|
2017-10-15 21:46:21 +02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
2017-05-01 14:59:18 +02:00
|
|
|
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := &context.Context{
|
2017-05-01 14:59:18 +02:00
|
|
|
Config: config.Project{
|
2018-02-15 04:08:28 +02:00
|
|
|
GitHubURLs: config.GitHubURLs{
|
|
|
|
Download: "https://github.company.com",
|
|
|
|
},
|
2017-11-27 01:25:51 +02:00
|
|
|
Dist: "disttt",
|
2017-05-01 14:59:18 +02:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "goreleaser",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{
|
2021-07-22 03:09:02 +02:00
|
|
|
Files: []config.File{
|
|
|
|
{Source: "glob/*"},
|
2019-12-29 20:02:15 +02:00
|
|
|
},
|
2017-01-18 19:08:48 +02:00
|
|
|
},
|
2017-01-14 23:52:39 +02:00
|
|
|
},
|
2017-07-02 02:13:02 +02:00
|
|
|
Builds: []config.Build{
|
2019-06-28 13:52:10 +02:00
|
|
|
{
|
|
|
|
ID: "build1",
|
|
|
|
Binary: "testreleaser",
|
|
|
|
},
|
2017-07-02 03:06:40 +02:00
|
|
|
{Goos: []string{"linux"}},
|
|
|
|
{
|
2019-06-28 13:52:10 +02:00
|
|
|
ID: "build3",
|
2017-07-02 03:06:40 +02:00
|
|
|
Binary: "another",
|
|
|
|
Ignore: []config.IgnoredBuild{
|
|
|
|
{Goos: "darwin", Goarch: "amd64"},
|
|
|
|
},
|
|
|
|
},
|
2017-07-02 02:13:02 +02:00
|
|
|
},
|
2017-09-12 05:49:02 +02:00
|
|
|
Dockers: []config.Docker{
|
2019-01-11 20:27:39 +02:00
|
|
|
{
|
|
|
|
ImageTemplates: []string{"a/b"},
|
|
|
|
},
|
2017-09-12 05:49:02 +02:00
|
|
|
},
|
2020-01-26 23:36:01 +02:00
|
|
|
Brews: []config.Homebrew{
|
|
|
|
{
|
|
|
|
Description: "foo",
|
|
|
|
},
|
|
|
|
},
|
2017-01-14 18:38:48 +02:00
|
|
|
},
|
|
|
|
}
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Len(t, ctx.Config.Archives[0].Files, 1)
|
|
|
|
require.NotEmpty(t, ctx.Config.Dockers[0].Goos)
|
|
|
|
require.NotEmpty(t, ctx.Config.Dockers[0].Goarch)
|
|
|
|
require.NotEmpty(t, ctx.Config.Dockers[0].Dockerfile)
|
|
|
|
require.Empty(t, ctx.Config.Dockers[0].Goarm)
|
|
|
|
require.Equal(t, "disttt", ctx.Config.Dist)
|
|
|
|
require.NotEqual(t, "https://github.com", ctx.Config.GitHubURLs.Download)
|
2020-11-21 15:36:29 +02:00
|
|
|
|
|
|
|
ctx = &context.Context{
|
|
|
|
TokenType: context.TokenTypeGitea,
|
|
|
|
|
|
|
|
Config: config.Project{
|
|
|
|
GiteaURLs: config.GiteaURLs{
|
|
|
|
API: "https://gitea.com/api/v1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Equal(t, "https://gitea.com", ctx.Config.GiteaURLs.Download)
|
2017-01-14 18:38:48 +02:00
|
|
|
}
|
2021-09-09 03:42:13 +02:00
|
|
|
|
|
|
|
func TestGiteaTemplateDownloadURL(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
apiURL string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "string_url",
|
|
|
|
apiURL: "https://gitea.com/api/v1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "download_url_template",
|
|
|
|
apiURL: "{{ .Env.GORELEASER_TEST_GITEA_URLS_API }}",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "download_url_template_invalid_value",
|
|
|
|
apiURL: "{{ .Env.GORELEASER_NOT_EXISTS }}",
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "download_url_template_invalid",
|
|
|
|
apiURL: "{{.dddddddddd",
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
ctx := &context.Context{
|
|
|
|
TokenType: context.TokenTypeGitea,
|
|
|
|
Env: context.Env{
|
|
|
|
"GORELEASER_TEST_GITEA_URLS_API": "https://gitea.com/api/v1",
|
|
|
|
},
|
|
|
|
Config: config.Project{
|
|
|
|
GiteaURLs: config.GiteaURLs{
|
|
|
|
API: tt.apiURL,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err := Pipe{}.Run(ctx)
|
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "https://gitea.com", ctx.Config.GiteaURLs.Download)
|
|
|
|
}
|
|
|
|
}
|