2020-04-28 02:42:44 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRelease(t *testing.T) {
|
2020-12-12 18:27:35 +02:00
|
|
|
setup(t)
|
2021-04-25 19:20:49 +02:00
|
|
|
cmd := newReleaseCmd()
|
2020-04-28 02:42:44 +02:00
|
|
|
cmd.cmd.SetArgs([]string{"--snapshot", "--timeout=1m", "--parallelism=2", "--deprecated"})
|
|
|
|
require.NoError(t, cmd.cmd.Execute())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReleaseInvalidConfig(t *testing.T) {
|
2020-12-12 18:27:35 +02:00
|
|
|
setup(t)
|
2020-04-28 02:42:44 +02:00
|
|
|
createFile(t, "goreleaser.yml", "foo: bar")
|
2021-04-25 19:20:49 +02:00
|
|
|
cmd := newReleaseCmd()
|
2020-04-28 02:42:44 +02:00
|
|
|
cmd.cmd.SetArgs([]string{"--snapshot", "--timeout=1m", "--parallelism=2", "--deprecated"})
|
|
|
|
require.EqualError(t, cmd.cmd.Execute(), "yaml: unmarshal errors:\n line 1: field foo not found in type config.Project")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReleaseBrokenProject(t *testing.T) {
|
2020-12-12 18:27:35 +02:00
|
|
|
setup(t)
|
2020-04-28 02:42:44 +02:00
|
|
|
createFile(t, "main.go", "not a valid go file")
|
2021-04-25 19:20:49 +02:00
|
|
|
cmd := newReleaseCmd()
|
2020-04-28 02:42:44 +02:00
|
|
|
cmd.cmd.SetArgs([]string{"--snapshot", "--timeout=1m", "--parallelism=2"})
|
|
|
|
require.EqualError(t, cmd.cmd.Execute(), "failed to parse dir: .: main.go:1:1: expected 'package', found not")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReleaseFlags(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
setup := func(opts releaseOpts) *context.Context {
|
2020-05-15 16:19:20 +02:00
|
|
|
return setupReleaseContext(context.New(config.Project{}), opts)
|
2020-04-28 02:42:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("snapshot", func(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := setup(releaseOpts{
|
2020-04-28 02:42:44 +02:00
|
|
|
snapshot: true,
|
|
|
|
})
|
|
|
|
require.True(t, ctx.Snapshot)
|
|
|
|
require.True(t, ctx.SkipPublish)
|
2021-05-25 05:45:59 +02:00
|
|
|
require.True(t, ctx.SkipValidate)
|
|
|
|
require.True(t, ctx.SkipAnnounce)
|
2020-04-28 02:42:44 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("skips", func(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := setup(releaseOpts{
|
2020-04-28 02:42:44 +02:00
|
|
|
skipPublish: true,
|
|
|
|
skipSign: true,
|
|
|
|
skipValidate: true,
|
|
|
|
})
|
|
|
|
require.True(t, ctx.SkipSign)
|
|
|
|
require.True(t, ctx.SkipPublish)
|
2021-05-25 05:45:59 +02:00
|
|
|
require.True(t, ctx.SkipValidate)
|
|
|
|
require.True(t, ctx.SkipAnnounce)
|
2020-04-28 02:42:44 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("parallelism", func(t *testing.T) {
|
|
|
|
require.Equal(t, 1, setup(releaseOpts{
|
|
|
|
parallelism: 1,
|
|
|
|
}).Parallelism)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("notes", func(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
notes := "foo.md"
|
|
|
|
header := "header.md"
|
|
|
|
footer := "footer.md"
|
|
|
|
ctx := setup(releaseOpts{
|
2021-05-22 02:07:47 +02:00
|
|
|
releaseNotesFile: notes,
|
|
|
|
releaseHeaderFile: header,
|
|
|
|
releaseFooterFile: footer,
|
2020-04-28 02:42:44 +02:00
|
|
|
})
|
2021-05-22 02:07:47 +02:00
|
|
|
require.Equal(t, notes, ctx.ReleaseNotesFile)
|
|
|
|
require.Equal(t, header, ctx.ReleaseHeaderFile)
|
|
|
|
require.Equal(t, footer, ctx.ReleaseFooterFile)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("templated notes", func(t *testing.T) {
|
|
|
|
notes := "foo.md"
|
|
|
|
header := "header.md"
|
|
|
|
footer := "footer.md"
|
|
|
|
ctx := setup(releaseOpts{
|
|
|
|
releaseNotesTmpl: notes,
|
|
|
|
releaseHeaderTmpl: header,
|
|
|
|
releaseFooterTmpl: footer,
|
|
|
|
})
|
|
|
|
require.Equal(t, notes, ctx.ReleaseNotesTmpl)
|
|
|
|
require.Equal(t, header, ctx.ReleaseHeaderTmpl)
|
|
|
|
require.Equal(t, footer, ctx.ReleaseFooterTmpl)
|
2020-04-28 02:42:44 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("rm dist", func(t *testing.T) {
|
|
|
|
require.True(t, setup(releaseOpts{
|
|
|
|
rmDist: true,
|
|
|
|
}).RmDist)
|
|
|
|
})
|
|
|
|
}
|