1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/pipe/milestone/milestone_test.go
Carlos Alexandro Becker 61bead8989
feat: improve output and pipe skipping (#2480)
* refactor: improve middleware

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: upload tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: twitter tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: source tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: snapshot tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: improved some tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: snapcraft skip

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip slack

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip sign

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip scoop

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip reddit

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip discord

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip publish

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip nfpm

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip milestone

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip custompublishers

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip checksums

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip changelog

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip brew

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip blob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip before

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip artifactory

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip announce

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip defaults

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: cmds

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip docker

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* chore: todo

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: go.mod

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip release

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: remove old skip pipe errors

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip teams

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip brew

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix/test: skip smtp

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: lint issues

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip docker

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip brew and scoop

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip docker

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip http/artifactory

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: increase coverage

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: fix

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2021-09-18 10:21:29 -03:00

241 lines
5.8 KiB
Go

package milestone
import (
"errors"
"os"
"testing"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/require"
)
func TestDefaultWithRepoConfig(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "git@github.com:githubowner/githubrepo.git")
ctx := &context.Context{
Config: config.Project{
Milestones: []config.Milestone{
{
Repo: config.Repo{
Name: "configrepo",
Owner: "configowner",
},
},
},
},
}
ctx.TokenType = context.TokenTypeGitHub
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)
}
func TestDefaultWithRepoRemote(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "git@github.com:githubowner/githubrepo.git")
ctx := context.New(config.Project{
Milestones: []config.Milestone{{}},
})
ctx.TokenType = context.TokenTypeGitHub
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)
}
func TestDefaultWithNameTemplate(t *testing.T) {
ctx := &context.Context{
Config: config.Project{
Milestones: []config.Milestone{
{
NameTemplate: "confignametemplate",
},
},
},
}
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "confignametemplate", ctx.Config.Milestones[0].NameTemplate)
}
func TestDefaultWithoutGitRepo(t *testing.T) {
testlib.Mktmp(t)
ctx := &context.Context{
Config: config.Project{
Milestones: []config.Milestone{{}},
},
}
ctx.TokenType = context.TokenTypeGitHub
require.EqualError(t, Pipe{}.Default(ctx), "current folder is not a git repository")
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
}
func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
testlib.Mktmp(t)
ctx := &context.Context{
Config: config.Project{
Milestones: []config.Milestone{{}},
},
}
ctx.TokenType = context.TokenTypeGitHub
testlib.GitInit(t)
require.EqualError(t, Pipe{}.Default(ctx), "no remote configured to list refs from")
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
}
func TestDefaultWithoutGitRepoSnapshot(t *testing.T) {
testlib.Mktmp(t)
ctx := &context.Context{
Config: config.Project{
Milestones: []config.Milestone{{}},
},
}
ctx.TokenType = context.TokenTypeGitHub
ctx.Snapshot = true
require.NoError(t, Pipe{}.Default(ctx))
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
}
func TestDefaultWithoutNameTemplate(t *testing.T) {
ctx := &context.Context{
Config: config.Project{
Milestones: []config.Milestone{{}},
},
}
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "{{ .Tag }}", ctx.Config.Milestones[0].NameTemplate)
}
func TestString(t *testing.T) {
require.NotEmpty(t, Pipe{}.String())
}
func TestPublishCloseDisabled(t *testing.T) {
ctx := context.New(config.Project{
Milestones: []config.Milestone{
{
Close: false,
},
},
})
client := &DummyClient{}
testlib.AssertSkipped(t, doPublish(ctx, client))
require.Equal(t, "", client.ClosedMilestone)
}
func TestPublishCloseEnabled(t *testing.T) {
ctx := context.New(config.Project{
Milestones: []config.Milestone{
{
Close: true,
NameTemplate: defaultNameTemplate,
Repo: config.Repo{
Name: "configrepo",
Owner: "configowner",
},
},
},
})
ctx.Git.CurrentTag = "v1.0.0"
client := &DummyClient{}
require.NoError(t, doPublish(ctx, client))
require.Equal(t, "v1.0.0", client.ClosedMilestone)
}
func TestPublishCloseError(t *testing.T) {
config := config.Project{
Milestones: []config.Milestone{
{
Close: true,
NameTemplate: defaultNameTemplate,
Repo: config.Repo{
Name: "configrepo",
Owner: "configowner",
},
},
},
}
ctx := context.New(config)
ctx.Git.CurrentTag = "v1.0.0"
client := &DummyClient{
FailToCloseMilestone: true,
}
require.NoError(t, doPublish(ctx, client))
require.Equal(t, "", client.ClosedMilestone)
}
func TestPublishCloseFailOnError(t *testing.T) {
config := config.Project{
Milestones: []config.Milestone{
{
Close: true,
FailOnError: true,
NameTemplate: defaultNameTemplate,
Repo: config.Repo{
Name: "configrepo",
Owner: "configowner",
},
},
},
}
ctx := context.New(config)
ctx.Git.CurrentTag = "v1.0.0"
client := &DummyClient{
FailToCloseMilestone: true,
}
require.Error(t, doPublish(ctx, client))
require.Equal(t, "", client.ClosedMilestone)
}
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))
})
}
type DummyClient struct {
ClosedMilestone string
FailToCloseMilestone bool
}
func (c *DummyClient) CloseMilestone(ctx *context.Context, repo client.Repo, title string) error {
if c.FailToCloseMilestone {
return errors.New("milestone failed")
}
c.ClosedMilestone = title
return nil
}
func (c *DummyClient) CreateRelease(ctx *context.Context, body string) (string, error) {
return "", nil
}
func (c *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
return "", nil
}
func (c *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo client.Repo, content []byte, path, msg string) error {
return nil
}
func (c *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) error {
return nil
}