1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-15 01:34:21 +02:00

test: testctx pkg (#3807)

alternative to #3806 

the idea is that both `context.New` and `context.Context{}` are never
used in tests.

not sure yet how much I like it, so far code does look a bit more
readable though.

---------

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2023-03-02 00:01:11 -03:00
committed by GitHub
parent e6159a1283
commit f544c5ce69
71 changed files with 2480 additions and 3121 deletions

View File

@ -10,6 +10,7 @@ import (
"testing"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/testctx"
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
@ -80,7 +81,7 @@ func TestMinioUpload(t *testing.T) {
require.NoError(t, os.WriteFile(debpath, []byte("fake\ndeb"), 0o744))
require.NoError(t, os.WriteFile(sigpath, []byte("fake\nsig"), 0o744))
require.NoError(t, os.WriteFile(certpath, []byte("fake\ncert"), 0o744))
ctx := context.New(config.Project{
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
ProjectName: "testupload",
Blobs: []config.Blob{
@ -97,8 +98,7 @@ func TestMinioUpload(t *testing.T) {
},
},
},
})
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
}, testctx.WithCurrentTag("v1.0.0"))
ctx.Artifacts.Add(&artifact.Artifact{
Type: artifact.Checksum,
Name: "checksum.txt",
@ -169,7 +169,7 @@ func TestMinioUploadCustomBucketID(t *testing.T) {
require.NoError(t, os.WriteFile(debpath, []byte("fake\ndeb"), 0o744))
// Set custom BUCKET_ID env variable.
require.NoError(t, os.Setenv("BUCKET_ID", name))
ctx := context.New(config.Project{
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
ProjectName: "testupload",
Blobs: []config.Blob{
@ -179,8 +179,7 @@ func TestMinioUploadCustomBucketID(t *testing.T) {
Endpoint: "http://" + listen,
},
},
})
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
}, testctx.WithCurrentTag("v1.0.0"))
ctx.Artifacts.Add(&artifact.Artifact{
Type: artifact.UploadableArchive,
Name: "bin.tar.gz",
@ -204,7 +203,7 @@ func TestMinioUploadRootFolder(t *testing.T) {
debpath := filepath.Join(folder, "bin.deb")
require.NoError(t, os.WriteFile(tgzpath, []byte("fake\ntargz"), 0o744))
require.NoError(t, os.WriteFile(debpath, []byte("fake\ndeb"), 0o744))
ctx := context.New(config.Project{
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
ProjectName: "testupload",
Blobs: []config.Blob{
@ -215,8 +214,7 @@ func TestMinioUploadRootFolder(t *testing.T) {
Endpoint: "http://" + listen,
},
},
})
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
}, testctx.WithCurrentTag("v1.0.0"))
ctx.Artifacts.Add(&artifact.Artifact{
Type: artifact.UploadableArchive,
Name: "bin.tar.gz",
@ -239,7 +237,7 @@ func TestMinioUploadInvalidCustomBucketID(t *testing.T) {
debpath := filepath.Join(folder, "bin.deb")
require.NoError(t, os.WriteFile(tgzpath, []byte("fake\ntargz"), 0o744))
require.NoError(t, os.WriteFile(debpath, []byte("fake\ndeb"), 0o744))
ctx := context.New(config.Project{
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
ProjectName: "testupload",
Blobs: []config.Blob{
@ -249,8 +247,7 @@ func TestMinioUploadInvalidCustomBucketID(t *testing.T) {
Endpoint: "http://" + listen,
},
},
})
ctx.Git = context.GitInfo{CurrentTag: "v1.1.0"}
}, testctx.WithCurrentTag("v1.1.0"))
ctx.Artifacts.Add(&artifact.Artifact{
Type: artifact.UploadableArchive,
Name: "bin.tar.gz",