2018-03-12 08:42:31 -03:00
|
|
|
package project
|
|
|
|
|
|
|
|
import (
|
2023-03-03 09:50:02 -03:00
|
|
|
"os/exec"
|
2018-03-12 08:42:31 -03:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2023-03-02 00:01:11 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testctx"
|
2023-03-03 09:50:02 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
2018-08-14 23:50:20 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
2018-03-12 08:42:31 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCustomProjectName(t *testing.T) {
|
2023-03-03 09:50:02 -03:00
|
|
|
_ = testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2018-03-12 08:42:31 -03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-02-26 12:38:07 +00:00
|
|
|
func TestEmptyProjectName_DefaultsToGitHubRelease(t *testing.T) {
|
2023-03-03 09:50:02 -03:00
|
|
|
_ = testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2018-03-12 08:42:31 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "bar",
|
|
|
|
Name: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "bar", ctx.Config.ProjectName)
|
|
|
|
}
|
2020-02-26 12:38:07 +00:00
|
|
|
|
|
|
|
func TestEmptyProjectName_DefaultsToGitLabRelease(t *testing.T) {
|
2023-03-03 09:50:02 -03:00
|
|
|
_ = testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2020-02-26 12:38:07 +00:00
|
|
|
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) {
|
2023-03-03 09:50:02 -03:00
|
|
|
_ = testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2020-02-26 12:38:07 +00:00
|
|
|
Release: config.Release{
|
|
|
|
Gitea: config.Repo{
|
|
|
|
Owner: "bar",
|
|
|
|
Name: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "bar", ctx.Config.ProjectName)
|
|
|
|
}
|
2020-03-04 16:03:05 -03:00
|
|
|
|
2023-03-03 09:50:02 -03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-03-04 16:03:05 -03:00
|
|
|
func TestEmptyProjectNameAndRelease(t *testing.T) {
|
2023-03-03 09:50:02 -03:00
|
|
|
_ = testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2020-03-04 16:03:05 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.EqualError(t, Pipe{}.Default(ctx), "couldn't guess project_name, please add it to your config")
|
|
|
|
}
|