github.com/triarius/goreleaser@v1.12.5/internal/pipe/release/scm_test.go (about)

     1  package release
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/triarius/goreleaser/pkg/config"
     7  	"github.com/triarius/goreleaser/pkg/context"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestSetupGitLab(t *testing.T) {
    12  	t.Run("no repo", func(t *testing.T) {
    13  		ctx := context.New(config.Project{})
    14  
    15  		require.NoError(t, setupGitLab(ctx))
    16  		require.Equal(t, "goreleaser", ctx.Config.Release.GitLab.Owner)
    17  		require.Equal(t, "goreleaser", ctx.Config.Release.GitLab.Name)
    18  	})
    19  
    20  	t.Run("with templates", func(t *testing.T) {
    21  		ctx := context.New(config.Project{
    22  			Env: []string{"NAME=foo", "OWNER=bar"},
    23  			GitLabURLs: config.GitLabURLs{
    24  				Download: "https://{{ .Env.OWNER }}/download",
    25  			},
    26  			Release: config.Release{
    27  				GitLab: config.Repo{
    28  					Owner: "{{.Env.OWNER}}",
    29  					Name:  "{{.Env.NAME}}",
    30  				},
    31  			},
    32  		})
    33  
    34  		require.NoError(t, setupGitLab(ctx))
    35  		require.Equal(t, "bar", ctx.Config.Release.GitLab.Owner)
    36  		require.Equal(t, "foo", ctx.Config.Release.GitLab.Name)
    37  		require.Equal(t, "https://bar/download/bar/foo/-/releases/", ctx.ReleaseURL)
    38  	})
    39  
    40  	t.Run("with invalid templates", func(t *testing.T) {
    41  		t.Run("owner", func(t *testing.T) {
    42  			ctx := context.New(config.Project{
    43  				Release: config.Release{
    44  					GitLab: config.Repo{
    45  						Name:  "foo",
    46  						Owner: "{{.Env.NOPE}}",
    47  					},
    48  				},
    49  			})
    50  
    51  			require.Error(t, setupGitLab(ctx))
    52  		})
    53  
    54  		t.Run("name", func(t *testing.T) {
    55  			ctx := context.New(config.Project{
    56  				Release: config.Release{
    57  					GitLab: config.Repo{
    58  						Name: "{{.Env.NOPE}}",
    59  					},
    60  				},
    61  			})
    62  
    63  			require.Error(t, setupGitLab(ctx))
    64  		})
    65  	})
    66  }
    67  
    68  func TestSetupGitea(t *testing.T) {
    69  	t.Run("no repo", func(t *testing.T) {
    70  		ctx := context.New(config.Project{})
    71  
    72  		require.NoError(t, setupGitea(ctx))
    73  		require.Equal(t, "goreleaser", ctx.Config.Release.Gitea.Owner)
    74  		require.Equal(t, "goreleaser", ctx.Config.Release.Gitea.Name)
    75  	})
    76  
    77  	t.Run("with templates", func(t *testing.T) {
    78  		ctx := context.New(config.Project{
    79  			Env: []string{"NAME=foo", "OWNER=bar"},
    80  			GiteaURLs: config.GiteaURLs{
    81  				Download: "https://{{ .Env.OWNER }}/download",
    82  			},
    83  			Release: config.Release{
    84  				Gitea: config.Repo{
    85  					Owner: "{{.Env.OWNER}}",
    86  					Name:  "{{.Env.NAME}}",
    87  				},
    88  			},
    89  		})
    90  
    91  		require.NoError(t, setupGitea(ctx))
    92  		require.Equal(t, "bar", ctx.Config.Release.Gitea.Owner)
    93  		require.Equal(t, "foo", ctx.Config.Release.Gitea.Name)
    94  		require.Equal(t, "https://bar/download/bar/foo/releases/tag/", ctx.ReleaseURL)
    95  	})
    96  
    97  	t.Run("with invalid templates", func(t *testing.T) {
    98  		t.Run("owner", func(t *testing.T) {
    99  			ctx := context.New(config.Project{
   100  				Release: config.Release{
   101  					Gitea: config.Repo{
   102  						Name:  "foo",
   103  						Owner: "{{.Env.NOPE}}",
   104  					},
   105  				},
   106  			})
   107  
   108  			require.Error(t, setupGitea(ctx))
   109  		})
   110  
   111  		t.Run("name", func(t *testing.T) {
   112  			ctx := context.New(config.Project{
   113  				Release: config.Release{
   114  					Gitea: config.Repo{
   115  						Name: "{{.Env.NOPE}}",
   116  					},
   117  				},
   118  			})
   119  
   120  			require.Error(t, setupGitea(ctx))
   121  		})
   122  	})
   123  }
   124  
   125  func TestSetupGitHub(t *testing.T) {
   126  	t.Run("no repo", func(t *testing.T) {
   127  		ctx := context.New(config.Project{})
   128  
   129  		require.NoError(t, setupGitHub(ctx))
   130  		require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
   131  		require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
   132  	})
   133  
   134  	t.Run("with templates", func(t *testing.T) {
   135  		ctx := context.New(config.Project{
   136  			Env: []string{"NAME=foo", "OWNER=bar"},
   137  			GitHubURLs: config.GitHubURLs{
   138  				Download: "https://{{ .Env.OWNER }}/download",
   139  			},
   140  			Release: config.Release{
   141  				GitHub: config.Repo{
   142  					Owner: "{{.Env.OWNER}}",
   143  					Name:  "{{.Env.NAME}}",
   144  				},
   145  			},
   146  		})
   147  
   148  		require.NoError(t, setupGitHub(ctx))
   149  		require.Equal(t, "bar", ctx.Config.Release.GitHub.Owner)
   150  		require.Equal(t, "foo", ctx.Config.Release.GitHub.Name)
   151  		require.Equal(t, "https://bar/download/bar/foo/releases/tag/", ctx.ReleaseURL)
   152  	})
   153  
   154  	t.Run("with invalid templates", func(t *testing.T) {
   155  		t.Run("owner", func(t *testing.T) {
   156  			ctx := context.New(config.Project{
   157  				Release: config.Release{
   158  					GitHub: config.Repo{
   159  						Name:  "foo",
   160  						Owner: "{{.Env.NOPE}}",
   161  					},
   162  				},
   163  			})
   164  
   165  			require.Error(t, setupGitHub(ctx))
   166  		})
   167  
   168  		t.Run("name", func(t *testing.T) {
   169  			ctx := context.New(config.Project{
   170  				Release: config.Release{
   171  					GitHub: config.Repo{
   172  						Name: "{{.Env.NOPE}}",
   173  					},
   174  				},
   175  			})
   176  
   177  			require.Error(t, setupGitHub(ctx))
   178  		})
   179  	})
   180  }