2017-12-02 19:53:19 -02:00
|
|
|
package snapshot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-08-14 23:50:20 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2020-10-06 09:48:04 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-12-02 19:53:19 -02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStringer(t *testing.T) {
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
2017-12-02 19:53:19 -02:00
|
|
|
}
|
2021-04-25 14:20:49 -03:00
|
|
|
|
2017-12-02 19:53:19 -02:00
|
|
|
func TestDefault(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := &context.Context{
|
2017-12-02 23:07:30 -02:00
|
|
|
Config: config.Project{
|
|
|
|
Snapshot: config.Snapshot{},
|
|
|
|
},
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2021-08-21 15:59:15 +02:00
|
|
|
require.Equal(t, "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}", ctx.Config.Snapshot.NameTemplate)
|
2017-12-02 23:07:30 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultSet(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := &context.Context{
|
2017-12-02 23:07:30 -02:00
|
|
|
Config: config.Project{
|
|
|
|
Snapshot: config.Snapshot{
|
|
|
|
NameTemplate: "snap",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "snap", ctx.Config.Snapshot.NameTemplate)
|
2017-12-02 19:53:19 -02:00
|
|
|
}
|
2018-12-13 10:09:36 -02:00
|
|
|
|
|
|
|
func TestSnapshotInvalidNametemplate(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{
|
2018-12-13 10:09:36 -02:00
|
|
|
Snapshot: config.Snapshot{
|
|
|
|
NameTemplate: "{{.ShortCommit}{{{sss}}}",
|
|
|
|
},
|
|
|
|
})
|
2020-10-06 09:48:04 -03:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), `failed to generate snapshot name: template: tmpl:1: unexpected "}" in operand`)
|
2018-12-13 10:09:36 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSnapshotEmptyFinalName(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{
|
2018-12-13 10:09:36 -02:00
|
|
|
Snapshot: config.Snapshot{
|
|
|
|
NameTemplate: "{{ .Commit }}",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Git.CurrentTag = "v1.2.3"
|
2020-10-06 09:48:04 -03:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), "empty snapshot name")
|
2018-12-13 10:09:36 -02:00
|
|
|
}
|
|
|
|
|
2021-09-18 10:21:29 -03:00
|
|
|
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))
|
|
|
|
})
|
2018-12-13 10:09:36 -02:00
|
|
|
}
|