mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-19 20:57:53 +02:00
alternative to #3806 the idea is that both `context.New` and `context.Context{}` are never used in tests. not sure yet how much I like it, so far code does look a bit more readable though. --------- Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package project
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/testctx"
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
)
|
|
|
|
func TestCustomProjectName(t *testing.T) {
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
ProjectName: "foo",
|
|
Release: config.Release{
|
|
GitHub: config.Repo{
|
|
Owner: "bar",
|
|
Name: "bar",
|
|
},
|
|
},
|
|
})
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Equal(t, "foo", ctx.Config.ProjectName)
|
|
}
|
|
|
|
func TestEmptyProjectName_DefaultsToGitHubRelease(t *testing.T) {
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
Release: config.Release{
|
|
GitHub: config.Repo{
|
|
Owner: "bar",
|
|
Name: "bar",
|
|
},
|
|
},
|
|
})
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Equal(t, "bar", ctx.Config.ProjectName)
|
|
}
|
|
|
|
func TestEmptyProjectName_DefaultsToGitLabRelease(t *testing.T) {
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
Release: config.Release{
|
|
GitLab: config.Repo{
|
|
Owner: "bar",
|
|
Name: "bar",
|
|
},
|
|
},
|
|
})
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Equal(t, "bar", ctx.Config.ProjectName)
|
|
}
|
|
|
|
func TestEmptyProjectName_DefaultsToGiteaRelease(t *testing.T) {
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
Release: config.Release{
|
|
Gitea: config.Repo{
|
|
Owner: "bar",
|
|
Name: "bar",
|
|
},
|
|
},
|
|
})
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Equal(t, "bar", ctx.Config.ProjectName)
|
|
}
|
|
|
|
func TestEmptyProjectNameAndRelease(t *testing.T) {
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
Release: config.Release{
|
|
GitHub: config.Repo{},
|
|
},
|
|
})
|
|
require.EqualError(t, Pipe{}.Default(ctx), "couldn't guess project_name, please add it to your config")
|
|
}
|