2017-12-02 19:53:19 -02:00
|
|
|
package snapshot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-12-13 10:09:36 -02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
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
|
|
|
}
|
|
|
|
func TestDefault(t *testing.T) {
|
2017-12-02 23:07:30 -02:00
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Snapshot: config.Snapshot{},
|
|
|
|
},
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "{{ .Tag }}-SNAPSHOT-{{ .ShortCommit }}", ctx.Config.Snapshot.NameTemplate)
|
2017-12-02 23:07:30 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultSet(t *testing.T) {
|
|
|
|
var ctx = &context.Context{
|
|
|
|
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) {
|
|
|
|
var ctx = context.New(config.Project{
|
|
|
|
Snapshot: config.Snapshot{
|
|
|
|
NameTemplate: "{{.ShortCommit}{{{sss}}}",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Snapshot = true
|
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) {
|
|
|
|
var ctx = context.New(config.Project{
|
|
|
|
Snapshot: config.Snapshot{
|
|
|
|
NameTemplate: "{{ .Commit }}",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Snapshot = true
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func TestNotASnapshot(t *testing.T) {
|
|
|
|
var ctx = context.New(config.Project{})
|
|
|
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
|
|
|
}
|