mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-21 21:07:19 +02:00
<!-- Hi, thanks for contributing! Please make sure you read our CONTRIBUTING guide. Also, add tests and the respective documentation changes as well. --> <!-- If applied, this commit will... --> ... <!-- Why is this change being made? --> ... <!-- # Provide links to any relevant tickets, URLs or other resources --> ... --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package snapshot
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/testctx"
|
|
"github.com/goreleaser/goreleaser/v2/internal/testlib"
|
|
"github.com/goreleaser/goreleaser/v2/pkg/config"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestStringer(t *testing.T) {
|
|
require.NotEmpty(t, Pipe{}.String())
|
|
}
|
|
|
|
func TestDefault(t *testing.T) {
|
|
ctx := testctx.NewWithCfg(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 := testctx.NewWithCfg(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 := testctx.NewWithCfg(config.Project{
|
|
Snapshot: config.Snapshot{
|
|
NameTemplate: "{{.ShortCommit}{{{sss}}}",
|
|
},
|
|
})
|
|
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
|
}
|
|
|
|
func TestSnapshotEmptyFinalName(t *testing.T) {
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
Snapshot: config.Snapshot{
|
|
NameTemplate: "{{ .Commit }}",
|
|
},
|
|
}, testctx.WithCurrentTag("v1.2.3"))
|
|
require.EqualError(t, Pipe{}.Run(ctx), "empty snapshot name")
|
|
}
|
|
|
|
func TestSnapshot(t *testing.T) {
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
Snapshot: config.Snapshot{
|
|
NameTemplate: "{{ incpatch .Tag }}",
|
|
},
|
|
}, testctx.WithCurrentTag("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(testctx.New()))
|
|
})
|
|
|
|
t.Run("dont skip", func(t *testing.T) {
|
|
ctx := testctx.New(testctx.Snapshot)
|
|
require.False(t, Pipe{}.Skip(ctx))
|
|
})
|
|
}
|