Repository: goreleaser/goreleaser
Pull request #2549 (2021-10-03 15:18:19)

refactor: unifying client mocks
making a single mock client we can use everywhere instead of copy/pasting a lot of code all over.

codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2549?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#2549](https://codecov.io/gh/goreleaser/goreleaser/pull/2549?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (754e4e6) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/57f79e91f88296c84c05d55fe6bccd0d0d29820c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (57f79e9) will **decrease** coverage by `0.02%`.
> The diff coverage is `81.25%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/2549/graphs/tree.svg?width=650&height=150&src=pr&token=3bJvv6b7hN&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)](https://codecov.io/gh/goreleaser/goreleaser/pull/2549?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)

```diff
@@            Coverage Diff             @@
##           master    #2549      +/-   ##
==========================================
- Coverage   82.83%   82.80%   -0.03%     
==========================================
  Files          95       96       +1     
  Lines        6823     6864      +41     
==========================================
+ Hits         5652     5684      +32     
- Misses        994     1002       +8     
- Partials      177      178       +1     
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/2549?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) | Coverage Δ | |
|---|---|---|
| [pkg/context/context.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2549/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-cGtnL2NvbnRleHQvY29udGV4dC5nbw==) | `100.00% <ø> (ø)` | |
| [internal/client/client.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2549/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-aW50ZXJuYWwvY2xpZW50L2NsaWVudC5nbw==) | `79.41% <75.00%> (-5.44%)` | :arrow_down: |
| [internal/client/mock.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2549/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-aW50ZXJuYWwvY2xpZW50L21vY2suZ28=) | `82.50% <82.50%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2549?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2549?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [57f79e9...754e4e6](https://codecov.io/gh/goreleaser/goreleaser/pull/2549?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).


Patch:
diff --git a/internal/client/client.go b/internal/client/client.go
index 36b9ee5b..cbb62907 100644
--- a/internal/client/client.go
+++ b/internal/client/client.go
@@ -49,16 +49,18 @@ func New(ctx *context.Context) (Client, error) {
 
 func newWithToken(ctx *context.Context, token string) (Client, error) {
 	log.WithField("type", ctx.TokenType).Debug("token type")
-	if ctx.TokenType == context.TokenTypeGitHub {
+	switch ctx.TokenType {
+	case context.TokenTypeGitHub:
 		return NewGitHub(ctx, token)
-	}
-	if ctx.TokenType == context.TokenTypeGitLab {
+	case context.TokenTypeGitLab:
 		return NewGitLab(ctx, token)
-	}
-	if ctx.TokenType == context.TokenTypeGitea {
+	case context.TokenTypeGitea:
 		return NewGitea(ctx, token)
+	case context.TokenTypeMock:
+		return NewMock(), nil
+	default:
+		return nil, fmt.Errorf("invalid client token type: %q", ctx.TokenType)
 	}
-	return nil, fmt.Errorf("invalid client token type: %q", ctx.TokenType)
 }
 
 func NewIfToken(ctx *context.Context, cli Client, token string) (Client, error) {
diff --git a/internal/client/mock.go b/internal/client/mock.go
new file mode 100644
index 00000000..891fd058
--- /dev/null
+++ b/internal/client/mock.go
@@ -0,0 +1,82 @@
+package client
+
+import (
+	"errors"
+	"fmt"
+	"io"
+	"os"
+	"sync"
+
+	"github.com/goreleaser/goreleaser/internal/artifact"
+	"github.com/goreleaser/goreleaser/pkg/config"
+	"github.com/goreleaser/goreleaser/pkg/context"
+)
+
+func NewMock() *Mock {
+	return &Mock{}
+}
+
+type Mock struct {
+	CreatedFile         bool
+	Content             string
+	Path                string
+	FailToCreateRelease bool
+	FailToUpload        bool
+	CreatedRelease      bool
+	UploadedFile        bool
+	UploadedFileNames   []string
+	UploadedFilePaths   map[string]string
+	FailFirstUpload     bool
+	Lock                sync.Mutex
+}
+
+func (c *Mock) CloseMilestone(ctx *context.Context, repo Repo, title string) error {
+	return nil
+}
+
+func (c *Mock) GetDefaultBranch(ctx *context.Context, repo Repo) (string, error) {
+	return "", errors.New("Mock does not yet implement GetDefaultBranch")
+}
+
+func (c *Mock) CreateRelease(ctx *context.Context, body string) (string, error) {
+	if c.FailToCreateRelease {
+		return "", errors.New("release failed")
+	}
+	c.CreatedRelease = true
+	return "", nil
+}
+
+func (c *Mock) ReleaseURLTemplate(ctx *context.Context) (string, error) {
+	return "https://dummyhost/download/{{ .Tag }}/{{ .ArtifactName }}", nil
+}
+
+func (c *Mock) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo Repo, content []byte, path, msg string) error {
+	c.CreatedFile = true
+	c.Content = string(content)
+	c.Path = path
+	return nil
+}
+
+func (c *Mock) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) error {
+	c.Lock.Lock()
+	defer c.Lock.Unlock()
+	if c.UploadedFilePaths == nil {
+		c.UploadedFilePaths = map[string]string{}
+	}
+	// ensure file is read to better mimic real behavior
+	_, err := io.ReadAll(file)
+	if err != nil {
+		return fmt.Errorf("unexpected error: %w", err)
+	}
+	if c.FailToUpload {
+		return errors.New("upload failed")
+	}
+	if c.FailFirstUpload {
+		c.FailFirstUpload = false
+		return RetriableError{Err: errors.New("upload failed, should retry")}
+	}
+	c.UploadedFile = true
+	c.UploadedFileNames = append(c.UploadedFileNames, artifact.Name)
+	c.UploadedFilePaths[artifact.Name] = artifact.Path
+	return nil
+}
diff --git a/pkg/context/context.go b/pkg/context/context.go
index cc76b7a4..7de7fac7 100644
--- a/pkg/context/context.go
+++ b/pkg/context/context.go
@@ -59,6 +59,8 @@ const (
 	TokenTypeGitLab TokenType = "gitlab"
 	// TokenTypeGitea defines gitea as type of the token.
 	TokenTypeGitea TokenType = "gitea"
+	// TokenTypeMock is a mock token type used in tests.
+	TokenTypeMock = "mock"
 )
 
 // Context carries along some data through the pipes.


Test patch:
diff --git a/internal/pipe/brew/brew_test.go b/internal/pipe/brew/brew_test.go
index 53f86676..9381edf1 100644
--- a/internal/pipe/brew/brew_test.go
+++ b/internal/pipe/brew/brew_test.go
@@ -1,7 +1,6 @@
 package brew
 
 import (
-	"errors"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -298,7 +297,7 @@ func TestFullPipe(t *testing.T) {
 			f, err := os.Create(path)
 			require.NoError(t, err)
 			require.NoError(t, f.Close())
-			client := &DummyClient{}
+			client := client.NewMock()
 			distFile := filepath.Join(folder, name+".rb")
 
 			if tt.expectedRunError == "" {
@@ -367,7 +366,7 @@ func TestRunPipeNameTemplate(t *testing.T) {
 	f, err := os.Create(path)
 	require.NoError(t, err)
 	require.NoError(t, f.Close())
-	client := &DummyClient{}
+	client := client.NewMock()
 	distFile := filepath.Join(folder, "foo_is_bar.rb")
 
 	require.NoError(t, runAll(ctx, client))
@@ -446,7 +445,7 @@ func TestRunPipeMultipleBrewsWithSkip(t *testing.T) {
 	require.NoError(t, err)
 	require.NoError(t, f.Close())
 
-	cli := &DummyClient{}
+	cli := client.NewMock()
 	require.NoError(t, runAll(ctx, cli))
 	require.EqualError(t, publishAll(ctx, cli), `brew.skip_upload is set`)
 	require.True(t, cli.CreatedFile)
@@ -567,7 +566,7 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
 				require.NoError(t, f.Close())
 			}
 
-			client := &DummyClient{}
+			client := client.NewMock()
 			distFile := filepath.Join(folder, name+".rb")
 
 			require.NoError(t, runAll(ctx, client))
@@ -596,7 +595,7 @@ func TestRunPipeNoBuilds(t *testing.T) {
 			},
 		},
 	}
-	client := &DummyClient{}
+	client := client.NewMock()
 	require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
 	require.False(t, client.CreatedFile)
 }
@@ -740,7 +739,7 @@ func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
 				},
 			})
 		}
-		client := &DummyClient{}
+		client := client.NewMock()
 		require.Equal(t, test.expectedError, runAll(ctx, client))
 		require.False(t, client.CreatedFile)
 		// clean the artifacts for the next run
@@ -768,7 +767,7 @@ func TestRunPipeBinaryRelease(t *testing.T) {
 		Goarch: "amd64",
 		Type:   artifact.Binary,
 	})
-	client := &DummyClient{}
+	client := client.NewMock()
 	require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
 	require.False(t, client.CreatedFile)
 }
@@ -805,7 +804,7 @@ func TestRunPipeNoUpload(t *testing.T) {
 			"Format": "tar.gz",
 		},
 	})
-	client := &DummyClient{}
+	client := client.NewMock()
 
 	assertNoPublish := func(t *testing.T) {
 		t.Helper()
@@ -857,7 +856,7 @@ func TestRunEmptyTokenType(t *testing.T) {
 			"Format": "tar.gz",
 		},
 	})
-	client := &DummyClient{}
+	client := client.NewMock()
 	require.NoError(t, runAll(ctx, client))
 }
 
@@ -906,37 +905,6 @@ func TestGHFolder(t *testing.T) {
 	require.Equal(t, "fooo/bar.rb", buildFormulaPath("fooo", "bar.rb"))
 }
 
-type DummyClient struct {
-	CreatedFile bool
-	Content     string
-}
-
-func (dc *DummyClient) CloseMilestone(ctx *context.Context, repo client.Repo, title string) error {
-	return nil
-}
-
-func (dc *DummyClient) GetDefaultBranch(ctx *context.Context, repo client.Repo) (string, error) {
-	return "", errors.New("DummyClient does not yet implement GetDefaultBranch")
-}
-
-func (dc *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID string, err error) {
-	return
-}
-
-func (dc *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
-	return "https://dummyhost/download/{{ .Tag }}/{{ .ArtifactName }}", nil
-}
-
-func (dc *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo client.Repo, content []byte, path, msg string) (err error) {
-	dc.CreatedFile = true
-	dc.Content = string(content)
-	return
-}
-
-func (dc *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) (err error) {
-	return
-}
-
 func TestSkip(t *testing.T) {
 	t.Run("skip", func(t *testing.T) {
 		require.True(t, Pipe{}.Skip(context.New(config.Project{})))
@@ -957,6 +925,6 @@ func TestRunSkipNoName(t *testing.T) {
 		Brews: []config.Homebrew{{}},
 	})
 
-	client := &DummyClient{}
+	client := client.NewMock()
 	testlib.AssertSkipped(t, runAll(ctx, client))
 }
diff --git a/internal/pipe/gofish/gofish_test.go b/internal/pipe/gofish/gofish_test.go
index 8f5c8c2c..21e1d7a7 100644
--- a/internal/pipe/gofish/gofish_test.go
+++ b/internal/pipe/gofish/gofish_test.go
@@ -1,7 +1,6 @@
 package gofish
 
 import (
-	"errors"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -211,7 +210,7 @@ func TestFullPipe(t *testing.T) {
 			f, err := os.Create(path)
 			require.NoError(t, err)
 			require.NoError(t, f.Close())
-			client := &DummyClient{}
+			client := client.NewMock()
 			distFile := filepath.Join(folder, name+".lua")
 
 			require.NoError(t, runAll(ctx, client))
@@ -275,7 +274,7 @@ func TestRunPipeNameTemplate(t *testing.T) {
 	f, err := os.Create(path)
 	require.NoError(t, err)
 	require.NoError(t, f.Close())
-	client := &DummyClient{}
+	client := client.NewMock()
 	distFile := filepath.Join(folder, "foo_is_bar.lua")
 
 	require.NoError(t, runAll(ctx, client))
@@ -354,7 +353,7 @@ func TestRunPipeMultipleGoFishWithSkip(t *testing.T) {
 	require.NoError(t, err)
 	require.NoError(t, f.Close())
 
-	cli := &DummyClient{}
+	cli := client.NewMock()
 	require.NoError(t, runAll(ctx, cli))
 	require.EqualError(t, publishAll(ctx, cli), `rig.skip_upload is set`)
 	require.True(t, cli.CreatedFile)
@@ -469,7 +468,7 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
 				require.NoError(t, f.Close())
 			}
 
-			client := &DummyClient{}
+			client := client.NewMock()
 			distFile := filepath.Join(folder, name+".lua")
 
 			require.NoError(t, runAll(ctx, client))
@@ -498,7 +497,7 @@ func TestRunPipeNoBuilds(t *testing.T) {
 			},
 		},
 	}
-	client := &DummyClient{}
+	client := client.NewMock()
 	require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
 	require.False(t, client.CreatedFile)
 }
@@ -642,7 +641,7 @@ func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
 				},
 			})
 		}
-		client := &DummyClient{}
+		client := client.NewMock()
 		require.Equal(t, test.expectedError, runAll(ctx, client))
 		require.False(t, client.CreatedFile)
 		// clean the artifacts for the next run
@@ -670,7 +669,7 @@ func TestRunPipeBinaryRelease(t *testing.T) {
 		Goarch: "amd64",
 		Type:   artifact.Binary,
 	})
-	client := &DummyClient{}
+	client := client.NewMock()
 	require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
 	require.False(t, client.CreatedFile)
 }
@@ -707,7 +706,7 @@ func TestRunPipeNoUpload(t *testing.T) {
 			"Format": "tar.gz",
 		},
 	})
-	client := &DummyClient{}
+	client := client.NewMock()
 
 	assertNoPublish := func(t *testing.T) {
 		t.Helper()
@@ -758,7 +757,7 @@ func TestRunEmptyTokenType(t *testing.T) {
 			"Format": "tar.gz",
 		},
 	})
-	client := &DummyClient{}
+	client := client.NewMock()
 	require.NoError(t, runAll(ctx, client))
 }
 
@@ -806,37 +805,6 @@ func TestGHFolder(t *testing.T) {
 	require.Equal(t, "fooo/bar.lua", buildFoodPath("fooo", "bar.lua"))
 }
 
-type DummyClient struct {
-	CreatedFile bool
-	Content     string
-}
-
-func (dc *DummyClient) CloseMilestone(ctx *context.Context, repo client.Repo, title string) error {
-	return nil
-}
-
-func (dc *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID string, err error) {
-	return
-}
-
-func (dc *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
-	return "https://dummyhost/download/{{ .Tag }}/{{ .ArtifactName }}", nil
-}
-
-func (dc *DummyClient) GetDefaultBranch(ctx *context.Context, repo client.Repo) (string, error) {
-	return "", errors.New("DummyClient does not yet implement GetDefaultBranch")
-}
-
-func (dc *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo client.Repo, content []byte, path, msg string) (err error) {
-	dc.CreatedFile = true
-	dc.Content = string(content)
-	return
-}
-
-func (dc *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) (err error) {
-	return
-}
-
 func TestSkip(t *testing.T) {
 	t.Run("skip", func(t *testing.T) {
 		require.True(t, Pipe{}.Skip(context.New(config.Project{})))
@@ -857,6 +825,6 @@ func TestRunSkipNoName(t *testing.T) {
 		Rigs: []config.GoFish{{}},
 	})
 
-	client := &DummyClient{}
+	client := client.NewMock()
 	testlib.AssertSkipped(t, runAll(ctx, client))
 }
diff --git a/internal/pipe/release/release_test.go b/internal/pipe/release/release_test.go
index ec5b282c..05aac348 100644
--- a/internal/pipe/release/release_test.go
+++ b/internal/pipe/release/release_test.go
@@ -1,13 +1,9 @@
 package release
 
 import (
-	"errors"
-	"fmt"
-	"io"
 	"os"
 	"path/filepath"
 	"strings"
-	"sync"
 	"testing"
 
 	"github.com/goreleaser/goreleaser/internal/artifact"
@@ -91,7 +87,7 @@ func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
 			"Format": "tar.gz",
 		},
 	})
-	client := &DummyClient{}
+	client := &client.Mock{}
 	require.NoError(t, doPublish(ctx, client))
 	require.True(t, client.CreatedRelease)
 	require.True(t, client.UploadedFile)
@@ -164,7 +160,7 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) {
 			"ID": "bar",
 		},
 	})
-	client := &DummyClient{}
+	client := &client.Mock{}
 	require.NoError(t, doPublish(ctx, client))
 	require.True(t, client.CreatedRelease)
 	require.True(t, client.UploadedFile)
@@ -186,7 +182,7 @@ func TestRunPipeReleaseCreationFailed(t *testing.T) {
 	}
 	ctx := context.New(config)
 	ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
-	client := &DummyClient{
+	client := &client.Mock{
 		FailToCreateRelease: true,
 	}
 	require.Error(t, doPublish(ctx, client))
@@ -210,7 +206,7 @@ func TestRunPipeWithFileThatDontExist(t *testing.T) {
 		Name: "bin.tar.gz",
 		Path: "/nope/nope/nope",
 	})
-	client := &DummyClient{}
+	client := &client.Mock{}
 	require.Error(t, doPublish(ctx, client))
 	require.True(t, client.CreatedRelease)
 	require.False(t, client.UploadedFile)
@@ -235,7 +231,7 @@ func TestRunPipeUploadFailure(t *testing.T) {
 		Name: "bin.tar.gz",
 		Path: tarfile.Name(),
 	})
-	client := &DummyClient{
+	client := &client.Mock{
 		FailToUpload: true,
 	}
 	require.EqualError(t, doPublish(ctx, client), "failed to upload bin.tar.gz after 1 tries: upload failed")
@@ -258,7 +254,7 @@ func TestRunPipeExtraFileNotFound(t *testing.T) {
 	}
 	ctx := context.New(config)
 	ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
-	client := &DummyClient{}
+	client := &client.Mock{}
 	require.EqualError(t, doPublish(ctx, client), "globbing failed for pattern ./nope: matching \"./nope\": file does not exist")
 	require.True(t, client.CreatedRelease)
 	require.False(t, client.UploadedFile)
@@ -279,7 +275,7 @@ func TestRunPipeExtraOverride(t *testing.T) {
 	}
 	ctx := context.New(config)
 	ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
-	client := &DummyClient{}
+	client := &client.Mock{}
 	require.NoError(t, doPublish(ctx, client))
 	require.True(t, client.CreatedRelease)
 	require.True(t, client.UploadedFile)
@@ -306,7 +302,7 @@ func TestRunPipeUploadRetry(t *testing.T) {
 		Name: "bin.tar.gz",
 		Path: tarfile.Name(),
 	})
-	client := &DummyClient{
+	client := &client.Mock{
 		FailFirstUpload: true,
 	}
 	require.NoError(t, doPublish(ctx, client))
@@ -523,62 +519,3 @@ func TestSkip(t *testing.T) {
 		require.False(t, Pipe{}.Skip(context.New(config.Project{})))
 	})
 }
-
-type DummyClient struct {
-	FailToCreateRelease bool
-	FailToUpload        bool
-	CreatedRelease      bool
-	UploadedFile        bool
-	UploadedFileNames   []string
-	UploadedFilePaths   map[string]string
-	FailFirstUpload     bool
-	Lock                sync.Mutex
-}
-
-func (c *DummyClient) CloseMilestone(ctx *context.Context, repo client.Repo, title string) error {
-	return nil
-}
-
-func (c *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID string, err error) {
-	if c.FailToCreateRelease {
-		return "", errors.New("release failed")
-	}
-	c.CreatedRelease = true
-	return
-}
-
-func (c *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
-	return "", nil
-}
-
-func (c *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo client.Repo, content []byte, path, msg string) (err error) {
-	return
-}
-
-func (c *DummyClient) GetDefaultBranch(ctx *context.Context, repo client.Repo) (string, error) {
-	return "", errors.New("DummyClient does not yet implement GetDefaultBranch")
-}
-
-func (c *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) error {
-	c.Lock.Lock()
-	defer c.Lock.Unlock()
-	if c.UploadedFilePaths == nil {
-		c.UploadedFilePaths = map[string]string{}
-	}
-	// ensure file is read to better mimic real behavior
-	_, err := io.ReadAll(file)
-	if err != nil {
-		return fmt.Errorf("unexpected error: %w", err)
-	}
-	if c.FailToUpload {
-		return errors.New("upload failed")
-	}
-	if c.FailFirstUpload {
-		c.FailFirstUpload = false
-		return client.RetriableError{Err: errors.New("upload failed, should retry")}
-	}
-	c.UploadedFile = true
-	c.UploadedFileNames = append(c.UploadedFileNames, artifact.Name)
-	c.UploadedFilePaths[artifact.Name] = artifact.Path
-	return nil
-}
diff --git a/internal/pipe/scoop/scoop_test.go b/internal/pipe/scoop/scoop_test.go
index 3d42d094..4de754f4 100644
--- a/internal/pipe/scoop/scoop_test.go
+++ b/internal/pipe/scoop/scoop_test.go
@@ -2,7 +2,6 @@ package scoop
 
 import (
 	ctx "context"
-	"errors"
 	"os"
 	"path/filepath"
 	"testing"
@@ -63,7 +62,7 @@ func Test_doRun(t *testing.T) {
 
 	type args struct {
 		ctx    *context.Context
-		client *DummyClient
+		client *client.Mock
 	}
 
 	type asserter func(*testing.T, args)
@@ -127,7 +126,7 @@ func Test_doRun(t *testing.T) {
 						},
 					},
 				},
-				&DummyClient{},
+				client.NewMock(),
 			},
 			[]*artifact.Artifact{
 				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
@@ -175,7 +174,7 @@ func Test_doRun(t *testing.T) {
 						},
 					},
 				},
-				&DummyClient{},
+				client.NewMock(),
 			},
 			[]*artifact.Artifact{
 				{
@@ -237,7 +236,7 @@ func Test_doRun(t *testing.T) {
 						},
 					},
 				},
-				&DummyClient{},
+				client.NewMock(),
 			},
 			[]*artifact.Artifact{
 				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
@@ -285,7 +284,7 @@ func Test_doRun(t *testing.T) {
 						},
 					},
 				},
-				&DummyClient{},
+				client.NewMock(),
 			},
 			[]*artifact.Artifact{
 				{
@@ -341,7 +340,7 @@ func Test_doRun(t *testing.T) {
 						},
 					},
 				},
-				&DummyClient{},
+				client.NewMock(),
 			},
 			[]*artifact.Artifact{
 				{
@@ -396,7 +395,7 @@ func Test_doRun(t *testing.T) {
 						},
 					},
 				},
-				&DummyClient{},
+				client.NewMock(),
 			},
 			[]*artifact.Artifact{
 				{Name: "foo_1.0.1_linux_amd64.tar.gz", Goos: "linux", Goarch: "amd64"},
@@ -438,7 +437,7 @@ func Test_doRun(t *testing.T) {
 						},
 					},
 				},
-				&DummyClient{},
+				client.NewMock(),
 			},
 			[]*artifact.Artifact{
 				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
@@ -490,7 +489,7 @@ func Test_doRun(t *testing.T) {
 						},
 					},
 				},
-				&DummyClient{},
+				client.NewMock(),
 			},
 			[]*artifact.Artifact{
 				{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
@@ -536,7 +535,7 @@ func Test_doRun(t *testing.T) {
 						},
 					},
 				},
-				&DummyClient{},
+				client.NewMock(),
 			},
 			[]*artifact.Artifact{
 				{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
@@ -578,7 +577,7 @@ func Test_doRun(t *testing.T) {
 						},
 					},
 				},
-				&DummyClient{},
+				client.NewMock(),
 			},
 			[]*artifact.Artifact{
 				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
@@ -620,7 +619,7 @@ func Test_doRun(t *testing.T) {
 						},
 					},
 				},
-				&DummyClient{},
+				client.NewMock(),
 			},
 			[]*artifact.Artifact{
 				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
@@ -940,7 +939,7 @@ func TestRunPipeScoopWithSkipUpload(t *testing.T) {
 	require.NoError(t, err)
 	require.NoError(t, f.Close())
 
-	cli := &DummyClient{}
+	cli := client.NewMock()
 	require.NoError(t, doRun(ctx, cli))
 	require.EqualError(t, doPublish(ctx, cli), `scoop.skip_upload is true`)
 
@@ -1036,36 +1035,3 @@ func TestSkip(t *testing.T) {
 		require.False(t, Pipe{}.Skip(ctx))
 	})
 }
-
-type DummyClient struct {
-	CreatedFile bool
-	Content     string
-	Path        string
-}
-
-func (dc *DummyClient) CloseMilestone(ctx *context.Context, repo client.Repo, title string) error {
-	return nil
-}
-
-func (dc *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID string, err error) {
-	return
-}
-
-func (dc *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
-	return "", nil
-}
-
-func (dc *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo client.Repo, content []byte, path, msg string) (err error) {
-	dc.CreatedFile = true
-	dc.Content = string(content)
-	dc.Path = path
-	return
-}
-
-func (dc *DummyClient) GetDefaultBranch(ctx *context.Context, repo client.Repo) (string, error) {
-	return "", errors.New("DummyClient does not yet implement GetDefaultBranch")
-}
-
-func (dc *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) (err error) {
-	return
-}