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