2020-07-09 22:40:37 +02:00
|
|
|
package milestone
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/internal/client"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2020-10-06 14:48:04 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-07-09 22:40:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDefaultWithRepoConfig(t *testing.T) {
|
2020-12-12 18:27:35 +02:00
|
|
|
testlib.Mktmp(t)
|
2020-07-09 22:40:37 +02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:githubowner/githubrepo.git")
|
|
|
|
|
2022-04-12 13:35:19 +02:00
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
Repo: config.Repo{
|
|
|
|
Name: "configrepo",
|
|
|
|
Owner: "configowner",
|
2020-07-09 22:40:37 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-04-12 13:35:19 +02:00
|
|
|
})
|
2020-07-09 22:40:37 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2020-10-06 14:48:04 +02: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 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultWithRepoRemote(t *testing.T) {
|
2020-12-12 18:27:35 +02:00
|
|
|
testlib.Mktmp(t)
|
2020-07-09 22:40:37 +02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:githubowner/githubrepo.git")
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Milestones: []config.Milestone{{}},
|
|
|
|
})
|
2020-07-09 22:40:37 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2020-10-06 14:48:04 +02: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 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultWithNameTemplate(t *testing.T) {
|
2022-04-12 13:35:19 +02:00
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
NameTemplate: "confignametemplate",
|
2020-07-09 22:40:37 +02:00
|
|
|
},
|
|
|
|
},
|
2022-04-12 13:35:19 +02:00
|
|
|
})
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "confignametemplate", ctx.Config.Milestones[0].NameTemplate)
|
2020-07-09 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultWithoutGitRepo(t *testing.T) {
|
2020-12-12 18:27:35 +02:00
|
|
|
testlib.Mktmp(t)
|
2022-04-12 13:35:19 +02:00
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Milestones: []config.Milestone{{}},
|
|
|
|
})
|
2020-07-09 22:40:37 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2020-10-06 14:48:04 +02: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 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
|
2020-12-12 18:27:35 +02:00
|
|
|
testlib.Mktmp(t)
|
2022-04-12 13:35:19 +02:00
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Milestones: []config.Milestone{{}},
|
|
|
|
})
|
2020-07-09 22:40:37 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
|
|
testlib.GitInit(t)
|
2021-09-15 21:12:45 +02:00
|
|
|
require.EqualError(t, Pipe{}.Default(ctx), "no remote configured to list refs from")
|
2020-10-06 14:48:04 +02:00
|
|
|
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
2020-07-09 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultWithoutGitRepoSnapshot(t *testing.T) {
|
2020-12-12 18:27:35 +02:00
|
|
|
testlib.Mktmp(t)
|
2022-04-12 13:35:19 +02:00
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Milestones: []config.Milestone{{}},
|
|
|
|
})
|
2020-07-09 22:40:37 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
|
|
ctx.Snapshot = true
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
2020-07-09 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultWithoutNameTemplate(t *testing.T) {
|
2022-04-12 13:35:19 +02:00
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Milestones: []config.Milestone{{}},
|
|
|
|
})
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "{{ .Tag }}", ctx.Config.Milestones[0].NameTemplate)
|
2020-07-09 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestString(t *testing.T) {
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
2020-07-09 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublishCloseDisabled(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := context.New(config.Project{
|
2020-07-09 22:40:37 +02:00
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
Close: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2021-10-06 01:53:17 +02:00
|
|
|
client := client.NewMock()
|
2020-07-09 22:40:37 +02:00
|
|
|
testlib.AssertSkipped(t, doPublish(ctx, client))
|
2020-10-06 14:48:04 +02:00
|
|
|
require.Equal(t, "", client.ClosedMilestone)
|
2020-07-09 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublishCloseEnabled(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := context.New(config.Project{
|
2020-07-09 22:40:37 +02:00
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
Close: true,
|
|
|
|
NameTemplate: defaultNameTemplate,
|
|
|
|
Repo: config.Repo{
|
|
|
|
Name: "configrepo",
|
|
|
|
Owner: "configowner",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Git.CurrentTag = "v1.0.0"
|
2021-10-06 01:53:17 +02:00
|
|
|
client := client.NewMock()
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, doPublish(ctx, client))
|
|
|
|
require.Equal(t, "v1.0.0", client.ClosedMilestone)
|
2020-07-09 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublishCloseError(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
config := config.Project{
|
2020-07-09 22:40:37 +02:00
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
Close: true,
|
|
|
|
NameTemplate: defaultNameTemplate,
|
|
|
|
Repo: config.Repo{
|
|
|
|
Name: "configrepo",
|
|
|
|
Owner: "configowner",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := context.New(config)
|
2020-07-09 22:40:37 +02:00
|
|
|
ctx.Git.CurrentTag = "v1.0.0"
|
2021-10-06 01:53:17 +02:00
|
|
|
client := &client.Mock{
|
2020-07-09 22:40:37 +02:00
|
|
|
FailToCloseMilestone: true,
|
|
|
|
}
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, doPublish(ctx, client))
|
|
|
|
require.Equal(t, "", client.ClosedMilestone)
|
2020-07-09 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublishCloseFailOnError(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
config := config.Project{
|
2020-07-09 22:40:37 +02:00
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{
|
|
|
|
Close: true,
|
|
|
|
FailOnError: true,
|
|
|
|
NameTemplate: defaultNameTemplate,
|
|
|
|
Repo: config.Repo{
|
|
|
|
Name: "configrepo",
|
|
|
|
Owner: "configowner",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := context.New(config)
|
2020-07-09 22:40:37 +02:00
|
|
|
ctx.Git.CurrentTag = "v1.0.0"
|
2021-10-06 01:53:17 +02:00
|
|
|
client := &client.Mock{
|
2020-07-09 22:40:37 +02:00
|
|
|
FailToCloseMilestone: true,
|
|
|
|
}
|
2020-10-06 14:48:04 +02:00
|
|
|
require.Error(t, doPublish(ctx, client))
|
|
|
|
require.Equal(t, "", client.ClosedMilestone)
|
2020-07-09 22:40:37 +02:00
|
|
|
}
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
func TestSkip(t *testing.T) {
|
|
|
|
t.Run("skip", func(t *testing.T) {
|
|
|
|
require.True(t, Pipe{}.Skip(context.New(config.Project{})))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("dont skip", func(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Milestones: []config.Milestone{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.False(t, Pipe{}.Skip(ctx))
|
|
|
|
})
|
|
|
|
}
|