2020-07-09 16:40:37 -04:00
|
|
|
package milestone
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-05-26 15:02:57 -03:00
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/client"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/testctx"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/testlib"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/pkg/config"
|
2020-10-06 09:48:04 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-07-09 16:40:37 -04:00
|
|
|
)
|
|
|
|
|
2023-06-20 09:33:59 -03:00
|
|
|
func TestContinueOnError(t *testing.T) {
|
|
|
|
require.True(t, Pipe{}.ContinueOnError())
|
|
|
|
}
|
|
|
|
|
2020-07-09 16:40:37 -04:00
|
|
|
func TestDefaultWithRepoConfig(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2020-07-09 16:40:37 -04:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:githubowner/githubrepo.git")
|
|
|
|
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-04-12 08:35:19 -03:00
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
Repo: config.Repo{
|
|
|
|
Name: "configrepo",
|
|
|
|
Owner: "configowner",
|
2020-07-09 16:40:37 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-02 00:01:11 -03:00
|
|
|
}, testctx.GitHubTokenType)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "configrepo", ctx.Config.Milestones[0].Repo.Name)
|
|
|
|
require.Equal(t, "configowner", ctx.Config.Milestones[0].Repo.Owner)
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
2022-05-09 09:32:43 -03:00
|
|
|
|
|
|
|
func TestDefaultWithInvalidRemote(t *testing.T) {
|
|
|
|
testlib.Mktmp(t)
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:githubowner.git")
|
|
|
|
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-05-09 09:32:43 -03:00
|
|
|
Milestones: []config.Milestone{{}},
|
2023-03-02 00:01:11 -03:00
|
|
|
}, testctx.GitHubTokenType)
|
2022-05-09 09:32:43 -03:00
|
|
|
require.Error(t, Pipe{}.Default(ctx))
|
|
|
|
}
|
2020-07-09 16:40:37 -04:00
|
|
|
|
|
|
|
func TestDefaultWithRepoRemote(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2020-07-09 16:40:37 -04:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:githubowner/githubrepo.git")
|
|
|
|
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-18 10:21:29 -03:00
|
|
|
Milestones: []config.Milestone{{}},
|
2023-03-02 00:01:11 -03:00
|
|
|
}, testctx.GitHubTokenType)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "githubrepo", ctx.Config.Milestones[0].Repo.Name)
|
|
|
|
require.Equal(t, "githubowner", ctx.Config.Milestones[0].Repo.Owner)
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultWithNameTemplate(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-04-12 08:35:19 -03:00
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
NameTemplate: "confignametemplate",
|
2020-07-09 16:40:37 -04:00
|
|
|
},
|
|
|
|
},
|
2022-04-12 08:35:19 -03:00
|
|
|
})
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "confignametemplate", ctx.Config.Milestones[0].NameTemplate)
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultWithoutGitRepo(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-04-12 08:35:19 -03:00
|
|
|
Milestones: []config.Milestone{{}},
|
2023-03-02 00:01:11 -03:00
|
|
|
}, testctx.GitHubTokenType)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.EqualError(t, Pipe{}.Default(ctx), "current folder is not a git repository")
|
|
|
|
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-04-12 08:35:19 -03:00
|
|
|
Milestones: []config.Milestone{{}},
|
2023-03-02 00:01:11 -03:00
|
|
|
}, testctx.GitHubTokenType)
|
2020-07-09 16:40:37 -04:00
|
|
|
testlib.GitInit(t)
|
2021-09-15 22:12:45 +03:00
|
|
|
require.EqualError(t, Pipe{}.Default(ctx), "no remote configured to list refs from")
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultWithoutGitRepoSnapshot(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-04-12 08:35:19 -03:00
|
|
|
Milestones: []config.Milestone{{}},
|
2023-03-02 00:01:11 -03:00
|
|
|
}, testctx.GitHubTokenType, testctx.Snapshot)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultWithoutNameTemplate(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-04-12 08:35:19 -03:00
|
|
|
Milestones: []config.Milestone{{}},
|
|
|
|
})
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "{{ .Tag }}", ctx.Config.Milestones[0].NameTemplate)
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestString(t *testing.T) {
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublishCloseDisabled(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2020-07-09 16:40:37 -04:00
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
Close: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2021-10-05 20:53:17 -03:00
|
|
|
client := client.NewMock()
|
2020-07-09 16:40:37 -04:00
|
|
|
testlib.AssertSkipped(t, doPublish(ctx, client))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Equal(t, "", client.ClosedMilestone)
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublishCloseEnabled(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2020-07-09 16:40:37 -04:00
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
Close: true,
|
|
|
|
NameTemplate: defaultNameTemplate,
|
|
|
|
Repo: config.Repo{
|
|
|
|
Name: "configrepo",
|
|
|
|
Owner: "configowner",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-02 00:01:11 -03:00
|
|
|
}, testctx.WithCurrentTag("v1.0.0"))
|
2021-10-05 20:53:17 -03:00
|
|
|
client := client.NewMock()
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, doPublish(ctx, client))
|
|
|
|
require.Equal(t, "v1.0.0", client.ClosedMilestone)
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublishCloseError(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
config := config.Project{
|
2020-07-09 16:40:37 -04:00
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
Close: true,
|
|
|
|
NameTemplate: defaultNameTemplate,
|
|
|
|
Repo: config.Repo{
|
|
|
|
Name: "configrepo",
|
|
|
|
Owner: "configowner",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("v1.0.0"))
|
2021-10-05 20:53:17 -03:00
|
|
|
client := &client.Mock{
|
2020-07-09 16:40:37 -04:00
|
|
|
FailToCloseMilestone: true,
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, doPublish(ctx, client))
|
|
|
|
require.Equal(t, "", client.ClosedMilestone)
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublishCloseFailOnError(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
config := config.Project{
|
2020-07-09 16:40:37 -04:00
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
Close: true,
|
|
|
|
FailOnError: true,
|
|
|
|
NameTemplate: defaultNameTemplate,
|
|
|
|
Repo: config.Repo{
|
|
|
|
Name: "configrepo",
|
|
|
|
Owner: "configowner",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("v1.0.0"))
|
2021-10-05 20:53:17 -03:00
|
|
|
client := &client.Mock{
|
2020-07-09 16:40:37 -04:00
|
|
|
FailToCloseMilestone: true,
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Error(t, doPublish(ctx, client))
|
|
|
|
require.Equal(t, "", client.ClosedMilestone)
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
2021-09-18 10:21:29 -03:00
|
|
|
func TestSkip(t *testing.T) {
|
|
|
|
t.Run("skip", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
require.True(t, Pipe{}.Skip(testctx.New()))
|
2021-09-18 10:21:29 -03:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("dont skip", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-18 10:21:29 -03:00
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.False(t, Pipe{}.Skip(ctx))
|
|
|
|
})
|
|
|
|
}
|