mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-11 13:38:41 +02:00
If all other strategies fail, try to infer the `package_name` property from the `go.mod` file, using its last segment as the actual package name. This is not perfect, but usually this will only be used when running against a new project, with no git url, empty/default config, etc... so, in reality, it'll rarely be used. closes #3825 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
package project
|
|
|
|
import (
|
|
"os/exec"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/testctx"
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
)
|
|
|
|
func TestCustomProjectName(t *testing.T) {
|
|
_ = testlib.Mktmp(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) {
|
|
_ = testlib.Mktmp(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) {
|
|
_ = testlib.Mktmp(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) {
|
|
_ = testlib.Mktmp(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 TestEmptyProjectName_DefaultsToGoModPath(t *testing.T) {
|
|
_ = testlib.Mktmp(t)
|
|
ctx := testctx.New()
|
|
require.NoError(t, exec.Command("go", "mod", "init", "github.com/foo/bar").Run())
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Equal(t, "bar", ctx.Config.ProjectName)
|
|
}
|
|
|
|
func TestEmptyProjectNameAndRelease(t *testing.T) {
|
|
_ = testlib.Mktmp(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")
|
|
}
|