github.com/triarius/goreleaser@v1.12.5/internal/pipe/brew/brew_test.go (about)

     1  package brew
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/triarius/goreleaser/internal/artifact"
    10  	"github.com/triarius/goreleaser/internal/client"
    11  	"github.com/triarius/goreleaser/internal/golden"
    12  	"github.com/triarius/goreleaser/internal/testlib"
    13  	"github.com/triarius/goreleaser/pkg/config"
    14  	"github.com/triarius/goreleaser/pkg/context"
    15  	"github.com/stretchr/testify/require"
    16  )
    17  
    18  func TestDescription(t *testing.T) {
    19  	require.NotEmpty(t, Pipe{}.String())
    20  }
    21  
    22  func TestNameWithDash(t *testing.T) {
    23  	require.Equal(t, formulaNameFor("some-binary"), "SomeBinary")
    24  }
    25  
    26  func TestNameWithUnderline(t *testing.T) {
    27  	require.Equal(t, formulaNameFor("some_binary"), "SomeBinary")
    28  }
    29  
    30  func TestNameWithDots(t *testing.T) {
    31  	require.Equal(t, formulaNameFor("binaryv0.0.0"), "Binaryv000")
    32  }
    33  
    34  func TestNameWithAT(t *testing.T) {
    35  	require.Equal(t, formulaNameFor("some_binary@1"), "SomeBinaryAT1")
    36  }
    37  
    38  func TestSimpleName(t *testing.T) {
    39  	require.Equal(t, formulaNameFor("binary"), "Binary")
    40  }
    41  
    42  var defaultTemplateData = templateData{
    43  	Desc:     "Some desc",
    44  	Homepage: "https://google.com",
    45  	LinuxPackages: []releasePackage{
    46  		{
    47  			DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz",
    48  			SHA256:      "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
    49  			OS:          "linux",
    50  			Arch:        "amd64",
    51  			Install:     []string{`bin.install "test"`},
    52  		},
    53  		{
    54  			DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz",
    55  			SHA256:      "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
    56  			OS:          "linux",
    57  			Arch:        "arm",
    58  			Install:     []string{`bin.install "test"`},
    59  		},
    60  		{
    61  			DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz",
    62  			SHA256:      "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
    63  			OS:          "linux",
    64  			Arch:        "arm64",
    65  			Install:     []string{`bin.install "test"`},
    66  		},
    67  	},
    68  	MacOSPackages: []releasePackage{
    69  		{
    70  			DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz",
    71  			SHA256:      "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68",
    72  			OS:          "darwin",
    73  			Arch:        "amd64",
    74  			Install:     []string{`bin.install "test"`},
    75  		},
    76  		{
    77  			DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz",
    78  			SHA256:      "1df5fdc2bad4ed4c28fbdc77b6c542988c0dc0e2ae34e0dc912bbb1c66646c58",
    79  			OS:          "darwin",
    80  			Arch:        "arm64",
    81  			Install:     []string{`bin.install "test"`},
    82  		},
    83  	},
    84  	Name:                 "Test",
    85  	Version:              "0.1.3",
    86  	Caveats:              []string{},
    87  	HasOnlyAmd64MacOsPkg: false,
    88  }
    89  
    90  func assertDefaultTemplateData(t *testing.T, formulae string) {
    91  	t.Helper()
    92  	require.Contains(t, formulae, "class Test < Formula")
    93  	require.Contains(t, formulae, `homepage "https://google.com"`)
    94  	require.Contains(t, formulae, `url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`)
    95  	require.Contains(t, formulae, `sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`)
    96  	require.Contains(t, formulae, `version "0.1.3"`)
    97  }
    98  
    99  func TestFullFormulae(t *testing.T) {
   100  	data := defaultTemplateData
   101  	data.License = "MIT"
   102  	data.Caveats = []string{"Here are some caveats"}
   103  	data.Dependencies = []config.HomebrewDependency{{Name: "gtk+"}}
   104  	data.Conflicts = []string{"svn"}
   105  	data.Plist = "it works"
   106  	data.PostInstall = []string{`touch "/tmp/foo"`, `system "echo", "done"`}
   107  	data.CustomBlock = []string{"devel do", `  url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`, `  sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`, "end"}
   108  	data.Tests = []string{`system "#{bin}/{{.ProjectName}}", "-version"`}
   109  	formulae, err := doBuildFormula(context.New(config.Project{
   110  		ProjectName: "foo",
   111  	}), data)
   112  	require.NoError(t, err)
   113  
   114  	golden.RequireEqualRb(t, []byte(formulae))
   115  }
   116  
   117  func TestFullFormulaeLinuxOnly(t *testing.T) {
   118  	data := defaultTemplateData
   119  	data.MacOSPackages = []releasePackage{}
   120  	formulae, err := doBuildFormula(context.New(config.Project{
   121  		ProjectName: "foo",
   122  	}), data)
   123  	require.NoError(t, err)
   124  
   125  	golden.RequireEqualRb(t, []byte(formulae))
   126  }
   127  
   128  func TestFullFormulaeMacOSOnly(t *testing.T) {
   129  	data := defaultTemplateData
   130  	data.LinuxPackages = []releasePackage{}
   131  	formulae, err := doBuildFormula(context.New(config.Project{
   132  		ProjectName: "foo",
   133  	}), data)
   134  	require.NoError(t, err)
   135  
   136  	golden.RequireEqualRb(t, []byte(formulae))
   137  }
   138  
   139  func TestFormulaeSimple(t *testing.T) {
   140  	formulae, err := doBuildFormula(context.New(config.Project{}), defaultTemplateData)
   141  	require.NoError(t, err)
   142  	assertDefaultTemplateData(t, formulae)
   143  	require.NotContains(t, formulae, "def caveats")
   144  	require.NotContains(t, formulae, "def plist;")
   145  }
   146  
   147  func TestSplit(t *testing.T) {
   148  	parts := split("system \"true\"\nsystem \"#{bin}/foo\", \"-h\"")
   149  	require.Equal(t, []string{"system \"true\"", "system \"#{bin}/foo\", \"-h\""}, parts)
   150  	parts = split("")
   151  	require.Equal(t, []string{}, parts)
   152  	parts = split("\n  ")
   153  	require.Equal(t, []string{}, parts)
   154  }
   155  
   156  func TestFullPipe(t *testing.T) {
   157  	type testcase struct {
   158  		prepare              func(ctx *context.Context)
   159  		expectedRunError     string
   160  		expectedPublishError string
   161  	}
   162  	for name, tt := range map[string]testcase{
   163  		"default": {
   164  			prepare: func(ctx *context.Context) {
   165  				ctx.TokenType = context.TokenTypeGitHub
   166  				ctx.Config.Brews[0].Tap.Owner = "test"
   167  				ctx.Config.Brews[0].Tap.Name = "test"
   168  				ctx.Config.Brews[0].Homepage = "https://github.com/goreleaser"
   169  			},
   170  		},
   171  		"custom_download_strategy": {
   172  			prepare: func(ctx *context.Context) {
   173  				ctx.TokenType = context.TokenTypeGitHub
   174  				ctx.Config.Brews[0].Tap.Owner = "test"
   175  				ctx.Config.Brews[0].Tap.Name = "test"
   176  				ctx.Config.Brews[0].Homepage = "https://github.com/goreleaser"
   177  
   178  				ctx.Config.Brews[0].DownloadStrategy = "GitHubPrivateRepositoryReleaseDownloadStrategy"
   179  			},
   180  		},
   181  		"custom_require": {
   182  			prepare: func(ctx *context.Context) {
   183  				ctx.TokenType = context.TokenTypeGitHub
   184  				ctx.Config.Brews[0].Tap.Owner = "test"
   185  				ctx.Config.Brews[0].Tap.Name = "test"
   186  				ctx.Config.Brews[0].Homepage = "https://github.com/goreleaser"
   187  
   188  				ctx.Config.Brews[0].DownloadStrategy = "CustomDownloadStrategy"
   189  				ctx.Config.Brews[0].CustomRequire = "custom_download_strategy"
   190  			},
   191  		},
   192  		"custom_block": {
   193  			prepare: func(ctx *context.Context) {
   194  				ctx.TokenType = context.TokenTypeGitHub
   195  				ctx.Config.Brews[0].Tap.Owner = "test"
   196  				ctx.Config.Brews[0].Tap.Name = "test"
   197  				ctx.Config.Brews[0].Homepage = "https://github.com/goreleaser"
   198  
   199  				ctx.Config.Brews[0].CustomBlock = `head "https://github.com/caarlos0/test.git"`
   200  			},
   201  		},
   202  		"default_gitlab": {
   203  			prepare: func(ctx *context.Context) {
   204  				ctx.TokenType = context.TokenTypeGitLab
   205  				ctx.Config.Brews[0].Tap.Owner = "test"
   206  				ctx.Config.Brews[0].Tap.Name = "test"
   207  				ctx.Config.Brews[0].Homepage = "https://gitlab.com/goreleaser"
   208  			},
   209  		},
   210  		"invalid_commit_template": {
   211  			prepare: func(ctx *context.Context) {
   212  				ctx.Config.Brews[0].Tap.Owner = "test"
   213  				ctx.Config.Brews[0].Tap.Name = "test"
   214  				ctx.Config.Brews[0].CommitMessageTemplate = "{{ .Asdsa }"
   215  			},
   216  			expectedPublishError: `template: tmpl:1: unexpected "}" in operand`,
   217  		},
   218  		"valid_tap_templates": {
   219  			prepare: func(ctx *context.Context) {
   220  				ctx.TokenType = context.TokenTypeGitHub
   221  				ctx.Env = map[string]string{
   222  					"FOO": "templated",
   223  				}
   224  				ctx.Config.Brews[0].Tap.Owner = "{{.Env.FOO}}"
   225  				ctx.Config.Brews[0].Tap.Name = "{{.Env.FOO}}"
   226  			},
   227  		},
   228  		"invalid_tap_name_template": {
   229  			prepare: func(ctx *context.Context) {
   230  				ctx.Config.Brews[0].Tap.Owner = "test"
   231  				ctx.Config.Brews[0].Tap.Name = "{{ .Asdsa }"
   232  			},
   233  			expectedRunError: `template: tmpl:1: unexpected "}" in operand`,
   234  		},
   235  		"invalid_tap_owner_template": {
   236  			prepare: func(ctx *context.Context) {
   237  				ctx.Config.Brews[0].Tap.Owner = "{{ .Asdsa }"
   238  				ctx.Config.Brews[0].Tap.Name = "test"
   239  			},
   240  			expectedRunError: `template: tmpl:1: unexpected "}" in operand`,
   241  		},
   242  		"invalid_tap_skip_upload_template": {
   243  			prepare: func(ctx *context.Context) {
   244  				ctx.Config.Brews[0].SkipUpload = "{{ .Asdsa }"
   245  				ctx.Config.Brews[0].Tap.Owner = "test"
   246  				ctx.Config.Brews[0].Tap.Name = "test"
   247  			},
   248  			expectedRunError: `template: tmpl:1: unexpected "}" in operand`,
   249  		},
   250  	} {
   251  		t.Run(name, func(t *testing.T) {
   252  			folder := t.TempDir()
   253  			ctx := &context.Context{
   254  				Git: context.GitInfo{
   255  					CurrentTag: "v1.0.1",
   256  				},
   257  				Version:   "1.0.1",
   258  				Artifacts: artifact.New(),
   259  				Env: map[string]string{
   260  					"FOO": "foo_is_bar",
   261  				},
   262  				Config: config.Project{
   263  					Dist:        folder,
   264  					ProjectName: name,
   265  					Brews: []config.Homebrew{
   266  						{
   267  							Name: name,
   268  							IDs: []string{
   269  								"foo",
   270  							},
   271  							Description: "Run pipe test formula and FOO={{ .Env.FOO }}",
   272  							Caveats:     "don't do this {{ .ProjectName }}",
   273  							Test:        "system \"true\"\nsystem \"#{bin}/foo\", \"-h\"",
   274  							Plist:       `<xml>whatever</xml>`,
   275  							Dependencies: []config.HomebrewDependency{
   276  								{Name: "zsh", Type: "optional"},
   277  								{Name: "bash", Version: "3.2.57"},
   278  								{Name: "fish", Type: "optional", Version: "v1.2.3"},
   279  							},
   280  							Conflicts:   []string{"gtk+", "qt"},
   281  							Service:     "run foo/bar\nkeep_alive true",
   282  							PostInstall: "system \"echo\"\ntouch \"/tmp/hi\"",
   283  							Install:     `bin.install "{{ .ProjectName }}"`,
   284  							Goamd64:     "v1",
   285  						},
   286  					},
   287  				},
   288  			}
   289  			tt.prepare(ctx)
   290  			ctx.Artifacts.Add(&artifact.Artifact{
   291  				Name:    "bar_bin.tar.gz",
   292  				Path:    "doesnt matter",
   293  				Goos:    "darwin",
   294  				Goarch:  "amd64",
   295  				Goamd64: "v1",
   296  				Type:    artifact.UploadableArchive,
   297  				Extra: map[string]interface{}{
   298  					artifact.ExtraID:     "bar",
   299  					artifact.ExtraFormat: "tar.gz",
   300  				},
   301  			})
   302  			path := filepath.Join(folder, "bin.tar.gz")
   303  			ctx.Artifacts.Add(&artifact.Artifact{
   304  				Name:    "bin.tar.gz",
   305  				Path:    path,
   306  				Goos:    "darwin",
   307  				Goarch:  "amd64",
   308  				Goamd64: "v1",
   309  				Type:    artifact.UploadableArchive,
   310  				Extra: map[string]interface{}{
   311  					artifact.ExtraID:     "foo",
   312  					artifact.ExtraFormat: "tar.gz",
   313  				},
   314  			})
   315  
   316  			f, err := os.Create(path)
   317  			require.NoError(t, err)
   318  			require.NoError(t, f.Close())
   319  			client := client.NewMock()
   320  			distFile := filepath.Join(folder, name+".rb")
   321  
   322  			if tt.expectedRunError == "" {
   323  				require.NoError(t, runAll(ctx, client))
   324  			} else {
   325  				require.EqualError(t, runAll(ctx, client), tt.expectedRunError)
   326  				return
   327  			}
   328  			if tt.expectedPublishError != "" {
   329  				require.EqualError(t, publishAll(ctx, client), tt.expectedPublishError)
   330  				return
   331  			}
   332  
   333  			require.NoError(t, publishAll(ctx, client))
   334  			require.True(t, client.CreatedFile)
   335  			golden.RequireEqualRb(t, []byte(client.Content))
   336  
   337  			distBts, err := os.ReadFile(distFile)
   338  			require.NoError(t, err)
   339  			require.Equal(t, client.Content, string(distBts))
   340  		})
   341  	}
   342  }
   343  
   344  func TestRunPipeNameTemplate(t *testing.T) {
   345  	folder := t.TempDir()
   346  	ctx := &context.Context{
   347  		Git: context.GitInfo{
   348  			CurrentTag: "v1.0.1",
   349  		},
   350  		Version:   "1.0.1",
   351  		Artifacts: artifact.New(),
   352  		Env: map[string]string{
   353  			"FOO_BAR": "is_bar",
   354  		},
   355  		Config: config.Project{
   356  			Dist:        folder,
   357  			ProjectName: "foo",
   358  			Brews: []config.Homebrew{
   359  				{
   360  					Name:        "foo_{{ .Env.FOO_BAR }}",
   361  					Description: "Foo bar",
   362  					Homepage:    "https://goreleaser.com",
   363  					Goamd64:     "v1",
   364  					Install:     `bin.install "foo"`,
   365  					Tap: config.RepoRef{
   366  						Owner: "foo",
   367  						Name:  "bar",
   368  					},
   369  					IDs: []string{
   370  						"foo",
   371  					},
   372  				},
   373  			},
   374  		},
   375  	}
   376  	path := filepath.Join(folder, "bin.tar.gz")
   377  	ctx.Artifacts.Add(&artifact.Artifact{
   378  		Name:    "bin.tar.gz",
   379  		Path:    path,
   380  		Goos:    "darwin",
   381  		Goarch:  "amd64",
   382  		Goamd64: "v1",
   383  		Type:    artifact.UploadableArchive,
   384  		Extra: map[string]interface{}{
   385  			artifact.ExtraID:     "foo",
   386  			artifact.ExtraFormat: "tar.gz",
   387  		},
   388  	})
   389  
   390  	f, err := os.Create(path)
   391  	require.NoError(t, err)
   392  	require.NoError(t, f.Close())
   393  	client := client.NewMock()
   394  	distFile := filepath.Join(folder, "foo_is_bar.rb")
   395  
   396  	require.NoError(t, runAll(ctx, client))
   397  	require.NoError(t, publishAll(ctx, client))
   398  	require.True(t, client.CreatedFile)
   399  	golden.RequireEqualRb(t, []byte(client.Content))
   400  	distBts, err := os.ReadFile(distFile)
   401  	require.NoError(t, err)
   402  	require.Equal(t, client.Content, string(distBts))
   403  }
   404  
   405  func TestRunPipeMultipleBrewsWithSkip(t *testing.T) {
   406  	folder := t.TempDir()
   407  	ctx := &context.Context{
   408  		Git: context.GitInfo{
   409  			CurrentTag: "v1.0.1",
   410  		},
   411  		Version:   "1.0.1",
   412  		Artifacts: artifact.New(),
   413  		Env: map[string]string{
   414  			"FOO_BAR":     "is_bar",
   415  			"SKIP_UPLOAD": "true",
   416  		},
   417  		Config: config.Project{
   418  			Dist:        folder,
   419  			ProjectName: "foo",
   420  			Brews: []config.Homebrew{
   421  				{
   422  					Name:    "foo",
   423  					Goamd64: "v1",
   424  					Tap: config.RepoRef{
   425  						Owner: "foo",
   426  						Name:  "bar",
   427  					},
   428  					IDs: []string{
   429  						"foo",
   430  					},
   431  					SkipUpload: "true",
   432  				},
   433  				{
   434  					Name:    "bar",
   435  					Goamd64: "v1",
   436  					Tap: config.RepoRef{
   437  						Owner: "foo",
   438  						Name:  "bar",
   439  					},
   440  					IDs: []string{
   441  						"foo",
   442  					},
   443  				},
   444  				{
   445  					Name:    "foobar",
   446  					Goamd64: "v1",
   447  					Tap: config.RepoRef{
   448  						Owner: "foo",
   449  						Name:  "bar",
   450  					},
   451  					IDs: []string{
   452  						"foo",
   453  					},
   454  					SkipUpload: "true",
   455  				},
   456  				{
   457  					Name:    "baz",
   458  					Goamd64: "v1",
   459  					Tap: config.RepoRef{
   460  						Owner: "foo",
   461  						Name:  "bar",
   462  					},
   463  					IDs: []string{
   464  						"foo",
   465  					},
   466  					SkipUpload: "{{ .Env.SKIP_UPLOAD }}",
   467  				},
   468  			},
   469  		},
   470  	}
   471  	path := filepath.Join(folder, "bin.tar.gz")
   472  	ctx.Artifacts.Add(&artifact.Artifact{
   473  		Name:    "bin.tar.gz",
   474  		Path:    path,
   475  		Goos:    "darwin",
   476  		Goarch:  "amd64",
   477  		Goamd64: "v1",
   478  		Type:    artifact.UploadableArchive,
   479  		Extra: map[string]interface{}{
   480  			artifact.ExtraID:     "foo",
   481  			artifact.ExtraFormat: "tar.gz",
   482  		},
   483  	})
   484  
   485  	f, err := os.Create(path)
   486  	require.NoError(t, err)
   487  	require.NoError(t, f.Close())
   488  
   489  	cli := client.NewMock()
   490  	require.NoError(t, runAll(ctx, cli))
   491  	require.EqualError(t, publishAll(ctx, cli), `brew.skip_upload is set`)
   492  	require.True(t, cli.CreatedFile)
   493  
   494  	for _, brew := range ctx.Config.Brews {
   495  		distFile := filepath.Join(folder, brew.Name+".rb")
   496  		_, err := os.Stat(distFile)
   497  		require.NoError(t, err, "file should exist: "+distFile)
   498  	}
   499  }
   500  
   501  func TestRunPipeForMultipleAmd64Versions(t *testing.T) {
   502  	for name, fn := range map[string]func(ctx *context.Context){
   503  		"v1": func(ctx *context.Context) {
   504  			ctx.Config.Brews[0].Goamd64 = "v1"
   505  		},
   506  		"v2": func(ctx *context.Context) {
   507  			ctx.Config.Brews[0].Goamd64 = "v2"
   508  		},
   509  		"v3": func(ctx *context.Context) {
   510  			ctx.Config.Brews[0].Goamd64 = "v3"
   511  		},
   512  		"v4": func(ctx *context.Context) {
   513  			ctx.Config.Brews[0].Goamd64 = "v4"
   514  		},
   515  	} {
   516  		t.Run(name, func(t *testing.T) {
   517  			folder := t.TempDir()
   518  			ctx := &context.Context{
   519  				TokenType: context.TokenTypeGitHub,
   520  				Git: context.GitInfo{
   521  					CurrentTag: "v1.0.1",
   522  				},
   523  				Version:   "1.0.1",
   524  				Artifacts: artifact.New(),
   525  				Env: map[string]string{
   526  					"FOO": "foo_is_bar",
   527  				},
   528  				Config: config.Project{
   529  					Dist:        folder,
   530  					ProjectName: name,
   531  					Brews: []config.Homebrew{
   532  						{
   533  							Name:        name,
   534  							Description: "Run pipe test formula",
   535  							Tap: config.RepoRef{
   536  								Owner: "test",
   537  								Name:  "test",
   538  							},
   539  							Homepage: "https://github.com/goreleaser",
   540  							Install:  `bin.install "foo"`,
   541  						},
   542  					},
   543  					GitHubURLs: config.GitHubURLs{
   544  						Download: "https://github.com",
   545  					},
   546  					Release: config.Release{
   547  						GitHub: config.Repo{
   548  							Owner: "test",
   549  							Name:  "test",
   550  						},
   551  					},
   552  				},
   553  			}
   554  			fn(ctx)
   555  			for _, a := range []struct {
   556  				name    string
   557  				goos    string
   558  				goarch  string
   559  				goamd64 string
   560  			}{
   561  				{
   562  					name:   "bin",
   563  					goos:   "darwin",
   564  					goarch: "arm64",
   565  				},
   566  				{
   567  					name:   "arm64",
   568  					goos:   "linux",
   569  					goarch: "arm64",
   570  				},
   571  				{
   572  					name:    "amd64v2",
   573  					goos:    "linux",
   574  					goarch:  "amd64",
   575  					goamd64: "v1",
   576  				},
   577  				{
   578  					name:    "amd64v2",
   579  					goos:    "linux",
   580  					goarch:  "amd64",
   581  					goamd64: "v2",
   582  				},
   583  				{
   584  					name:    "amd64v3",
   585  					goos:    "linux",
   586  					goarch:  "amd64",
   587  					goamd64: "v3",
   588  				},
   589  				{
   590  					name:    "amd64v3",
   591  					goos:    "linux",
   592  					goarch:  "amd64",
   593  					goamd64: "v4",
   594  				},
   595  			} {
   596  				path := filepath.Join(folder, fmt.Sprintf("%s.tar.gz", a.name))
   597  				ctx.Artifacts.Add(&artifact.Artifact{
   598  					Name:    fmt.Sprintf("%s.tar.gz", a.name),
   599  					Path:    path,
   600  					Goos:    a.goos,
   601  					Goarch:  a.goarch,
   602  					Goamd64: a.goamd64,
   603  					Type:    artifact.UploadableArchive,
   604  					Extra: map[string]interface{}{
   605  						artifact.ExtraID:     a.name,
   606  						artifact.ExtraFormat: "tar.gz",
   607  					},
   608  				})
   609  				f, err := os.Create(path)
   610  				require.NoError(t, err)
   611  				require.NoError(t, f.Close())
   612  			}
   613  
   614  			client := client.NewMock()
   615  			distFile := filepath.Join(folder, name+".rb")
   616  
   617  			require.NoError(t, runAll(ctx, client))
   618  			require.NoError(t, publishAll(ctx, client))
   619  			require.True(t, client.CreatedFile)
   620  			golden.RequireEqualRb(t, []byte(client.Content))
   621  
   622  			distBts, err := os.ReadFile(distFile)
   623  			require.NoError(t, err)
   624  			require.Equal(t, client.Content, string(distBts))
   625  		})
   626  	}
   627  }
   628  
   629  func TestRunPipeForMultipleArmVersions(t *testing.T) {
   630  	for name, fn := range map[string]func(ctx *context.Context){
   631  		"multiple_armv5": func(ctx *context.Context) {
   632  			ctx.Config.Brews[0].Goarm = "5"
   633  		},
   634  		"multiple_armv6": func(ctx *context.Context) {
   635  			ctx.Config.Brews[0].Goarm = "6"
   636  		},
   637  		"multiple_armv7": func(ctx *context.Context) {
   638  			ctx.Config.Brews[0].Goarm = "7"
   639  		},
   640  	} {
   641  		t.Run(name, func(t *testing.T) {
   642  			folder := t.TempDir()
   643  			ctx := &context.Context{
   644  				TokenType: context.TokenTypeGitHub,
   645  				Git: context.GitInfo{
   646  					CurrentTag: "v1.0.1",
   647  				},
   648  				Version:   "1.0.1",
   649  				Artifacts: artifact.New(),
   650  				Env: map[string]string{
   651  					"FOO": "foo_is_bar",
   652  				},
   653  				Config: config.Project{
   654  					Dist:        folder,
   655  					ProjectName: name,
   656  					Brews: []config.Homebrew{
   657  						{
   658  							Name:         name,
   659  							Description:  "Run pipe test formula and FOO={{ .Env.FOO }}",
   660  							Caveats:      "don't do this {{ .ProjectName }}",
   661  							Test:         "system \"true\"\nsystem \"#{bin}/foo\", \"-h\"",
   662  							Plist:        `<xml>whatever</xml>`,
   663  							Dependencies: []config.HomebrewDependency{{Name: "zsh"}, {Name: "bash", Type: "recommended"}},
   664  							Conflicts:    []string{"gtk+", "qt"},
   665  							Install:      `bin.install "{{ .ProjectName }}"`,
   666  							Tap: config.RepoRef{
   667  								Owner: "test",
   668  								Name:  "test",
   669  							},
   670  							Homepage: "https://github.com/goreleaser",
   671  						},
   672  					},
   673  					GitHubURLs: config.GitHubURLs{
   674  						Download: "https://github.com",
   675  					},
   676  					Release: config.Release{
   677  						GitHub: config.Repo{
   678  							Owner: "test",
   679  							Name:  "test",
   680  						},
   681  					},
   682  				},
   683  			}
   684  			fn(ctx)
   685  			for _, a := range []struct {
   686  				name   string
   687  				goos   string
   688  				goarch string
   689  				goarm  string
   690  			}{
   691  				{
   692  					name:   "bin",
   693  					goos:   "darwin",
   694  					goarch: "amd64",
   695  				},
   696  				{
   697  					name:   "arm64",
   698  					goos:   "linux",
   699  					goarch: "arm64",
   700  				},
   701  				{
   702  					name:   "armv5",
   703  					goos:   "linux",
   704  					goarch: "arm",
   705  					goarm:  "5",
   706  				},
   707  				{
   708  					name:   "armv6",
   709  					goos:   "linux",
   710  					goarch: "arm",
   711  					goarm:  "6",
   712  				},
   713  				{
   714  					name:   "armv7",
   715  					goos:   "linux",
   716  					goarch: "arm",
   717  					goarm:  "7",
   718  				},
   719  			} {
   720  				path := filepath.Join(folder, fmt.Sprintf("%s.tar.gz", a.name))
   721  				ctx.Artifacts.Add(&artifact.Artifact{
   722  					Name:   fmt.Sprintf("%s.tar.gz", a.name),
   723  					Path:   path,
   724  					Goos:   a.goos,
   725  					Goarch: a.goarch,
   726  					Goarm:  a.goarm,
   727  					Type:   artifact.UploadableArchive,
   728  					Extra: map[string]interface{}{
   729  						artifact.ExtraID:     a.name,
   730  						artifact.ExtraFormat: "tar.gz",
   731  					},
   732  				})
   733  				f, err := os.Create(path)
   734  				require.NoError(t, err)
   735  				require.NoError(t, f.Close())
   736  			}
   737  
   738  			client := client.NewMock()
   739  			distFile := filepath.Join(folder, name+".rb")
   740  
   741  			require.NoError(t, runAll(ctx, client))
   742  			require.NoError(t, publishAll(ctx, client))
   743  			require.True(t, client.CreatedFile)
   744  			golden.RequireEqualRb(t, []byte(client.Content))
   745  
   746  			distBts, err := os.ReadFile(distFile)
   747  			require.NoError(t, err)
   748  			require.Equal(t, client.Content, string(distBts))
   749  		})
   750  	}
   751  }
   752  
   753  func TestRunPipeNoBuilds(t *testing.T) {
   754  	ctx := context.New(
   755  		config.Project{
   756  			Brews: []config.Homebrew{
   757  				{
   758  					Tap: config.RepoRef{
   759  						Owner: "test",
   760  						Name:  "test",
   761  					},
   762  				},
   763  			},
   764  		},
   765  	)
   766  	ctx.TokenType = context.TokenTypeGitHub
   767  	client := client.NewMock()
   768  	require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
   769  	require.False(t, client.CreatedFile)
   770  }
   771  
   772  func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
   773  	ctx := context.New(
   774  		config.Project{
   775  			Brews: []config.Homebrew{
   776  				{
   777  					Tap: config.RepoRef{
   778  						Owner: "test",
   779  						Name:  "test",
   780  					},
   781  				},
   782  			},
   783  		},
   784  	)
   785  
   786  	ctx.TokenType = context.TokenTypeGitHub
   787  	f, err := os.CreateTemp(t.TempDir(), "")
   788  	require.NoError(t, err)
   789  	t.Cleanup(func() {
   790  		require.NoError(t, f.Close())
   791  	})
   792  
   793  	tests := []struct {
   794  		expectedError error
   795  		osarchs       []struct {
   796  			goos   string
   797  			goarch string
   798  			goarm  string
   799  		}
   800  	}{
   801  		{
   802  			expectedError: ErrMultipleArchivesSameOS,
   803  			osarchs: []struct {
   804  				goos   string
   805  				goarch string
   806  				goarm  string
   807  			}{
   808  				{
   809  					goos:   "darwin",
   810  					goarch: "amd64",
   811  				},
   812  				{
   813  					goos:   "darwin",
   814  					goarch: "amd64",
   815  				},
   816  			},
   817  		},
   818  		{
   819  			expectedError: ErrMultipleArchivesSameOS,
   820  			osarchs: []struct {
   821  				goos   string
   822  				goarch string
   823  				goarm  string
   824  			}{
   825  				{
   826  					goos:   "linux",
   827  					goarch: "amd64",
   828  				},
   829  				{
   830  					goos:   "linux",
   831  					goarch: "amd64",
   832  				},
   833  			},
   834  		},
   835  		{
   836  			expectedError: ErrMultipleArchivesSameOS,
   837  			osarchs: []struct {
   838  				goos   string
   839  				goarch string
   840  				goarm  string
   841  			}{
   842  				{
   843  					goos:   "linux",
   844  					goarch: "arm64",
   845  				},
   846  				{
   847  					goos:   "linux",
   848  					goarch: "arm64",
   849  				},
   850  			},
   851  		},
   852  		{
   853  			expectedError: ErrMultipleArchivesSameOS,
   854  			osarchs: []struct {
   855  				goos   string
   856  				goarch string
   857  				goarm  string
   858  			}{
   859  				{
   860  					goos:   "linux",
   861  					goarch: "arm",
   862  					goarm:  "6",
   863  				},
   864  				{
   865  					goos:   "linux",
   866  					goarch: "arm",
   867  					goarm:  "6",
   868  				},
   869  			},
   870  		},
   871  		{
   872  			expectedError: ErrMultipleArchivesSameOS,
   873  			osarchs: []struct {
   874  				goos   string
   875  				goarch string
   876  				goarm  string
   877  			}{
   878  				{
   879  					goos:   "linux",
   880  					goarch: "arm",
   881  					goarm:  "5",
   882  				},
   883  				{
   884  					goos:   "linux",
   885  					goarch: "arm",
   886  					goarm:  "6",
   887  				},
   888  				{
   889  					goos:   "linux",
   890  					goarch: "arm",
   891  					goarm:  "7",
   892  				},
   893  			},
   894  		},
   895  	}
   896  
   897  	for _, test := range tests {
   898  		for idx, ttt := range test.osarchs {
   899  			ctx.Artifacts.Add(&artifact.Artifact{
   900  				Name:   fmt.Sprintf("bin%d", idx),
   901  				Path:   f.Name(),
   902  				Goos:   ttt.goos,
   903  				Goarch: ttt.goarch,
   904  				Type:   artifact.UploadableArchive,
   905  				Extra: map[string]interface{}{
   906  					artifact.ExtraID:     fmt.Sprintf("foo%d", idx),
   907  					artifact.ExtraFormat: "tar.gz",
   908  				},
   909  			})
   910  		}
   911  		client := client.NewMock()
   912  		require.Equal(t, test.expectedError, runAll(ctx, client))
   913  		require.False(t, client.CreatedFile)
   914  		// clean the artifacts for the next run
   915  		ctx.Artifacts = artifact.New()
   916  	}
   917  }
   918  
   919  func TestRunPipeBinaryRelease(t *testing.T) {
   920  	folder := t.TempDir()
   921  	ctx := &context.Context{
   922  		Git: context.GitInfo{
   923  			CurrentTag: "v1.2.1",
   924  		},
   925  		Version:   "1.2.1",
   926  		Artifacts: artifact.New(),
   927  		Config: config.Project{
   928  			Dist:        folder,
   929  			ProjectName: "foo",
   930  			Brews: []config.Homebrew{
   931  				{
   932  					Name:        "foo",
   933  					Homepage:    "https://goreleaser.com",
   934  					Description: "Fake desc",
   935  					Tap: config.RepoRef{
   936  						Owner: "foo",
   937  						Name:  "bar",
   938  					},
   939  				},
   940  			},
   941  		},
   942  	}
   943  
   944  	path := filepath.Join(folder, "dist/foo_darwin_all/foo")
   945  	ctx.Artifacts.Add(&artifact.Artifact{
   946  		Name:   "foo_macos",
   947  		Path:   path,
   948  		Goos:   "darwin",
   949  		Goarch: "all",
   950  		Type:   artifact.UploadableBinary,
   951  		Extra: map[string]interface{}{
   952  			artifact.ExtraID:     "foo",
   953  			artifact.ExtraFormat: "binary",
   954  			artifact.ExtraBinary: "foo",
   955  		},
   956  	})
   957  
   958  	require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
   959  	f, err := os.Create(path)
   960  	require.NoError(t, err)
   961  	require.NoError(t, f.Close())
   962  
   963  	client := client.NewMock()
   964  	require.NoError(t, runAll(ctx, client))
   965  	require.NoError(t, publishAll(ctx, client))
   966  	require.True(t, client.CreatedFile)
   967  	golden.RequireEqualRb(t, []byte(client.Content))
   968  }
   969  
   970  func TestRunPipeNoUpload(t *testing.T) {
   971  	folder := t.TempDir()
   972  	ctx := context.New(config.Project{
   973  		Dist:        folder,
   974  		ProjectName: "foo",
   975  		Release:     config.Release{},
   976  		Brews: []config.Homebrew{
   977  			{
   978  				Tap: config.RepoRef{
   979  					Owner: "test",
   980  					Name:  "test",
   981  				},
   982  				Goamd64: "v1",
   983  			},
   984  		},
   985  	})
   986  	ctx.Env = map[string]string{
   987  		"SKIP_UPLOAD": "true",
   988  	}
   989  	ctx.TokenType = context.TokenTypeGitHub
   990  	ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
   991  	path := filepath.Join(folder, "whatever.tar.gz")
   992  	f, err := os.Create(path)
   993  	require.NoError(t, err)
   994  	require.NoError(t, f.Close())
   995  	ctx.Artifacts.Add(&artifact.Artifact{
   996  		Name:    "bin",
   997  		Path:    path,
   998  		Goos:    "darwin",
   999  		Goarch:  "amd64",
  1000  		Goamd64: "v1",
  1001  		Type:    artifact.UploadableArchive,
  1002  		Extra: map[string]interface{}{
  1003  			artifact.ExtraID:     "foo",
  1004  			artifact.ExtraFormat: "tar.gz",
  1005  		},
  1006  	})
  1007  	client := client.NewMock()
  1008  
  1009  	assertNoPublish := func(t *testing.T) {
  1010  		t.Helper()
  1011  		require.NoError(t, runAll(ctx, client))
  1012  		testlib.AssertSkipped(t, publishAll(ctx, client))
  1013  		require.False(t, client.CreatedFile)
  1014  	}
  1015  	t.Run("skip upload true", func(t *testing.T) {
  1016  		ctx.Config.Brews[0].SkipUpload = "true"
  1017  		ctx.Semver.Prerelease = ""
  1018  		assertNoPublish(t)
  1019  	})
  1020  	t.Run("skip upload true set by template", func(t *testing.T) {
  1021  		ctx.Config.Brews[0].SkipUpload = "{{.Env.SKIP_UPLOAD}}"
  1022  		ctx.Semver.Prerelease = ""
  1023  		assertNoPublish(t)
  1024  	})
  1025  	t.Run("skip upload auto", func(t *testing.T) {
  1026  		ctx.Config.Brews[0].SkipUpload = "auto"
  1027  		ctx.Semver.Prerelease = "beta1"
  1028  		assertNoPublish(t)
  1029  	})
  1030  }
  1031  
  1032  func TestRunEmptyTokenType(t *testing.T) {
  1033  	folder := t.TempDir()
  1034  	ctx := context.New(config.Project{
  1035  		Dist:        folder,
  1036  		ProjectName: "foo",
  1037  		Release:     config.Release{},
  1038  		Brews: []config.Homebrew{
  1039  			{
  1040  				Tap: config.RepoRef{
  1041  					Owner: "test",
  1042  					Name:  "test",
  1043  				},
  1044  				Goamd64: "v1",
  1045  			},
  1046  		},
  1047  	})
  1048  	ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
  1049  	path := filepath.Join(folder, "whatever.tar.gz")
  1050  	f, err := os.Create(path)
  1051  	require.NoError(t, err)
  1052  	require.NoError(t, f.Close())
  1053  	ctx.Artifacts.Add(&artifact.Artifact{
  1054  		Name:    "bin",
  1055  		Path:    path,
  1056  		Goos:    "darwin",
  1057  		Goarch:  "amd64",
  1058  		Goamd64: "v1",
  1059  		Type:    artifact.UploadableArchive,
  1060  		Extra: map[string]interface{}{
  1061  			artifact.ExtraID:     "foo",
  1062  			artifact.ExtraFormat: "tar.gz",
  1063  		},
  1064  	})
  1065  	client := client.NewMock()
  1066  	require.NoError(t, runAll(ctx, client))
  1067  }
  1068  
  1069  func TestDefault(t *testing.T) {
  1070  	testlib.Mktmp(t)
  1071  
  1072  	ctx := &context.Context{
  1073  		TokenType: context.TokenTypeGitHub,
  1074  		Config: config.Project{
  1075  			ProjectName: "myproject",
  1076  			Brews: []config.Homebrew{
  1077  				{},
  1078  			},
  1079  		},
  1080  	}
  1081  	require.NoError(t, Pipe{}.Default(ctx))
  1082  	require.Equal(t, ctx.Config.ProjectName, ctx.Config.Brews[0].Name)
  1083  	require.NotEmpty(t, ctx.Config.Brews[0].CommitAuthor.Name)
  1084  	require.NotEmpty(t, ctx.Config.Brews[0].CommitAuthor.Email)
  1085  	require.NotEmpty(t, ctx.Config.Brews[0].CommitMessageTemplate)
  1086  }
  1087  
  1088  func TestGHFolder(t *testing.T) {
  1089  	require.Equal(t, "bar.rb", buildFormulaPath("", "bar.rb"))
  1090  	require.Equal(t, "fooo/bar.rb", buildFormulaPath("fooo", "bar.rb"))
  1091  }
  1092  
  1093  func TestSkip(t *testing.T) {
  1094  	t.Run("skip", func(t *testing.T) {
  1095  		require.True(t, Pipe{}.Skip(context.New(config.Project{})))
  1096  	})
  1097  
  1098  	t.Run("dont skip", func(t *testing.T) {
  1099  		ctx := context.New(config.Project{
  1100  			Brews: []config.Homebrew{
  1101  				{},
  1102  			},
  1103  		})
  1104  		require.False(t, Pipe{}.Skip(ctx))
  1105  	})
  1106  }
  1107  
  1108  func TestRunSkipNoName(t *testing.T) {
  1109  	ctx := context.New(config.Project{
  1110  		Brews: []config.Homebrew{{}},
  1111  	})
  1112  
  1113  	client := client.NewMock()
  1114  	testlib.AssertSkipped(t, runAll(ctx, client))
  1115  }
  1116  
  1117  func TestInstalls(t *testing.T) {
  1118  	t.Run("provided", func(t *testing.T) {
  1119  		require.Equal(t, []string{
  1120  			`bin.install "foo"`,
  1121  			`bin.install "bar"`,
  1122  		}, installs(
  1123  			config.Homebrew{Install: "bin.install \"foo\"\nbin.install \"bar\""},
  1124  			&artifact.Artifact{},
  1125  		))
  1126  	})
  1127  
  1128  	t.Run("from archives", func(t *testing.T) {
  1129  		require.Equal(t, []string{
  1130  			`bin.install "bar"`,
  1131  			`bin.install "foo"`,
  1132  		}, installs(
  1133  			config.Homebrew{},
  1134  			&artifact.Artifact{
  1135  				Type: artifact.UploadableArchive,
  1136  				Extra: map[string]interface{}{
  1137  					artifact.ExtraBinaries: []string{"foo", "bar"},
  1138  				},
  1139  			},
  1140  		))
  1141  	})
  1142  
  1143  	t.Run("from binary", func(t *testing.T) {
  1144  		require.Equal(t, []string{
  1145  			`bin.install "foo_macos" => "foo"`,
  1146  		}, installs(
  1147  			config.Homebrew{},
  1148  			&artifact.Artifact{
  1149  				Name: "foo_macos",
  1150  				Type: artifact.UploadableBinary,
  1151  				Extra: map[string]interface{}{
  1152  					artifact.ExtraBinary: "foo",
  1153  				},
  1154  			},
  1155  		))
  1156  	})
  1157  }
  1158  
  1159  func TestRunPipeUniversalBinary(t *testing.T) {
  1160  	folder := t.TempDir()
  1161  	ctx := &context.Context{
  1162  		Git: context.GitInfo{
  1163  			CurrentTag: "v1.0.1",
  1164  		},
  1165  		Version:   "1.0.1",
  1166  		Artifacts: artifact.New(),
  1167  		Config: config.Project{
  1168  			Dist:        folder,
  1169  			ProjectName: "unibin",
  1170  			Brews: []config.Homebrew{
  1171  				{
  1172  					Name:        "unibin",
  1173  					Homepage:    "https://goreleaser.com",
  1174  					Description: "Fake desc",
  1175  					Tap: config.RepoRef{
  1176  						Owner: "unibin",
  1177  						Name:  "bar",
  1178  					},
  1179  					IDs: []string{
  1180  						"unibin",
  1181  					},
  1182  					Install: `bin.install "unibin"`,
  1183  				},
  1184  			},
  1185  		},
  1186  	}
  1187  	path := filepath.Join(folder, "bin.tar.gz")
  1188  	ctx.Artifacts.Add(&artifact.Artifact{
  1189  		Name:   "bin.tar.gz",
  1190  		Path:   path,
  1191  		Goos:   "darwin",
  1192  		Goarch: "all",
  1193  		Type:   artifact.UploadableArchive,
  1194  		Extra: map[string]interface{}{
  1195  			artifact.ExtraID:       "unibin",
  1196  			artifact.ExtraFormat:   "tar.gz",
  1197  			artifact.ExtraBinaries: []string{"unibin"},
  1198  			artifact.ExtraReplaces: true,
  1199  		},
  1200  	})
  1201  
  1202  	f, err := os.Create(path)
  1203  	require.NoError(t, err)
  1204  	require.NoError(t, f.Close())
  1205  	client := client.NewMock()
  1206  	distFile := filepath.Join(folder, "unibin.rb")
  1207  
  1208  	require.NoError(t, runAll(ctx, client))
  1209  	require.NoError(t, publishAll(ctx, client))
  1210  	require.True(t, client.CreatedFile)
  1211  	golden.RequireEqualRb(t, []byte(client.Content))
  1212  	distBts, err := os.ReadFile(distFile)
  1213  	require.NoError(t, err)
  1214  	require.Equal(t, client.Content, string(distBts))
  1215  }
  1216  
  1217  func TestRunPipeUniversalBinaryNotReplacing(t *testing.T) {
  1218  	folder := t.TempDir()
  1219  	ctx := &context.Context{
  1220  		Git: context.GitInfo{
  1221  			CurrentTag: "v1.0.1",
  1222  		},
  1223  		Version:   "1.0.1",
  1224  		Artifacts: artifact.New(),
  1225  		Config: config.Project{
  1226  			Dist:        folder,
  1227  			ProjectName: "unibin",
  1228  			Brews: []config.Homebrew{
  1229  				{
  1230  					Name:        "unibin",
  1231  					Homepage:    "https://goreleaser.com",
  1232  					Description: "Fake desc",
  1233  					Tap: config.RepoRef{
  1234  						Owner: "unibin",
  1235  						Name:  "bar",
  1236  					},
  1237  					IDs: []string{
  1238  						"unibin",
  1239  					},
  1240  					Install: `bin.install "unibin"`,
  1241  					Goamd64: "v1",
  1242  				},
  1243  			},
  1244  		},
  1245  	}
  1246  	path := filepath.Join(folder, "bin.tar.gz")
  1247  	ctx.Artifacts.Add(&artifact.Artifact{
  1248  		Name:    "bin_amd64.tar.gz",
  1249  		Path:    path,
  1250  		Goos:    "darwin",
  1251  		Goarch:  "amd64",
  1252  		Goamd64: "v1",
  1253  		Type:    artifact.UploadableArchive,
  1254  		Extra: map[string]interface{}{
  1255  			artifact.ExtraID:       "unibin",
  1256  			artifact.ExtraFormat:   "tar.gz",
  1257  			artifact.ExtraBinaries: []string{"unibin"},
  1258  		},
  1259  	})
  1260  	ctx.Artifacts.Add(&artifact.Artifact{
  1261  		Name:    "bin_arm64.tar.gz",
  1262  		Path:    path,
  1263  		Goos:    "darwin",
  1264  		Goarch:  "arm64",
  1265  		Goamd64: "v1",
  1266  		Type:    artifact.UploadableArchive,
  1267  		Extra: map[string]interface{}{
  1268  			artifact.ExtraID:       "unibin",
  1269  			artifact.ExtraFormat:   "tar.gz",
  1270  			artifact.ExtraBinaries: []string{"unibin"},
  1271  		},
  1272  	})
  1273  	ctx.Artifacts.Add(&artifact.Artifact{
  1274  		Name:   "bin.tar.gz",
  1275  		Path:   path,
  1276  		Goos:   "darwin",
  1277  		Goarch: "all",
  1278  		Type:   artifact.UploadableArchive,
  1279  		Extra: map[string]interface{}{
  1280  			artifact.ExtraID:       "unibin",
  1281  			artifact.ExtraFormat:   "tar.gz",
  1282  			artifact.ExtraBinaries: []string{"unibin"},
  1283  			artifact.ExtraReplaces: false,
  1284  		},
  1285  	})
  1286  
  1287  	f, err := os.Create(path)
  1288  	require.NoError(t, err)
  1289  	require.NoError(t, f.Close())
  1290  	client := client.NewMock()
  1291  	distFile := filepath.Join(folder, "unibin.rb")
  1292  
  1293  	require.NoError(t, runAll(ctx, client))
  1294  	require.NoError(t, publishAll(ctx, client))
  1295  	require.True(t, client.CreatedFile)
  1296  	golden.RequireEqualRb(t, []byte(client.Content))
  1297  	distBts, err := os.ReadFile(distFile)
  1298  	require.NoError(t, err)
  1299  	require.Equal(t, client.Content, string(distBts))
  1300  }