mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-24 04:16:27 +02:00
ee17c9583d
* feat(ci): compile with go 1.19 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: fixing template test Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: improve check Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: more test and docs fixes Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: fix Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: fix * test: fix * fix: lint Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: docker templates Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: godoc for RequireTemplateError
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
package snapshot
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestStringer(t *testing.T) {
|
|
require.NotEmpty(t, Pipe{}.String())
|
|
}
|
|
|
|
func TestDefault(t *testing.T) {
|
|
ctx := &context.Context{
|
|
Config: config.Project{
|
|
Snapshot: config.Snapshot{},
|
|
},
|
|
}
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Equal(t, "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}", ctx.Config.Snapshot.NameTemplate)
|
|
}
|
|
|
|
func TestDefaultSet(t *testing.T) {
|
|
ctx := &context.Context{
|
|
Config: config.Project{
|
|
Snapshot: config.Snapshot{
|
|
NameTemplate: "snap",
|
|
},
|
|
},
|
|
}
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Equal(t, "snap", ctx.Config.Snapshot.NameTemplate)
|
|
}
|
|
|
|
func TestSnapshotInvalidNametemplate(t *testing.T) {
|
|
ctx := context.New(config.Project{
|
|
Snapshot: config.Snapshot{
|
|
NameTemplate: "{{.ShortCommit}{{{sss}}}",
|
|
},
|
|
})
|
|
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
|
}
|
|
|
|
func TestSnapshotEmptyFinalName(t *testing.T) {
|
|
ctx := context.New(config.Project{
|
|
Snapshot: config.Snapshot{
|
|
NameTemplate: "{{ .Commit }}",
|
|
},
|
|
})
|
|
ctx.Git.CurrentTag = "v1.2.3"
|
|
require.EqualError(t, Pipe{}.Run(ctx), "empty snapshot name")
|
|
}
|
|
|
|
func TestSnapshot(t *testing.T) {
|
|
ctx := context.New(config.Project{
|
|
Snapshot: config.Snapshot{
|
|
NameTemplate: "{{ incpatch .Tag }}",
|
|
},
|
|
})
|
|
ctx.Git.CurrentTag = "v1.2.3"
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
require.Equal(t, "v1.2.4", ctx.Version)
|
|
}
|
|
|
|
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{})
|
|
ctx.Snapshot = true
|
|
require.False(t, Pipe{}.Skip(ctx))
|
|
})
|
|
}
|