github.com/goreleaser/goreleaser@v1.25.1/internal/pipe/snapshot/snapshot_test.go (about)

     1  package snapshot
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/goreleaser/goreleaser/internal/testctx"
     7  	"github.com/goreleaser/goreleaser/internal/testlib"
     8  	"github.com/goreleaser/goreleaser/pkg/config"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestStringer(t *testing.T) {
    13  	require.NotEmpty(t, Pipe{}.String())
    14  }
    15  
    16  func TestDefault(t *testing.T) {
    17  	ctx := testctx.NewWithCfg(config.Project{
    18  		Snapshot: config.Snapshot{},
    19  	})
    20  	require.NoError(t, Pipe{}.Default(ctx))
    21  	require.Equal(t, "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}", ctx.Config.Snapshot.NameTemplate)
    22  }
    23  
    24  func TestDefaultSet(t *testing.T) {
    25  	ctx := testctx.NewWithCfg(config.Project{
    26  		Snapshot: config.Snapshot{
    27  			NameTemplate: "snap",
    28  		},
    29  	})
    30  	require.NoError(t, Pipe{}.Default(ctx))
    31  	require.Equal(t, "snap", ctx.Config.Snapshot.NameTemplate)
    32  }
    33  
    34  func TestSnapshotInvalidNametemplate(t *testing.T) {
    35  	ctx := testctx.NewWithCfg(config.Project{
    36  		Snapshot: config.Snapshot{
    37  			NameTemplate: "{{.ShortCommit}{{{sss}}}",
    38  		},
    39  	})
    40  	testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
    41  }
    42  
    43  func TestSnapshotEmptyFinalName(t *testing.T) {
    44  	ctx := testctx.NewWithCfg(config.Project{
    45  		Snapshot: config.Snapshot{
    46  			NameTemplate: "{{ .Commit }}",
    47  		},
    48  	}, testctx.WithCurrentTag("v1.2.3"))
    49  	require.EqualError(t, Pipe{}.Run(ctx), "empty snapshot name")
    50  }
    51  
    52  func TestSnapshot(t *testing.T) {
    53  	ctx := testctx.NewWithCfg(config.Project{
    54  		Snapshot: config.Snapshot{
    55  			NameTemplate: "{{ incpatch .Tag }}",
    56  		},
    57  	}, testctx.WithCurrentTag("v1.2.3"))
    58  	require.NoError(t, Pipe{}.Run(ctx))
    59  	require.Equal(t, "v1.2.4", ctx.Version)
    60  }
    61  
    62  func TestSkip(t *testing.T) {
    63  	t.Run("skip", func(t *testing.T) {
    64  		require.True(t, Pipe{}.Skip(testctx.New()))
    65  	})
    66  
    67  	t.Run("dont skip", func(t *testing.T) {
    68  		ctx := testctx.New(testctx.Snapshot)
    69  		require.False(t, Pipe{}.Skip(ctx))
    70  	})
    71  }