1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00
Carlos Alexandro Becker ec2db4a727
feat!: rename module to /v2 (#4894)
<!--

Hi, thanks for contributing!

Please make sure you read our CONTRIBUTING guide.

Also, add tests and the respective documentation changes as well.

-->


<!-- If applied, this commit will... -->

...

<!-- Why is this change being made? -->

...

<!-- # Provide links to any relevant tickets, URLs or other resources
-->

...

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-05-26 15:02:57 -03:00

181 lines
4.4 KiB
Go

package release
import (
"testing"
"github.com/goreleaser/goreleaser/v2/internal/git"
"github.com/goreleaser/goreleaser/v2/internal/testctx"
"github.com/goreleaser/goreleaser/v2/pkg/config"
"github.com/stretchr/testify/require"
)
func TestSetupGitLab(t *testing.T) {
t.Run("no repo", func(t *testing.T) {
ctx := testctx.New()
require.NoError(t, setupGitLab(ctx))
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)
})
t.Run("with templates", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Env: []string{"NAME=foo", "OWNER=bar"},
GitLabURLs: config.GitLabURLs{
Download: "https://{{ .Env.OWNER }}/download",
},
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)
require.Equal(t, "https://bar/download/bar/foo/-/releases/", ctx.ReleaseURL)
})
t.Run("with invalid templates", func(t *testing.T) {
t.Run("owner", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Release: config.Release{
GitLab: config.Repo{
Name: "foo",
Owner: "{{.Env.NOPE}}",
},
},
})
require.Error(t, setupGitLab(ctx))
})
t.Run("name", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
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) {
ctx := testctx.New()
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) {
ctx := testctx.NewWithCfg(config.Project{
Env: []string{"NAME=foo", "OWNER=bar"},
GiteaURLs: config.GiteaURLs{
Download: "https://{{ .Env.OWNER }}/download",
},
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)
require.Equal(t, "https://bar/download/bar/foo/releases/tag/", ctx.ReleaseURL)
})
t.Run("with invalid templates", func(t *testing.T) {
t.Run("owner", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Release: config.Release{
Gitea: config.Repo{
Name: "foo",
Owner: "{{.Env.NOPE}}",
},
},
})
require.Error(t, setupGitea(ctx))
})
t.Run("name", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
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) {
ctx := testctx.New()
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) {
ctx := testctx.NewWithCfg(config.Project{
Env: []string{"NAME=foo", "OWNER=bar"},
GitHubURLs: config.GitHubURLs{
Download: "https://{{ .Env.OWNER }}/download",
},
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)
require.Equal(t, "https://bar/download/bar/foo/releases/tag/", ctx.ReleaseURL)
})
t.Run("with invalid templates", func(t *testing.T) {
t.Run("owner", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Release: config.Release{
GitHub: config.Repo{
Name: "foo",
Owner: "{{.Env.NOPE}}",
},
},
})
require.Error(t, setupGitHub(ctx))
})
t.Run("name", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Release: config.Release{
GitHub: config.Repo{
Name: "{{.Env.NOPE}}",
},
},
})
require.Error(t, setupGitHub(ctx))
})
})
}