2022-06-26 22:00:05 -03:00
|
|
|
package release
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-11-04 16:02:33 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/git"
|
2023-03-02 00:01:11 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testctx"
|
2022-06-26 22:00:05 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetupGitLab(t *testing.T) {
|
|
|
|
t.Run("no repo", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New()
|
2022-06-26 22:00:05 -03:00
|
|
|
require.NoError(t, setupGitLab(ctx))
|
2022-11-04 16:02:33 -03:00
|
|
|
repo, err := git.ExtractRepoFromConfig(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, repo.Owner, ctx.Config.Release.GitLab.Owner)
|
|
|
|
require.Equal(t, repo.Name, ctx.Config.Release.GitLab.Name)
|
2022-06-26 22:00:05 -03:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with templates", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-06-26 22:00:05 -03:00
|
|
|
Env: []string{"NAME=foo", "OWNER=bar"},
|
2022-09-11 14:28:50 -03:00
|
|
|
GitLabURLs: config.GitLabURLs{
|
|
|
|
Download: "https://{{ .Env.OWNER }}/download",
|
|
|
|
},
|
2022-06-26 22:00:05 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitLab: config.Repo{
|
|
|
|
Owner: "{{.Env.OWNER}}",
|
|
|
|
Name: "{{.Env.NAME}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, setupGitLab(ctx))
|
|
|
|
require.Equal(t, "bar", ctx.Config.Release.GitLab.Owner)
|
|
|
|
require.Equal(t, "foo", ctx.Config.Release.GitLab.Name)
|
2022-09-11 14:28:50 -03:00
|
|
|
require.Equal(t, "https://bar/download/bar/foo/-/releases/", ctx.ReleaseURL)
|
2022-06-26 22:00:05 -03:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with invalid templates", func(t *testing.T) {
|
|
|
|
t.Run("owner", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-06-26 22:00:05 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitLab: config.Repo{
|
|
|
|
Name: "foo",
|
|
|
|
Owner: "{{.Env.NOPE}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, setupGitLab(ctx))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("name", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-06-26 22:00:05 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitLab: config.Repo{
|
|
|
|
Name: "{{.Env.NOPE}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, setupGitLab(ctx))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetupGitea(t *testing.T) {
|
|
|
|
t.Run("no repo", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New()
|
2022-06-26 22:00:05 -03:00
|
|
|
require.NoError(t, setupGitea(ctx))
|
|
|
|
require.Equal(t, "goreleaser", ctx.Config.Release.Gitea.Owner)
|
|
|
|
require.Equal(t, "goreleaser", ctx.Config.Release.Gitea.Name)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with templates", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-06-26 22:00:05 -03:00
|
|
|
Env: []string{"NAME=foo", "OWNER=bar"},
|
2022-09-11 14:28:50 -03:00
|
|
|
GiteaURLs: config.GiteaURLs{
|
|
|
|
Download: "https://{{ .Env.OWNER }}/download",
|
|
|
|
},
|
2022-06-26 22:00:05 -03:00
|
|
|
Release: config.Release{
|
|
|
|
Gitea: config.Repo{
|
|
|
|
Owner: "{{.Env.OWNER}}",
|
|
|
|
Name: "{{.Env.NAME}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, setupGitea(ctx))
|
|
|
|
require.Equal(t, "bar", ctx.Config.Release.Gitea.Owner)
|
|
|
|
require.Equal(t, "foo", ctx.Config.Release.Gitea.Name)
|
2022-09-11 14:28:50 -03:00
|
|
|
require.Equal(t, "https://bar/download/bar/foo/releases/tag/", ctx.ReleaseURL)
|
2022-06-26 22:00:05 -03:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with invalid templates", func(t *testing.T) {
|
|
|
|
t.Run("owner", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-06-26 22:00:05 -03:00
|
|
|
Release: config.Release{
|
|
|
|
Gitea: config.Repo{
|
|
|
|
Name: "foo",
|
|
|
|
Owner: "{{.Env.NOPE}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, setupGitea(ctx))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("name", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-06-26 22:00:05 -03:00
|
|
|
Release: config.Release{
|
|
|
|
Gitea: config.Repo{
|
|
|
|
Name: "{{.Env.NOPE}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, setupGitea(ctx))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetupGitHub(t *testing.T) {
|
|
|
|
t.Run("no repo", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New()
|
2022-06-26 22:00:05 -03:00
|
|
|
require.NoError(t, setupGitHub(ctx))
|
|
|
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
|
|
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with templates", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-06-26 22:00:05 -03:00
|
|
|
Env: []string{"NAME=foo", "OWNER=bar"},
|
2022-09-11 14:28:50 -03:00
|
|
|
GitHubURLs: config.GitHubURLs{
|
|
|
|
Download: "https://{{ .Env.OWNER }}/download",
|
|
|
|
},
|
2022-06-26 22:00:05 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "{{.Env.OWNER}}",
|
|
|
|
Name: "{{.Env.NAME}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, setupGitHub(ctx))
|
|
|
|
require.Equal(t, "bar", ctx.Config.Release.GitHub.Owner)
|
|
|
|
require.Equal(t, "foo", ctx.Config.Release.GitHub.Name)
|
2022-09-11 14:28:50 -03:00
|
|
|
require.Equal(t, "https://bar/download/bar/foo/releases/tag/", ctx.ReleaseURL)
|
2022-06-26 22:00:05 -03:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with invalid templates", func(t *testing.T) {
|
|
|
|
t.Run("owner", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-06-26 22:00:05 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Name: "foo",
|
|
|
|
Owner: "{{.Env.NOPE}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, setupGitHub(ctx))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("name", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-06-26 22:00:05 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Name: "{{.Env.NOPE}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, setupGitHub(ctx))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|