2017-12-02 19:53:19 -02:00
|
|
|
package snapshot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-05-26 15:02:57 -03:00
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/testctx"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/testlib"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/pkg/config"
|
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) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
|
|
Snapshot: config.Snapshot{},
|
|
|
|
})
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2024-07-29 08:21:00 -04:00
|
|
|
require.Equal(t, "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}", ctx.Config.Snapshot.VersionTemplate)
|
2017-12-02 23:07:30 -02:00
|
|
|
}
|
|
|
|
|
2024-07-29 08:21:00 -04:00
|
|
|
func TestDefaultDeprecated(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
|
|
Snapshot: config.Snapshot{
|
|
|
|
NameTemplate: "snap",
|
2017-12-02 23:07:30 -02:00
|
|
|
},
|
2023-03-02 00:01:11 -03:00
|
|
|
})
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2024-07-29 08:21:00 -04:00
|
|
|
require.Equal(t, "snap", ctx.Config.Snapshot.VersionTemplate)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultSet(t *testing.T) {
|
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
|
|
Snapshot: config.Snapshot{
|
|
|
|
VersionTemplate: "snap",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "snap", ctx.Config.Snapshot.VersionTemplate)
|
2017-12-02 19:53:19 -02:00
|
|
|
}
|
2018-12-13 10:09:36 -02:00
|
|
|
|
2024-07-29 08:21:00 -04:00
|
|
|
func TestSnapshotInvalidVersionTemplate(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2018-12-13 10:09:36 -02:00
|
|
|
Snapshot: config.Snapshot{
|
2024-07-29 08:21:00 -04:00
|
|
|
VersionTemplate: "{{.ShortCommit}{{{sss}}}",
|
2018-12-13 10:09:36 -02:00
|
|
|
},
|
|
|
|
})
|
2022-08-06 18:44:23 -03:00
|
|
|
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
2018-12-13 10:09:36 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSnapshotEmptyFinalName(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2018-12-13 10:09:36 -02:00
|
|
|
Snapshot: config.Snapshot{
|
2024-07-29 08:21:00 -04:00
|
|
|
VersionTemplate: "{{ .Commit }}",
|
2018-12-13 10:09:36 -02:00
|
|
|
},
|
2023-03-02 00:01:11 -03:00
|
|
|
}, testctx.WithCurrentTag("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) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-18 10:21:29 -03:00
|
|
|
Snapshot: config.Snapshot{
|
2024-09-19 23:55:10 -03:00
|
|
|
VersionTemplate: "{{ incpatch .Version }}",
|
2021-09-18 10:21:29 -03:00
|
|
|
},
|
2024-09-19 23:55:10 -03:00
|
|
|
}, testctx.WithVersion("1.2.3"))
|
2021-09-18 10:21:29 -03:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
2024-09-19 23:55:10 -03:00
|
|
|
require.Equal(t, "1.2.4", ctx.Version)
|
2021-09-18 10:21:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSkip(t *testing.T) {
|
|
|
|
t.Run("skip", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
require.True(t, Pipe{}.Skip(testctx.New()))
|
2021-09-18 10:21:29 -03:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("dont skip", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New(testctx.Snapshot)
|
2021-09-18 10:21:29 -03:00
|
|
|
require.False(t, Pipe{}.Skip(ctx))
|
|
|
|
})
|
2018-12-13 10:09:36 -02:00
|
|
|
}
|