1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-03 00:57:43 +02:00

chore: gofumpt & lint (#2190)

Signed-off-by: Carlos Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker
2021-04-25 14:20:49 -03:00
committed by GitHub
parent 5866b9cb63
commit 860b4a8f81
61 changed files with 721 additions and 706 deletions

View File

@ -1,3 +1,8 @@
linters:
enable:
- thelper
- gofumpt
- tparallel
- unconvert
- unparam
- wastedassign

View File

@ -45,7 +45,7 @@ func newBuildCmd() *buildCmd {
It allows you to quickly check if your GoReleaser build configurations are doing what you expect.
Finally, it allows you to generate a local build for your current machine only using the `+ "`--single-target`"+` option, and specific build IDs using the `+"`--id`"+` option.
Finally, it allows you to generate a local build for your current machine only using the ` + "`--single-target`" + ` option, and specific build IDs using the ` + "`--id`" + ` option.
`,
SilenceUsage: true,
SilenceErrors: true,

View File

@ -18,8 +18,8 @@ type checkCmd struct {
}
func newCheckCmd() *checkCmd {
var root = &checkCmd{}
var cmd = &cobra.Command{
root := &checkCmd{}
cmd := &cobra.Command{
Use: "check",
Aliases: []string{"c"},
Short: "Checks if configuration is valid",
@ -31,7 +31,7 @@ func newCheckCmd() *checkCmd {
if err != nil {
return err
}
var ctx = context.New(cfg)
ctx := context.New(cfg)
ctx.Deprecated = root.deprecated
if err := ctrlc.Default.Run(ctx, func() error {

View File

@ -7,31 +7,31 @@ import (
)
func TestCheckConfig(t *testing.T) {
var cmd = newCheckCmd()
cmd := newCheckCmd()
cmd.cmd.SetArgs([]string{"-f", "testdata/good.yml"})
require.NoError(t, cmd.cmd.Execute())
}
func TestCheckConfigThatDoesNotExist(t *testing.T) {
var cmd = newCheckCmd()
cmd := newCheckCmd()
cmd.cmd.SetArgs([]string{"-f", "testdata/nope.yml"})
require.EqualError(t, cmd.cmd.Execute(), "open testdata/nope.yml: no such file or directory")
}
func TestCheckConfigUnmarshalError(t *testing.T) {
var cmd = newCheckCmd()
cmd := newCheckCmd()
cmd.cmd.SetArgs([]string{"-f", "testdata/unmarshal_error.yml"})
require.EqualError(t, cmd.cmd.Execute(), "yaml: unmarshal errors:\n line 1: field foo not found in type config.Project")
}
func TestCheckConfigInvalid(t *testing.T) {
var cmd = newCheckCmd()
cmd := newCheckCmd()
cmd.cmd.SetArgs([]string{"-f", "testdata/invalid.yml"})
require.EqualError(t, cmd.cmd.Execute(), "invalid config: found 2 builds with the ID 'a', please fix your config")
}
func TestCheckConfigDeprecated(t *testing.T) {
var cmd = newCheckCmd()
cmd := newCheckCmd()
cmd.cmd.SetArgs([]string{"-f", "testdata/good.yml", "--deprecated"})
require.EqualError(t, cmd.cmd.Execute(), "config is valid, but uses deprecated properties, check logs above for details")
}

View File

@ -17,7 +17,7 @@ func TestConfigFlagNotSetButExists(t *testing.T) {
"goreleaser.yaml",
} {
t.Run(name, func(t *testing.T) {
var folder = setup(t)
folder := setup(t)
require.NoError(t, os.Rename(
filepath.Join(folder, "goreleaser.yml"),
filepath.Join(folder, name),
@ -30,7 +30,7 @@ func TestConfigFlagNotSetButExists(t *testing.T) {
}
func TestConfigFileDoesntExist(t *testing.T) {
var folder = setup(t)
folder := setup(t)
err := os.Remove(filepath.Join(folder, "goreleaser.yml"))
require.NoError(t, err)
proj, err := loadConfig("")

View File

@ -10,7 +10,7 @@ import (
func TestRelease(t *testing.T) {
setup(t)
var cmd = newReleaseCmd()
cmd := newReleaseCmd()
cmd.cmd.SetArgs([]string{"--snapshot", "--timeout=1m", "--parallelism=2", "--deprecated"})
require.NoError(t, cmd.cmd.Execute())
}
@ -18,7 +18,7 @@ func TestRelease(t *testing.T) {
func TestReleaseInvalidConfig(t *testing.T) {
setup(t)
createFile(t, "goreleaser.yml", "foo: bar")
var cmd = newReleaseCmd()
cmd := newReleaseCmd()
cmd.cmd.SetArgs([]string{"--snapshot", "--timeout=1m", "--parallelism=2", "--deprecated"})
require.EqualError(t, cmd.cmd.Execute(), "yaml: unmarshal errors:\n line 1: field foo not found in type config.Project")
}
@ -26,18 +26,18 @@ func TestReleaseInvalidConfig(t *testing.T) {
func TestReleaseBrokenProject(t *testing.T) {
setup(t)
createFile(t, "main.go", "not a valid go file")
var cmd = newReleaseCmd()
cmd := newReleaseCmd()
cmd.cmd.SetArgs([]string{"--snapshot", "--timeout=1m", "--parallelism=2"})
require.EqualError(t, cmd.cmd.Execute(), "failed to parse dir: .: main.go:1:1: expected 'package', found not")
}
func TestReleaseFlags(t *testing.T) {
var setup = func(opts releaseOpts) *context.Context {
setup := func(opts releaseOpts) *context.Context {
return setupReleaseContext(context.New(config.Project{}), opts)
}
t.Run("snapshot", func(t *testing.T) {
var ctx = setup(releaseOpts{
ctx := setup(releaseOpts{
snapshot: true,
})
require.True(t, ctx.Snapshot)
@ -46,7 +46,7 @@ func TestReleaseFlags(t *testing.T) {
})
t.Run("skips", func(t *testing.T) {
var ctx = setup(releaseOpts{
ctx := setup(releaseOpts{
skipPublish: true,
skipSign: true,
skipValidate: true,
@ -63,10 +63,10 @@ func TestReleaseFlags(t *testing.T) {
})
t.Run("notes", func(t *testing.T) {
var notes = "foo.md"
var header = "header.md"
var footer = "footer.md"
var ctx = setup(releaseOpts{
notes := "foo.md"
header := "header.md"
footer := "footer.md"
ctx := setup(releaseOpts{
releaseNotes: notes,
releaseHeader: header,
releaseFooter: footer,

View File

@ -8,14 +8,14 @@ import (
)
func TestRootCmd(t *testing.T) {
var mem = &exitMemento{}
mem := &exitMemento{}
Execute("1.2.3", mem.Exit, []string{"-h"})
require.Equal(t, 0, mem.code)
}
func TestRootCmdHelp(t *testing.T) {
var mem = &exitMemento{}
var cmd = newRootCmd("", mem.Exit).cmd
mem := &exitMemento{}
cmd := newRootCmd("", mem.Exit).cmd
cmd.SetArgs([]string{"-h"})
require.NoError(t, cmd.Execute())
require.Equal(t, 0, mem.code)
@ -23,8 +23,8 @@ func TestRootCmdHelp(t *testing.T) {
func TestRootCmdVersion(t *testing.T) {
var b bytes.Buffer
var mem = &exitMemento{}
var cmd = newRootCmd("1.2.3", mem.Exit).cmd
mem := &exitMemento{}
cmd := newRootCmd("1.2.3", mem.Exit).cmd
cmd.SetOut(&b)
cmd.SetArgs([]string{"-v"})
require.NoError(t, cmd.Execute())
@ -33,31 +33,31 @@ func TestRootCmdVersion(t *testing.T) {
}
func TestRootCmdExitCode(t *testing.T) {
var mem = &exitMemento{}
var cmd = newRootCmd("", mem.Exit)
var args = []string{"check", "--deprecated", "-f", "testdata/good.yml"}
mem := &exitMemento{}
cmd := newRootCmd("", mem.Exit)
args := []string{"check", "--deprecated", "-f", "testdata/good.yml"}
cmd.Execute(args)
require.Equal(t, 2, mem.code)
}
func TestRootRelease(t *testing.T) {
setup(t)
var mem = &exitMemento{}
var cmd = newRootCmd("", mem.Exit)
mem := &exitMemento{}
cmd := newRootCmd("", mem.Exit)
cmd.Execute([]string{})
require.Equal(t, 1, mem.code)
}
func TestRootReleaseDebug(t *testing.T) {
setup(t)
var mem = &exitMemento{}
var cmd = newRootCmd("", mem.Exit)
mem := &exitMemento{}
cmd := newRootCmd("", mem.Exit)
cmd.Execute([]string{"r", "--debug"})
require.Equal(t, 1, mem.code)
}
func TestShouldPrependRelease(t *testing.T) {
var result = func(args []string) bool {
result := func(args []string) bool {
return shouldPrependRelease(newRootCmd("1", func(_ int) {}).cmd, args)
}

View File

@ -154,7 +154,7 @@ func (artifacts Artifacts) List() []*Artifact {
// GroupByPlatform groups the artifacts by their platform.
func (artifacts Artifacts) GroupByPlatform() map[string][]*Artifact {
var result = map[string][]*Artifact{}
result := map[string][]*Artifact{}
for _, a := range artifacts.items {
plat := a.Goos + a.Goarch + a.Goarm + a.Gomips
result[plat] = append(result[plat], a)
@ -208,7 +208,7 @@ func ByType(t Type) Filter {
// ByFormats filters artifacts by a `Format` extra field.
func ByFormats(formats ...string) Filter {
var filters = make([]Filter, 0, len(formats))
filters := make([]Filter, 0, len(formats))
for _, format := range formats {
format := format
filters = append(filters, func(a *Artifact) bool {
@ -220,7 +220,7 @@ func ByFormats(formats ...string) Filter {
// ByIDs filter artifacts by an `ID` extra field.
func ByIDs(ids ...string) Filter {
var filters = make([]Filter, 0, len(ids))
filters := make([]Filter, 0, len(ids))
for _, id := range ids {
id := id
filters = append(filters, func(a *Artifact) bool {
@ -266,7 +266,7 @@ func (artifacts *Artifacts) Filter(filter Filter) Artifacts {
return *artifacts
}
var result = New()
result := New()
for _, a := range artifacts.items {
if filter(a) {
result.items = append(result.items, a)

View File

@ -162,7 +162,6 @@ func (s *GetExistingReleaseSuite) TestReleaseExists() {
require.NotNil(t, result)
require.Equal(t, *result, release)
require.NoError(t, err)
}
func TestGetExistingReleaseSuite(t *testing.T) {
@ -409,7 +408,7 @@ func TestGiteaUploadSuite(t *testing.T) {
}
func TestGiteaReleaseURLTemplate(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
GiteaURLs: config.GiteaURLs{
API: "https://gitea.com/api/v1",
Download: "https://gitea.com",

View File

@ -48,7 +48,7 @@ func TestNewGitHubClient(t *testing.T) {
}
func TestGitHubUploadReleaseIDNotInt(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
client, err := NewGitHub(ctx, ctx.Token)
require.NoError(t, err)
@ -60,7 +60,7 @@ func TestGitHubUploadReleaseIDNotInt(t *testing.T) {
}
func TestGitHubReleaseURLTemplate(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
GitHubURLs: config.GitHubURLs{
// default URL would otherwise be set via pipe/defaults
Download: DefaultGitHubDownloadURL,
@ -83,7 +83,7 @@ func TestGitHubReleaseURLTemplate(t *testing.T) {
}
func TestGitHubCreateReleaseWrongNameTemplate(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Release: config.Release{
NameTemplate: "{{.dddddddddd",
},

View File

@ -34,7 +34,7 @@ func NewGitLab(ctx *context.Context, token string) (Client, error) {
InsecureSkipVerify: ctx.Config.GitLabURLs.SkipTLSVerify,
},
}
var options = []gitlab.ClientOptionFunc{
options := []gitlab.ClientOptionFunc{
gitlab.WithHTTPClient(&http.Client{
Transport: transport,
}),
@ -52,7 +52,6 @@ func NewGitLab(ctx *context.Context, token string) (Client, error) {
// CloseMilestone closes a given milestone.
func (c *gitlabClient) CloseMilestone(ctx *context.Context, repo Repo, title string) error {
milestone, err := c.getMilestoneByTitle(repo, title)
if err != nil {
return err
}
@ -287,7 +286,6 @@ func (c *gitlabClient) Upload(
file.Name(),
nil,
)
if err != nil {
return err
}
@ -308,7 +306,6 @@ func (c *gitlabClient) Upload(
Name: &name,
URL: &linkURL,
})
if err != nil {
return RetriableError{err}
}
@ -360,7 +357,6 @@ func (c *gitlabClient) getMilestoneByTitle(repo Repo, title string) (*gitlab.Mil
for {
milestones, resp, err := c.client.Milestones.ListMilestones(repo.String(), opts)
if err != nil {
return nil, err
}

View File

@ -35,7 +35,7 @@ func TestFailToExtractHashFromProjectFileURL(t *testing.T) {
}
func TestGitLabReleaseURLTemplate(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
GitLabURLs: config.GitLabURLs{
// default URL would otherwise be set via pipe/defaults
Download: DefaultGitLabDownloadURL,

View File

@ -29,7 +29,7 @@ func TestExecute(t *testing.T) {
// Preload artifacts
ctx.Artifacts = artifact.New()
var folder = t.TempDir()
folder := t.TempDir()
for _, a := range []struct {
id string
ext string
@ -43,8 +43,8 @@ func TestExecute(t *testing.T) {
{"checksum", "sum", artifact.Checksum},
{"signature", "sig", artifact.Signature},
} {
var file = filepath.Join(folder, "a."+a.ext)
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0644))
file := filepath.Join(folder, "a."+a.ext)
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
ctx.Artifacts.Add(&artifact.Artifact{
Name: "a." + a.ext,
Goos: "linux",

View File

@ -12,7 +12,7 @@ import (
// Find resolves extra files globs et al into a map of names/paths or an error.
func Find(files []config.ExtraFile) (map[string]string, error) {
var result = map[string]string{}
result := map[string]string{}
for _, extra := range files {
if extra.Glob == "" {
continue
@ -27,7 +27,7 @@ func Find(files []config.ExtraFile) (map[string]string, error) {
log.Debugf("ignoring directory %s", file)
continue
}
var name = filepath.Base(file)
name := filepath.Base(file)
if old, ok := result[name]; ok {
log.Warnf("overriding %s with %s for name %s", old, file, name)
}

View File

@ -19,12 +19,12 @@ func IsRepo() bool {
// RunEnv runs a git command with the specified env vars and returns its output or errors.
func RunEnv(env map[string]string, args ...string) (string, error) {
// TODO: use exex.CommandContext here and refactor.
var extraArgs = []string{
extraArgs := []string{
"-c", "log.showSignature=false",
}
args = append(extraArgs, args...)
/* #nosec */
var cmd = exec.Command("git", args...)
cmd := exec.Command("git", args...)
if env != nil {
cmd.Env = []string{}

View File

@ -121,13 +121,13 @@ func getUsername(ctx *context.Context, upload *config.Upload, kind string) strin
return upload.Username
}
var key = fmt.Sprintf("%s_%s_USERNAME", strings.ToUpper(kind), strings.ToUpper(upload.Name))
key := fmt.Sprintf("%s_%s_USERNAME", strings.ToUpper(kind), strings.ToUpper(upload.Name))
return ctx.Env[key]
}
// password is optional
func getPassword(ctx *context.Context, upload *config.Upload, kind string) string {
var key = fmt.Sprintf("%s_%s_SECRET", strings.ToUpper(kind), strings.ToUpper(upload.Name))
key := fmt.Sprintf("%s_%s_SECRET", strings.ToUpper(kind), strings.ToUpper(upload.Name))
return ctx.Env[key]
}
@ -176,7 +176,7 @@ func Upload(ctx *context.Context, uploads []config.Upload, kind string, check Re
return err
}
var filter = artifact.Or(filters...)
filter := artifact.Or(filters...)
if len(upload.IDs) > 0 {
filter = artifact.And(filter, artifact.ByIDs(upload.IDs...))
}
@ -189,9 +189,9 @@ func Upload(ctx *context.Context, uploads []config.Upload, kind string, check Re
}
func uploadWithFilter(ctx *context.Context, upload *config.Upload, filter artifact.Filter, kind string, check ResponseChecker) error {
var artifacts = ctx.Artifacts.Filter(filter).List()
artifacts := ctx.Artifacts.Filter(filter).List()
log.Debugf("will upload %d artifacts", len(artifacts))
var g = semerrgroup.New(ctx.Parallelism)
g := semerrgroup.New(ctx.Parallelism)
for _, artifact := range artifacts {
artifact := artifact
g.Go(func() error {
@ -233,7 +233,7 @@ func uploadAsset(ctx *context.Context, upload *config.Upload, artifact *artifact
}
log.Debugf("generated target url: %s", targetURL)
var headers = map[string]string{}
headers := map[string]string{}
if upload.CustomHeaders != nil {
for name, value := range upload.CustomHeaders {
resolvedValue, err := resolveHeaderTemplate(ctx, upload, artifact, value)
@ -364,7 +364,7 @@ func executeHTTPRequest(ctx *context.Context, upload *config.Upload, req *h.Requ
// resolveTargetTemplate returns the resolved target template with replaced variables
// Those variables can be replaced by the given context, goos, goarch, goarm and more.
func resolveTargetTemplate(ctx *context.Context, upload *config.Upload, artifact *artifact.Artifact) (string, error) {
var replacements = map[string]string{}
replacements := map[string]string{}
if upload.Mode == ModeBinary {
// TODO: multiple archives here
replacements = ctx.Config.Archives[0].Replacements
@ -377,7 +377,7 @@ func resolveTargetTemplate(ctx *context.Context, upload *config.Upload, artifact
// resolveHeaderTemplate returns the resolved custom header template with replaced variables
// Those variables can be replaced by the given context, goos, goarch, goarm and more.
func resolveHeaderTemplate(ctx *context.Context, upload *config.Upload, artifact *artifact.Artifact, headerValue string) (string, error) {
var replacements = map[string]string{}
replacements := map[string]string{}
if upload.Mode == ModeBinary {
// TODO: multiple archives here
replacements = ctx.Config.Archives[0].Replacements

View File

@ -21,8 +21,8 @@ import (
)
func TestAssetOpenDefault(t *testing.T) {
var tf = filepath.Join(t.TempDir(), "asset")
require.NoError(t, os.WriteFile(tf, []byte("a"), 0765))
tf := filepath.Join(t.TempDir(), "asset")
require.NoError(t, os.WriteFile(tf, []byte("a"), 0o765))
a, err := assetOpenDefault("blah", &artifact.Artifact{
Path: tf,
@ -237,7 +237,7 @@ func TestUpload(t *testing.T) {
ctx.Env["TEST_A_USERNAME"] = "u2"
ctx.Version = "2.1.0"
ctx.Artifacts = artifact.New()
var folder = t.TempDir()
folder := t.TempDir()
for _, a := range []struct {
ext string
typ artifact.Type
@ -250,8 +250,8 @@ func TestUpload(t *testing.T) {
{"sum", artifact.Checksum},
{"sig", artifact.Signature},
} {
var file = filepath.Join(folder, "a."+a.ext)
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0644))
file := filepath.Join(folder, "a."+a.ext)
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
ctx.Artifacts.Add(&artifact.Artifact{
Name: "a." + a.ext,
Goos: "linux",
@ -273,7 +273,8 @@ func TestUpload(t *testing.T) {
setup func(*httptest.Server) (*context.Context, config.Upload)
check func(r []*h.Request) error
}{
{"wrong-mode", true, true, true, true,
{
"wrong-mode", true, true, true, true,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: "wrong-mode",
@ -285,7 +286,8 @@ func TestUpload(t *testing.T) {
},
checks(),
},
{"username-from-env", true, true, false, false,
{
"username-from-env", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeArchive,
@ -299,7 +301,8 @@ func TestUpload(t *testing.T) {
check{"/blah/2.1.0/a.tar", "u2", "x", content, map[string]string{}},
),
},
{"post", true, true, false, false,
{
"post", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Method: h.MethodPost,
@ -315,7 +318,8 @@ func TestUpload(t *testing.T) {
check{"/blah/2.1.0/a.tar", "u1", "x", content, map[string]string{}},
),
},
{"archive", true, true, false, false,
{
"archive", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeArchive,
@ -330,7 +334,8 @@ func TestUpload(t *testing.T) {
check{"/blah/2.1.0/a.tar", "u1", "x", content, map[string]string{}},
),
},
{"archive_with_os_tmpl", true, true, false, false,
{
"archive_with_os_tmpl", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeArchive,
@ -345,7 +350,8 @@ func TestUpload(t *testing.T) {
check{"/blah/2.1.0/linux/amd64/a.tar", "u1", "x", content, map[string]string{}},
),
},
{"archive_with_ids", true, true, false, false,
{
"archive_with_ids", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeArchive,
@ -361,7 +367,8 @@ func TestUpload(t *testing.T) {
check{"/blah/2.1.0/a.tar", "u1", "x", content, map[string]string{}},
),
},
{"binary", true, true, false, false,
{
"binary", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeBinary,
@ -373,7 +380,8 @@ func TestUpload(t *testing.T) {
},
checks(check{"/blah/2.1.0/a.ubi", "u2", "x", content, map[string]string{}}),
},
{"binary_with_os_tmpl", true, true, false, false,
{
"binary_with_os_tmpl", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeBinary,
@ -385,7 +393,8 @@ func TestUpload(t *testing.T) {
},
checks(check{"/blah/2.1.0/Linux/amd64/a.ubi", "u2", "x", content, map[string]string{}}),
},
{"binary_with_ids", true, true, false, false,
{
"binary_with_ids", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeBinary,
@ -398,7 +407,8 @@ func TestUpload(t *testing.T) {
},
checks(check{"/blah/2.1.0/a.ubi", "u2", "x", content, map[string]string{}}),
},
{"binary-add-ending-bar", true, true, false, false,
{
"binary-add-ending-bar", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeBinary,
@ -410,7 +420,8 @@ func TestUpload(t *testing.T) {
},
checks(check{"/blah/2.1.0/a.ubi", "u2", "x", content, map[string]string{}}),
},
{"archive-with-checksum-and-signature", true, true, false, false,
{
"archive-with-checksum-and-signature", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeArchive,
@ -429,7 +440,8 @@ func TestUpload(t *testing.T) {
check{"/blah/2.1.0/a.sig", "u3", "x", content, map[string]string{}},
),
},
{"bad-template", true, true, true, true,
{
"bad-template", true, true, true, true,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeBinary,
@ -443,7 +455,8 @@ func TestUpload(t *testing.T) {
},
checks(),
},
{"failed-request", true, true, true, true,
{
"failed-request", true, true, true, true,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeBinary,
@ -457,7 +470,8 @@ func TestUpload(t *testing.T) {
},
checks(),
},
{"broken-cert", false, true, false, true,
{
"broken-cert", false, true, false, true,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeBinary,
@ -471,7 +485,8 @@ func TestUpload(t *testing.T) {
},
checks(),
},
{"skip-publishing", true, true, true, true,
{
"skip-publishing", true, true, true, true,
func(s *httptest.Server) (*context.Context, config.Upload) {
c := *ctx
c.SkipPublish = true
@ -479,7 +494,8 @@ func TestUpload(t *testing.T) {
},
checks(),
},
{"checksumheader", true, true, false, false,
{
"checksumheader", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeBinary,
@ -492,7 +508,8 @@ func TestUpload(t *testing.T) {
},
checks(check{"/blah/2.1.0/a.ubi", "u2", "x", content, map[string]string{"-x-sha256": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"}}),
},
{"custom-headers", true, true, false, false,
{
"custom-headers", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeBinary,
@ -507,7 +524,8 @@ func TestUpload(t *testing.T) {
},
checks(check{"/blah/2.1.0/a.ubi", "u2", "x", content, map[string]string{"x-custom-header-name": "custom-header-value"}}),
},
{"custom-headers-with-template", true, true, false, false,
{
"custom-headers-with-template", true, true, false, false,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeBinary,
@ -522,7 +540,8 @@ func TestUpload(t *testing.T) {
},
checks(check{"/blah/2.1.0/a.ubi", "u2", "x", content, map[string]string{"x-project-name": "blah"}}),
},
{"invalid-template-in-custom-headers", true, true, true, true,
{
"invalid-template-in-custom-headers", true, true, true, true,
func(s *httptest.Server) (*context.Context, config.Upload) {
return ctx, config.Upload{
Mode: ModeBinary,
@ -572,7 +591,6 @@ func TestUpload(t *testing.T) {
})
}
}
}
func cert(srv *httptest.Server) string {

View File

@ -7,14 +7,14 @@ import (
)
func TestIDs(t *testing.T) {
var ids = New("foos")
ids := New("foos")
ids.Inc("foo")
ids.Inc("bar")
require.NoError(t, ids.Validate())
}
func TestIDsError(t *testing.T) {
var ids = New("builds")
ids := New("builds")
ids.Inc("foo")
ids.Inc("bar")
ids.Inc("foo")

View File

@ -46,12 +46,12 @@ func (Pipe) String() string {
// Default sets the pipe defaults.
func (Pipe) Default(ctx *context.Context) error {
var ids = ids.New("archives")
ids := ids.New("archives")
if len(ctx.Config.Archives) == 0 {
ctx.Config.Archives = append(ctx.Config.Archives, config.Archive{})
}
for i := range ctx.Config.Archives {
var archive = &ctx.Config.Archives[i]
archive := &ctx.Config.Archives[i]
if archive.Format == "" {
archive.Format = "tar.gz"
}
@ -88,10 +88,10 @@ func (Pipe) Default(ctx *context.Context) error {
// Run the pipe.
func (Pipe) Run(ctx *context.Context) error {
var g = semerrgroup.New(ctx.Parallelism)
g := semerrgroup.New(ctx.Parallelism)
for i, archive := range ctx.Config.Archives {
archive := archive
var artifacts = ctx.Artifacts.Filter(
artifacts := ctx.Artifacts.Filter(
artifact.And(
artifact.ByType(artifact.Binary),
artifact.ByIDs(archive.Builds...),
@ -115,7 +115,7 @@ func (Pipe) Run(ctx *context.Context) error {
}
func checkArtifacts(artifacts map[string][]*artifact.Artifact) error {
var lens = map[int]bool{}
lens := map[int]bool{}
for _, v := range artifacts {
lens[len(v)] = true
}
@ -126,7 +126,7 @@ func checkArtifacts(artifacts map[string][]*artifact.Artifact) error {
}
func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Artifact) error {
var format = packageFormat(arch, binaries[0].Goos)
format := packageFormat(arch, binaries[0].Goos)
folder, err := tmpl.New(ctx).
WithArtifact(binaries[0], arch.Replacements).
Apply(arch.NameTemplate)
@ -135,7 +135,7 @@ func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Arti
}
archivePath := filepath.Join(ctx.Config.Dist, folder+"."+format)
lock.Lock()
if err := os.MkdirAll(filepath.Dir(archivePath), 0755|os.ModeDir); err != nil {
if err := os.MkdirAll(filepath.Dir(archivePath), 0o755|os.ModeDir); err != nil {
lock.Unlock()
return err
}
@ -151,7 +151,7 @@ func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Arti
lock.Unlock()
defer archiveFile.Close()
var log = log.WithField("archive", archivePath)
log := log.WithField("archive", archivePath)
log.Info("creating")
template := tmpl.New(ctx).
@ -161,7 +161,7 @@ func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Arti
return err
}
var a = NewEnhancedArchive(archive.New(archiveFile), wrap)
a := NewEnhancedArchive(archive.New(archiveFile), wrap)
defer a.Close()
files, err := findFiles(template, arch)

View File

@ -25,19 +25,19 @@ func TestDescription(t *testing.T) {
func createFakeBinary(t *testing.T, dist, arch, bin string) {
t.Helper()
var path = filepath.Join(dist, arch, bin)
require.NoError(t, os.MkdirAll(filepath.Dir(path), 0755))
path := filepath.Join(dist, arch, bin)
require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
f, err := os.Create(path)
require.NoError(t, err)
require.NoError(t, f.Close())
}
func TestRunPipe(t *testing.T) {
var folder = testlib.Mktmp(t)
folder := testlib.Mktmp(t)
for _, format := range []string{"tar.gz", "zip"} {
t.Run("Archive format "+format, func(t *testing.T) {
var dist = filepath.Join(folder, format+"_dist")
require.NoError(t, os.Mkdir(dist, 0755))
dist := filepath.Join(folder, format+"_dist")
require.NoError(t, os.Mkdir(dist, 0o755))
for _, arch := range []string{"darwinamd64", "linux386", "linuxarm7", "linuxmipssoftfloat"} {
createFakeBinary(t, dist, arch, "bin/mybin")
}
@ -47,11 +47,11 @@ func TestRunPipe(t *testing.T) {
require.NoError(t, err)
require.NoError(t, f.Close())
}
require.NoError(t, os.MkdirAll(filepath.Join(folder, "foo", "bar", "foobar"), 0755))
require.NoError(t, os.MkdirAll(filepath.Join(folder, "foo", "bar", "foobar"), 0o755))
f, err := os.Create(filepath.Join(filepath.Join(folder, "foo", "bar", "foobar", "blah.txt")))
require.NoError(t, err)
require.NoError(t, f.Close())
var ctx = context.New(
ctx := context.New(
config.Project{
Dist: dist,
ProjectName: "foobar",
@ -74,7 +74,7 @@ func TestRunPipe(t *testing.T) {
},
},
)
var darwinBuild = &artifact.Artifact{
darwinBuild := &artifact.Artifact{
Goos: "darwin",
Goarch: "amd64",
Name: "bin/mybin",
@ -85,7 +85,7 @@ func TestRunPipe(t *testing.T) {
"ID": "default",
},
}
var linux386Build = &artifact.Artifact{
linux386Build := &artifact.Artifact{
Goos: "linux",
Goarch: "386",
Name: "bin/mybin",
@ -96,7 +96,7 @@ func TestRunPipe(t *testing.T) {
"ID": "default",
},
}
var linuxArmBuild = &artifact.Artifact{
linuxArmBuild := &artifact.Artifact{
Goos: "linux",
Goarch: "arm",
Goarm: "7",
@ -108,7 +108,7 @@ func TestRunPipe(t *testing.T) {
"ID": "default",
},
}
var linuxMipsBuild = &artifact.Artifact{
linuxMipsBuild := &artifact.Artifact{
Goos: "linux",
Goarch: "mips",
Gomips: "softfloat",
@ -120,7 +120,7 @@ func TestRunPipe(t *testing.T) {
"ID": "default",
},
}
var windowsBuild = &artifact.Artifact{
windowsBuild := &artifact.Artifact{
Goos: "windows",
Goarch: "amd64",
Name: "bin/mybin.exe",
@ -141,7 +141,7 @@ func TestRunPipe(t *testing.T) {
ctx.Git.CurrentTag = "v0.0.1"
ctx.Config.Archives[0].Format = format
require.NoError(t, Pipe{}.Run(ctx))
var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List()
archives := ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List()
for _, arch := range archives {
require.Equal(t, "myid", arch.Extra["ID"].(string), "all archives should have the archive ID set")
}
@ -183,14 +183,14 @@ func TestRunPipe(t *testing.T) {
}
func TestRunPipeDifferentBinaryCount(t *testing.T) {
var folder = testlib.Mktmp(t)
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
folder := testlib.Mktmp(t)
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
for _, arch := range []string{"darwinamd64", "linuxamd64"} {
createFakeBinary(t, dist, arch, "bin/mybin")
}
createFakeBinary(t, dist, "darwinamd64", "bin/foobar")
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Dist: dist,
ProjectName: "foobar",
Archives: []config.Archive{
@ -202,7 +202,7 @@ func TestRunPipeDifferentBinaryCount(t *testing.T) {
},
},
})
var darwinBuild = &artifact.Artifact{
darwinBuild := &artifact.Artifact{
Goos: "darwin",
Goarch: "amd64",
Name: "bin/mybin",
@ -213,7 +213,7 @@ func TestRunPipeDifferentBinaryCount(t *testing.T) {
"ID": "default",
},
}
var darwinBuild2 = &artifact.Artifact{
darwinBuild2 := &artifact.Artifact{
Goos: "darwin",
Goarch: "amd64",
Name: "bin/foobar",
@ -224,7 +224,7 @@ func TestRunPipeDifferentBinaryCount(t *testing.T) {
"ID": "foobar",
},
}
var linuxArmBuild = &artifact.Artifact{
linuxArmBuild := &artifact.Artifact{
Goos: "linux",
Goarch: "amd64",
Name: "bin/mybin",
@ -254,10 +254,10 @@ func TestRunPipeDifferentBinaryCount(t *testing.T) {
}
func TestRunPipeNoBinaries(t *testing.T) {
var folder = testlib.Mktmp(t)
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
var ctx = context.New(config.Project{
folder := testlib.Mktmp(t)
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := context.New(config.Project{
Dist: dist,
ProjectName: "foobar",
Archives: []config.Archive{{}},
@ -275,7 +275,7 @@ func zipFiles(t *testing.T, path string) []string {
require.NoError(t, err)
r, err := zip.NewReader(f, info.Size())
require.NoError(t, err)
var paths = make([]string, len(r.File))
paths := make([]string, len(r.File))
for i, zf := range r.File {
paths[i] = zf.Name
}
@ -290,7 +290,7 @@ func tarFiles(t *testing.T, path string) []string {
gr, err := gzip.NewReader(f)
require.NoError(t, err)
defer gr.Close()
var r = tar.NewReader(gr)
r := tar.NewReader(gr)
var paths []string
for {
next, err := r.Next()
@ -304,11 +304,11 @@ func tarFiles(t *testing.T, path string) []string {
}
func TestRunPipeBinary(t *testing.T) {
var folder = testlib.Mktmp(t)
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0755))
folder := testlib.Mktmp(t)
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0o755))
f, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
require.NoError(t, err)
require.NoError(t, f.Close())
@ -318,7 +318,7 @@ func TestRunPipeBinary(t *testing.T) {
f, err = os.Create(filepath.Join(folder, "README.md"))
require.NoError(t, err)
require.NoError(t, f.Close())
var ctx = context.New(
ctx := context.New(
config.Project{
Dist: dist,
Archives: []config.Archive{
@ -356,7 +356,7 @@ func TestRunPipeBinary(t *testing.T) {
},
})
require.NoError(t, Pipe{}.Run(ctx))
var binaries = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableBinary))
binaries := ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableBinary))
darwin := binaries.Filter(artifact.ByGoos("darwin")).List()[0]
windows := binaries.Filter(artifact.ByGoos("windows")).List()[0]
require.Equal(t, "mybin_0.0.1_darwin_amd64", darwin.Name)
@ -365,7 +365,7 @@ func TestRunPipeBinary(t *testing.T) {
}
func TestRunPipeDistRemoved(t *testing.T) {
var ctx = context.New(
ctx := context.New(
config.Project{
Dist: "/tmp/path/to/nope",
Archives: []config.Archive{
@ -395,14 +395,14 @@ func TestRunPipeDistRemoved(t *testing.T) {
}
func TestRunPipeInvalidGlob(t *testing.T) {
var folder = testlib.Mktmp(t)
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
folder := testlib.Mktmp(t)
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0o755))
f, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
require.NoError(t, err)
require.NoError(t, f.Close())
var ctx = context.New(
ctx := context.New(
config.Project{
Dist: dist,
Archives: []config.Archive{
@ -433,14 +433,14 @@ func TestRunPipeInvalidGlob(t *testing.T) {
}
func TestRunPipeInvalidNameTemplate(t *testing.T) {
var folder = testlib.Mktmp(t)
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
folder := testlib.Mktmp(t)
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0o755))
f, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
require.NoError(t, err)
require.NoError(t, f.Close())
var ctx = context.New(
ctx := context.New(
config.Project{
Dist: dist,
Archives: []config.Archive{
@ -468,14 +468,14 @@ func TestRunPipeInvalidNameTemplate(t *testing.T) {
}
func TestRunPipeInvalidFilesNameTemplate(t *testing.T) {
var folder = testlib.Mktmp(t)
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
folder := testlib.Mktmp(t)
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0o755))
f, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
require.NoError(t, err)
require.NoError(t, f.Close())
var ctx = context.New(
ctx := context.New(
config.Project{
Dist: dist,
Archives: []config.Archive{
@ -506,14 +506,14 @@ func TestRunPipeInvalidFilesNameTemplate(t *testing.T) {
}
func TestRunPipeInvalidWrapInDirectoryTemplate(t *testing.T) {
var folder = testlib.Mktmp(t)
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
folder := testlib.Mktmp(t)
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0o755))
f, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
require.NoError(t, err)
require.NoError(t, f.Close())
var ctx = context.New(
ctx := context.New(
config.Project{
Dist: dist,
Archives: []config.Archive{
@ -542,17 +542,17 @@ func TestRunPipeInvalidWrapInDirectoryTemplate(t *testing.T) {
}
func TestRunPipeWrap(t *testing.T) {
var folder = testlib.Mktmp(t)
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
folder := testlib.Mktmp(t)
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0o755))
f, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
require.NoError(t, err)
require.NoError(t, f.Close())
f, err = os.Create(filepath.Join(folder, "README.md"))
require.NoError(t, err)
require.NoError(t, f.Close())
var ctx = context.New(
ctx := context.New(
config.Project{
Dist: dist,
Archives: []config.Archive{
@ -585,7 +585,7 @@ func TestRunPipeWrap(t *testing.T) {
})
require.NoError(t, Pipe{}.Run(ctx))
var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List()
archives := ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List()
require.Len(t, archives, 1)
require.Equal(t, "foo_macOS", archives[0].ExtraOr("WrappedIn", ""))
@ -608,7 +608,7 @@ func TestRunPipeWrap(t *testing.T) {
}
func TestDefault(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Archives: []config.Archive{},
},
@ -620,7 +620,7 @@ func TestDefault(t *testing.T) {
}
func TestDefaultSet(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Archives: []config.Archive{
{
@ -641,7 +641,7 @@ func TestDefaultSet(t *testing.T) {
}
func TestDefaultFormatBinary(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Archives: []config.Archive{
{
@ -655,7 +655,7 @@ func TestDefaultFormatBinary(t *testing.T) {
}
func TestFormatFor(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Archives: []config.Archive{
{
@ -676,11 +676,11 @@ func TestFormatFor(t *testing.T) {
}
func TestBinaryOverride(t *testing.T) {
var folder = testlib.Mktmp(t)
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0755))
folder := testlib.Mktmp(t)
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0o755))
f, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
require.NoError(t, err)
require.NoError(t, f.Close())
@ -692,7 +692,7 @@ func TestBinaryOverride(t *testing.T) {
require.NoError(t, f.Close())
for _, format := range []string{"tar.gz", "zip"} {
t.Run("Archive format "+format, func(t *testing.T) {
var ctx = context.New(
ctx := context.New(
config.Project{
Dist: dist,
ProjectName: "foobar",
@ -741,7 +741,7 @@ func TestBinaryOverride(t *testing.T) {
ctx.Config.Archives[0].Format = format
require.NoError(t, Pipe{}.Run(ctx))
var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive))
archives := ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive))
darwin := archives.Filter(artifact.ByGoos("darwin")).List()[0]
require.Equal(t, "foobar_0.0.1_darwin_amd64."+format, darwin.Name)
require.Equal(t, format, darwin.ExtraOr("Format", ""))
@ -756,18 +756,18 @@ func TestBinaryOverride(t *testing.T) {
}
func TestRunPipeSameArchiveFilename(t *testing.T) {
var folder = testlib.Mktmp(t)
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0755))
folder := testlib.Mktmp(t)
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0o755))
f, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
require.NoError(t, err)
require.NoError(t, f.Close())
f, err = os.Create(filepath.Join(dist, "windowsamd64", "mybin.exe"))
require.NoError(t, err)
require.NoError(t, f.Close())
var ctx = context.New(
ctx := context.New(
config.Project{
Dist: dist,
ProjectName: "foobar",
@ -815,7 +815,7 @@ func TestRunPipeSameArchiveFilename(t *testing.T) {
}
func TestDuplicateFilesInsideArchive(t *testing.T) {
var folder = t.TempDir()
folder := t.TempDir()
f, err := ioutil.TempFile(folder, "")
require.NoError(t, err)
@ -856,7 +856,7 @@ func TestWrapInDirectory(t *testing.T) {
}
func TestSeveralArchivesWithTheSameID(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Archives: []config.Archive{
{

View File

@ -35,18 +35,14 @@ func teardown() {
server.Close()
}
func testMethod(t *testing.T, r *http.Request, want string) {
func requireMethodPut(t *testing.T, r *http.Request) {
t.Helper()
if got := r.Method; got != want {
t.Errorf("Request method: %v, want %v", got, want)
}
require.Equal(t, http.MethodPut, r.Method)
}
func testHeader(t *testing.T, r *http.Request, header, want string) {
func requireHeader(t *testing.T, r *http.Request, header, want string) {
t.Helper()
if got := r.Header.Get(header); got != want {
t.Errorf("Header.Get(%q) returned %q, want %q", header, got, want)
}
require.Equal(t, want, r.Header.Get(header))
}
// TODO: improve all tests bellow by checking wether the mocked handlers
@ -66,10 +62,10 @@ func TestRunPipe_ModeBinary(t *testing.T) {
// Dummy artifactories
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{
@ -92,10 +88,10 @@ func TestRunPipe_ModeBinary(t *testing.T) {
}`)
})
mux.HandleFunc("/example-repo-local/mybin/linux/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{
@ -118,10 +114,10 @@ func TestRunPipe_ModeBinary(t *testing.T) {
}`)
})
mux.HandleFunc("/production-repo-remote/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "productionuser" with secret "productionuser-apikey"
testHeader(t, r, "Authorization", "Basic cHJvZHVjdGlvbnVzZXI6cHJvZHVjdGlvbnVzZXItYXBpa2V5")
requireHeader(t, r, "Authorization", "Basic cHJvZHVjdGlvbnVzZXI6cHJvZHVjdGlvbnVzZXItYXBpa2V5")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{
@ -144,10 +140,10 @@ func TestRunPipe_ModeBinary(t *testing.T) {
}`)
})
mux.HandleFunc("/production-repo-remote/mybin/linux/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "productionuser" with secret "productionuser-apikey"
testHeader(t, r, "Authorization", "Basic cHJvZHVjdGlvbnVzZXI6cHJvZHVjdGlvbnVzZXItYXBpa2V5")
requireHeader(t, r, "Authorization", "Basic cHJvZHVjdGlvbnVzZXI6cHJvZHVjdGlvbnVzZXItYXBpa2V5")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{
@ -255,9 +251,9 @@ func TestRunPipe_ModeArchive(t *testing.T) {
// Dummy artifactories
mux.HandleFunc("/example-repo-local/goreleaser/1.0.0/bin.tar.gz", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
requireMethodPut(t, r)
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{
@ -281,9 +277,9 @@ func TestRunPipe_ModeArchive(t *testing.T) {
uploads.Store("targz", true)
})
mux.HandleFunc("/example-repo-local/goreleaser/1.0.0/bin.deb", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
requireMethodPut(t, r)
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{
@ -399,10 +395,10 @@ func TestRunPipe_BadCredentials(t *testing.T) {
// Dummy artifactories
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.WriteHeader(http.StatusUnauthorized)
fmt.Fprint(w, `{
@ -459,10 +455,10 @@ func TestRunPipe_UnparsableErrorResponse(t *testing.T) {
// Dummy artifactories
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.WriteHeader(http.StatusUnauthorized)
fmt.Fprint(w, `...{

View File

@ -60,7 +60,7 @@ func TestRunPipeFail(t *testing.T) {
}
func TestRunWithEnv(t *testing.T) {
var f = filepath.Join(t.TempDir(), "testfile")
f := filepath.Join(t.TempDir(), "testfile")
require.NoError(t, Pipe{}.Run(context.New(
config.Project{
Env: []string{

View File

@ -23,7 +23,7 @@ func TestNoBlob(t *testing.T) {
func TestDefaultsNoConfig(t *testing.T) {
errorString := "bucket or provider cannot be empty"
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Blobs: []config.Blob{
{},
},
@ -33,7 +33,7 @@ func TestDefaultsNoConfig(t *testing.T) {
func TestDefaultsNoBucket(t *testing.T) {
errorString := "bucket or provider cannot be empty"
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Blobs: []config.Blob{
{
Provider: "azblob",
@ -45,7 +45,7 @@ func TestDefaultsNoBucket(t *testing.T) {
func TestDefaultsNoProvider(t *testing.T) {
errorString := "bucket or provider cannot be empty"
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Blobs: []config.Blob{
{
Bucket: "goreleaser-bucket",
@ -56,7 +56,7 @@ func TestDefaultsNoProvider(t *testing.T) {
}
func TestDefaults(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Blobs: []config.Blob{
{
Bucket: "foo",
@ -86,7 +86,7 @@ func TestDefaults(t *testing.T) {
}
func TestDefaultsWithProvider(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Blobs: []config.Blob{
{
Bucket: "foo",
@ -110,7 +110,7 @@ func TestPipe_Publish(t *testing.T) {
}
func TestPipe_PublishExtraFiles(t *testing.T) {
var extra = []config.ExtraFile{
extra := []config.ExtraFile{
{
Glob: "./testdata/file.golden",
},
@ -122,14 +122,14 @@ func pipePublish(t *testing.T, extra []config.ExtraFile) {
t.Helper()
gcloudCredentials, _ := filepath.Abs("./testdata/credentials.json")
var folder = t.TempDir()
folder := t.TempDir()
tgzpath := filepath.Join(folder, "bin.tar.gz")
debpath := filepath.Join(folder, "bin.deb")
require.NoError(t, os.WriteFile(tgzpath, []byte("fake\ntargz"), 0744))
require.NoError(t, os.WriteFile(debpath, []byte("fake\ndeb"), 0744))
require.NoError(t, os.WriteFile(tgzpath, []byte("fake\ntargz"), 0o744))
require.NoError(t, os.WriteFile(debpath, []byte("fake\ndeb"), 0o744))
// Azure Blob Context
var azblobctx = context.New(config.Project{
azblobctx := context.New(config.Project{
Dist: folder,
ProjectName: "testupload",
Blobs: []config.Blob{
@ -154,7 +154,7 @@ func pipePublish(t *testing.T, extra []config.ExtraFile) {
})
// Google Cloud Storage Context
var gsctx = context.New(config.Project{
gsctx := context.New(config.Project{
Dist: folder,
ProjectName: "testupload",
Blobs: []config.Blob{
@ -180,7 +180,7 @@ func pipePublish(t *testing.T, extra []config.ExtraFile) {
})
// AWS S3 Context
var s3ctx = context.New(config.Project{
s3ctx := context.New(config.Project{
Dist: folder,
ProjectName: "testupload",
Blobs: []config.Blob{

View File

@ -40,7 +40,7 @@ func urlFor(ctx *context.Context, conf config.Blob) (string, error) {
return bucketURL, nil
}
var query = url.Values{}
query := url.Values{}
if conf.Endpoint != "" {
query.Add("endpoint", conf.Endpoint)
query.Add("s3ForcePathStyle", "true")
@ -73,7 +73,7 @@ func doUpload(ctx *context.Context, conf config.Blob) error {
return err
}
var filter = artifact.Or(
filter := artifact.Or(
artifact.ByType(artifact.UploadableArchive),
artifact.ByType(artifact.UploadableBinary),
artifact.ByType(artifact.UploadableSourceArchive),
@ -85,19 +85,19 @@ func doUpload(ctx *context.Context, conf config.Blob) error {
filter = artifact.And(filter, artifact.ByIDs(conf.IDs...))
}
var up = newUploader(ctx)
up := newUploader(ctx)
if err := up.Open(ctx, bucketURL); err != nil {
return handleError(err, bucketURL)
}
defer up.Close()
var g = semerrgroup.New(ctx.Parallelism)
g := semerrgroup.New(ctx.Parallelism)
for _, artifact := range ctx.Artifacts.Filter(filter).List() {
artifact := artifact
g.Go(func() error {
// TODO: replace this with ?prefix=folder on the bucket url
var dataFile = artifact.Path
var uploadFile = path.Join(folder, artifact.Name)
dataFile := artifact.Path
uploadFile := path.Join(folder, artifact.Name)
err := uploadData(ctx, conf, up, dataFile, uploadFile, bucketURL)
@ -113,7 +113,7 @@ func doUpload(ctx *context.Context, conf config.Blob) error {
name := name
fullpath := fullpath
g.Go(func() error {
var uploadFile = path.Join(folder, name)
uploadFile := path.Join(folder, name)
err := uploadData(ctx, conf, up, fullpath, uploadFile, bucketURL)
@ -215,6 +215,7 @@ func (u *productionUploader) Close() error {
}
return u.bucket.Close()
}
func (u *productionUploader) Open(ctx *context.Context, bucket string) error {
log.WithFields(log.Fields{
"bucket": bucket,

View File

@ -91,9 +91,9 @@ func TestFullFormulae(t *testing.T) {
}), data)
require.NoError(t, err)
var golden = "testdata/test.rb.golden"
golden := "testdata/test.rb.golden"
if *update {
err := os.WriteFile(golden, []byte(formulae), 0655)
err := os.WriteFile(golden, []byte(formulae), 0o655)
require.NoError(t, err)
}
bts, err := os.ReadFile(golden)
@ -111,9 +111,9 @@ func TestFullFormulaeLinuxOnly(t *testing.T) {
}), data)
require.NoError(t, err)
var golden = "testdata/test_linux_only.rb.golden"
golden := "testdata/test_linux_only.rb.golden"
if *update {
err := os.WriteFile(golden, []byte(formulae), 0655)
err := os.WriteFile(golden, []byte(formulae), 0o655)
require.NoError(t, err)
}
bts, err := os.ReadFile(golden)
@ -131,7 +131,7 @@ func TestFormulaeSimple(t *testing.T) {
}
func TestSplit(t *testing.T) {
var parts = split("system \"true\"\nsystem \"#{bin}/foo -h\"")
parts := split("system \"true\"\nsystem \"#{bin}/foo -h\"")
require.Equal(t, []string{"system \"true\"", "system \"#{bin}/foo -h\""}, parts)
parts = split("")
require.Equal(t, []string{}, parts)
@ -180,8 +180,8 @@ func TestRunPipe(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
var folder = t.TempDir()
var ctx = &context.Context{
folder := t.TempDir()
ctx := &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
@ -223,7 +223,7 @@ func TestRunPipe(t *testing.T) {
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
},
})
var path = filepath.Join(folder, "bin.tar.gz")
path := filepath.Join(folder, "bin.tar.gz")
ctx.Artifacts.Add(&artifact.Artifact{
Name: "bin.tar.gz",
Path: path,
@ -241,13 +241,13 @@ func TestRunPipe(t *testing.T) {
require.NoError(t, err)
require.NoError(t, f.Close())
client := &DummyClient{}
var distFile = filepath.Join(folder, name+".rb")
distFile := filepath.Join(folder, name+".rb")
require.NoError(t, doRun(ctx, ctx.Config.Brews[0], client))
require.True(t, client.CreatedFile)
var golden = fmt.Sprintf("testdata/%s.rb.golden", name)
golden := fmt.Sprintf("testdata/%s.rb.golden", name)
if *update {
require.NoError(t, os.WriteFile(golden, []byte(client.Content), 0655))
require.NoError(t, os.WriteFile(golden, []byte(client.Content), 0o655))
}
bts, err := os.ReadFile(golden)
require.NoError(t, err)
@ -261,8 +261,8 @@ func TestRunPipe(t *testing.T) {
}
func TestRunPipeNameTemplate(t *testing.T) {
var folder = t.TempDir()
var ctx = &context.Context{
folder := t.TempDir()
ctx := &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
@ -288,7 +288,7 @@ func TestRunPipeNameTemplate(t *testing.T) {
},
},
}
var path = filepath.Join(folder, "bin.tar.gz")
path := filepath.Join(folder, "bin.tar.gz")
ctx.Artifacts.Add(&artifact.Artifact{
Name: "bin.tar.gz",
Path: path,
@ -306,13 +306,13 @@ func TestRunPipeNameTemplate(t *testing.T) {
require.NoError(t, err)
require.NoError(t, f.Close())
client := &DummyClient{}
var distFile = filepath.Join(folder, "foo_is_bar.rb")
distFile := filepath.Join(folder, "foo_is_bar.rb")
require.NoError(t, doRun(ctx, ctx.Config.Brews[0], client))
require.True(t, client.CreatedFile)
var golden = "testdata/foo_is_bar.rb.golden"
golden := "testdata/foo_is_bar.rb.golden"
if *update {
require.NoError(t, os.WriteFile(golden, []byte(client.Content), 0655))
require.NoError(t, os.WriteFile(golden, []byte(client.Content), 0o655))
}
bts, err := os.ReadFile(golden)
require.NoError(t, err)
@ -324,8 +324,8 @@ func TestRunPipeNameTemplate(t *testing.T) {
}
func TestRunPipeMultipleBrewsWithSkip(t *testing.T) {
var folder = t.TempDir()
var ctx = &context.Context{
folder := t.TempDir()
ctx := &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
@ -373,7 +373,7 @@ func TestRunPipeMultipleBrewsWithSkip(t *testing.T) {
},
},
}
var path = filepath.Join(folder, "bin.tar.gz")
path := filepath.Join(folder, "bin.tar.gz")
ctx.Artifacts.Add(&artifact.Artifact{
Name: "bin.tar.gz",
Path: path,
@ -391,16 +391,15 @@ func TestRunPipeMultipleBrewsWithSkip(t *testing.T) {
require.NoError(t, err)
require.NoError(t, f.Close())
var cli = &DummyClient{}
cli := &DummyClient{}
require.EqualError(t, publishAll(ctx, cli), `brew.skip_upload is set`)
require.True(t, cli.CreatedFile)
for _, brew := range ctx.Config.Brews {
var distFile = filepath.Join(folder, brew.Name+".rb")
distFile := filepath.Join(folder, brew.Name+".rb")
_, err := os.Stat(distFile)
require.NoError(t, err, "file should exist: "+distFile)
}
}
func TestRunPipeForMultipleArmVersions(t *testing.T) {
@ -415,8 +414,8 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
ctx.Config.Brews[0].Goarm = "7"
},
} {
var folder = t.TempDir()
var ctx = &context.Context{
folder := t.TempDir()
ctx := &context.Context{
TokenType: context.TokenTypeGitHub,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
@ -493,7 +492,7 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
goarm: "7",
},
} {
var path = filepath.Join(folder, fmt.Sprintf("%s.tar.gz", a.name))
path := filepath.Join(folder, fmt.Sprintf("%s.tar.gz", a.name))
ctx.Artifacts.Add(&artifact.Artifact{
Name: fmt.Sprintf("%s.tar.gz", a.name),
Path: path,
@ -512,13 +511,13 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
}
client := &DummyClient{}
var distFile = filepath.Join(folder, name+".rb")
distFile := filepath.Join(folder, name+".rb")
require.NoError(t, doRun(ctx, ctx.Config.Brews[0], client))
require.True(t, client.CreatedFile)
var golden = fmt.Sprintf("testdata/%s.rb.golden", name)
golden := fmt.Sprintf("testdata/%s.rb.golden", name)
if *update {
require.NoError(t, os.WriteFile(golden, []byte(client.Content), 0655))
require.NoError(t, os.WriteFile(golden, []byte(client.Content), 0o655))
}
bts, err := os.ReadFile(golden)
require.NoError(t, err)
@ -531,7 +530,7 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
}
func TestRunPipeNoBuilds(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
TokenType: context.TokenTypeGitHub,
Config: config.Project{
Brews: []config.Homebrew{
@ -550,7 +549,7 @@ func TestRunPipeNoBuilds(t *testing.T) {
}
func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
var ctx = context.New(
ctx := context.New(
config.Project{
Brews: []config.Homebrew{
{
@ -697,7 +696,7 @@ func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
}
func TestRunPipeBrewNotSetup(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
client := &DummyClient{}
@ -706,7 +705,7 @@ func TestRunPipeBrewNotSetup(t *testing.T) {
}
func TestRunPipeBinaryRelease(t *testing.T) {
var ctx = context.New(
ctx := context.New(
config.Project{
Brews: []config.Homebrew{
{
@ -731,8 +730,8 @@ func TestRunPipeBinaryRelease(t *testing.T) {
}
func TestRunPipeNoUpload(t *testing.T) {
var folder = t.TempDir()
var ctx = context.New(config.Project{
folder := t.TempDir()
ctx := context.New(config.Project{
Dist: folder,
ProjectName: "foo",
Release: config.Release{},
@ -747,7 +746,7 @@ func TestRunPipeNoUpload(t *testing.T) {
})
ctx.TokenType = context.TokenTypeGitHub
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
var path = filepath.Join(folder, "whatever.tar.gz")
path := filepath.Join(folder, "whatever.tar.gz")
f, err := os.Create(path)
require.NoError(t, err)
require.NoError(t, f.Close())
@ -764,7 +763,7 @@ func TestRunPipeNoUpload(t *testing.T) {
})
client := &DummyClient{}
var assertNoPublish = func(t *testing.T) {
assertNoPublish := func(t *testing.T) {
t.Helper()
testlib.AssertSkipped(t, doRun(ctx, ctx.Config.Brews[0], client))
require.False(t, client.CreatedFile)
@ -784,8 +783,8 @@ func TestRunPipeNoUpload(t *testing.T) {
}
func TestRunEmptyTokenType(t *testing.T) {
var folder = t.TempDir()
var ctx = context.New(config.Project{
folder := t.TempDir()
ctx := context.New(config.Project{
Dist: folder,
ProjectName: "foo",
Release: config.Release{},
@ -799,7 +798,7 @@ func TestRunEmptyTokenType(t *testing.T) {
},
})
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
var path = filepath.Join(folder, "whatever.tar.gz")
path := filepath.Join(folder, "whatever.tar.gz")
f, err := os.Create(path)
require.NoError(t, err)
require.NoError(t, f.Close())
@ -819,8 +818,8 @@ func TestRunEmptyTokenType(t *testing.T) {
}
func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
var folder = t.TempDir()
var ctx = context.New(config.Project{
folder := t.TempDir()
ctx := context.New(config.Project{
Dist: folder,
ProjectName: "foo",
Release: config.Release{},
@ -835,7 +834,7 @@ func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
})
ctx.TokenType = context.TokenTypeGitea
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
var path = filepath.Join(folder, "whatever.tar.gz")
path := filepath.Join(folder, "whatever.tar.gz")
f, err := os.Create(path)
require.NoError(t, err)
require.NoError(t, f.Close())
@ -857,7 +856,7 @@ func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
func TestDefault(t *testing.T) {
testlib.Mktmp(t)
var ctx = &context.Context{
ctx := &context.Context{
TokenType: context.TokenTypeGitHub,
Config: config.Project{
ProjectName: "myproject",

View File

@ -16,8 +16,10 @@ import (
"github.com/stretchr/testify/require"
)
var errFailedBuild = errors.New("fake builder failed")
var errFailedDefault = errors.New("fake builder defaults failed")
var (
errFailedBuild = errors.New("fake builder failed")
errFailedDefault = errors.New("fake builder defaults failed")
)
type fakeBuilder struct {
fail bool
@ -35,10 +37,10 @@ func (f *fakeBuilder) Build(ctx *context.Context, build config.Build, options ap
if f.fail {
return errFailedBuild
}
if err := os.MkdirAll(filepath.Dir(options.Path), 0755); err != nil {
if err := os.MkdirAll(filepath.Dir(options.Path), 0o755); err != nil {
return err
}
if err := os.WriteFile(options.Path, []byte("foo"), 0755); err != nil {
if err := os.WriteFile(options.Path, []byte("foo"), 0o755); err != nil {
return err
}
ctx.Artifacts.Add(&artifact.Artifact{
@ -62,8 +64,8 @@ func TestPipeDescription(t *testing.T) {
}
func TestBuild(t *testing.T) {
var folder = testlib.Mktmp(t)
var config = config.Project{
folder := testlib.Mktmp(t)
config := config.Project{
Dist: folder,
Builds: []config.Build{
{
@ -74,7 +76,7 @@ func TestBuild(t *testing.T) {
},
},
}
var ctx = &context.Context{
ctx := &context.Context{
Artifacts: artifact.New(),
Git: context.GitInfo{
CurrentTag: "v1.2.3",
@ -90,8 +92,8 @@ func TestBuild(t *testing.T) {
}
func TestRunPipe(t *testing.T) {
var folder = testlib.Mktmp(t)
var config = config.Project{
folder := testlib.Mktmp(t)
config := config.Project{
Dist: folder,
Builds: []config.Build{
{
@ -103,7 +105,7 @@ func TestRunPipe(t *testing.T) {
},
},
}
var ctx = context.New(config)
ctx := context.New(config)
ctx.Git.CurrentTag = "2.4.5"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, ctx.Artifacts.List(), []*artifact.Artifact{{
@ -112,10 +114,10 @@ func TestRunPipe(t *testing.T) {
}
func TestRunFullPipe(t *testing.T) {
var folder = testlib.Mktmp(t)
var pre = filepath.Join(folder, "pre")
var post = filepath.Join(folder, "post")
var config = config.Project{
folder := testlib.Mktmp(t)
pre := filepath.Join(folder, "pre")
post := filepath.Join(folder, "post")
config := config.Project{
Builds: []config.Build{
{
ID: "build1",
@ -136,7 +138,7 @@ func TestRunFullPipe(t *testing.T) {
},
Dist: folder,
}
var ctx = context.New(config)
ctx := context.New(config)
ctx.Git.CurrentTag = "2.4.5"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, ctx.Artifacts.List(), []*artifact.Artifact{{
@ -148,10 +150,10 @@ func TestRunFullPipe(t *testing.T) {
}
func TestRunFullPipeFail(t *testing.T) {
var folder = testlib.Mktmp(t)
var pre = filepath.Join(folder, "pre")
var post = filepath.Join(folder, "post")
var config = config.Project{
folder := testlib.Mktmp(t)
pre := filepath.Join(folder, "pre")
post := filepath.Join(folder, "post")
config := config.Project{
Dist: folder,
Builds: []config.Build{
{
@ -171,7 +173,7 @@ func TestRunFullPipeFail(t *testing.T) {
},
},
}
var ctx = context.New(config)
ctx := context.New(config)
ctx.Git.CurrentTag = "2.4.5"
require.EqualError(t, Pipe{}.Run(ctx), errFailedBuild.Error())
require.Empty(t, ctx.Artifacts.List())
@ -179,8 +181,8 @@ func TestRunFullPipeFail(t *testing.T) {
}
func TestRunPipeFailingHooks(t *testing.T) {
var folder = testlib.Mktmp(t)
var cfg = config.Project{
folder := testlib.Mktmp(t)
cfg := config.Project{
Dist: folder,
Builds: []config.Build{
{
@ -192,14 +194,14 @@ func TestRunPipeFailingHooks(t *testing.T) {
},
}
t.Run("pre-hook", func(t *testing.T) {
var ctx = context.New(cfg)
ctx := context.New(cfg)
ctx.Git.CurrentTag = "2.3.4"
ctx.Config.Builds[0].Hooks.Pre = []config.BuildHook{{Cmd: "exit 1"}}
ctx.Config.Builds[0].Hooks.Post = []config.BuildHook{{Cmd: "echo post"}}
require.EqualError(t, Pipe{}.Run(ctx), `pre hook failed: "": exec: "exit": executable file not found in $PATH`)
})
t.Run("post-hook", func(t *testing.T) {
var ctx = context.New(cfg)
ctx := context.New(cfg)
ctx.Git.CurrentTag = "2.3.4"
ctx.Config.Builds[0].Hooks.Pre = []config.BuildHook{{Cmd: "echo pre"}}
ctx.Config.Builds[0].Hooks.Post = []config.BuildHook{{Cmd: "exit 1"}}
@ -208,15 +210,15 @@ func TestRunPipeFailingHooks(t *testing.T) {
}
func TestDefaultNoBuilds(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
require.NoError(t, Pipe{}.Default(ctx))
}
func TestDefaultFail(t *testing.T) {
var folder = testlib.Mktmp(t)
var config = config.Project{
folder := testlib.Mktmp(t)
config := config.Project{
Dist: folder,
Builds: []config.Build{
{
@ -224,14 +226,14 @@ func TestDefaultFail(t *testing.T) {
},
},
}
var ctx = context.New(config)
ctx := context.New(config)
require.EqualError(t, Pipe{}.Default(ctx), errFailedDefault.Error())
require.Empty(t, ctx.Artifacts.List())
}
func TestDefaultExpandEnv(t *testing.T) {
require.NoError(t, os.Setenv("XBAR", "FOOBAR"))
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Builds: []config.Build{
{
@ -243,12 +245,12 @@ func TestDefaultExpandEnv(t *testing.T) {
},
}
require.NoError(t, Pipe{}.Default(ctx))
var env = ctx.Config.Builds[0].Env[0]
env := ctx.Config.Builds[0].Env[0]
require.Equal(t, "XFOO=bar_FOOBAR", env)
}
func TestDefaultEmptyBuild(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
ProjectName: "foo",
Builds: []config.Build{
@ -257,7 +259,7 @@ func TestDefaultEmptyBuild(t *testing.T) {
},
}
require.NoError(t, Pipe{}.Default(ctx))
var build = ctx.Config.Builds[0]
build := ctx.Config.Builds[0]
require.Equal(t, ctx.Config.ProjectName, build.ID)
require.Equal(t, ctx.Config.ProjectName, build.Binary)
require.Equal(t, ".", build.Dir)
@ -271,7 +273,7 @@ func TestDefaultEmptyBuild(t *testing.T) {
}
func TestDefaultBuildID(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
ProjectName: "foo",
Builds: []config.Build{
@ -285,12 +287,12 @@ func TestDefaultBuildID(t *testing.T) {
},
}
require.EqualError(t, Pipe{}.Default(ctx), "found 2 builds with the ID 'foo', please fix your config")
var build = ctx.Config.Builds[0]
build := ctx.Config.Builds[0]
require.Equal(t, ctx.Config.ProjectName, build.ID)
}
func TestSeveralBuildsWithTheSameID(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Builds: []config.Build{
{
@ -308,7 +310,7 @@ func TestSeveralBuildsWithTheSameID(t *testing.T) {
}
func TestDefaultPartialBuilds(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Builds: []config.Build{
{
@ -329,7 +331,7 @@ func TestDefaultPartialBuilds(t *testing.T) {
}
require.NoError(t, Pipe{}.Default(ctx))
t.Run("build0", func(t *testing.T) {
var build = ctx.Config.Builds[0]
build := ctx.Config.Builds[0]
require.Equal(t, "bar", build.Binary)
require.Equal(t, ".", build.Dir)
require.Equal(t, "./cmd/main.go", build.Main)
@ -340,7 +342,7 @@ func TestDefaultPartialBuilds(t *testing.T) {
require.Equal(t, "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser", build.Ldflags[0])
})
t.Run("build1", func(t *testing.T) {
var build = ctx.Config.Builds[1]
build := ctx.Config.Builds[1]
require.Equal(t, "foo", build.Binary)
require.Equal(t, ".", build.Main)
require.Equal(t, "baz", build.Dir)
@ -355,7 +357,7 @@ func TestDefaultPartialBuilds(t *testing.T) {
func TestDefaultFillSingleBuild(t *testing.T) {
testlib.Mktmp(t)
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
ProjectName: "foo",
SingleBuild: config.Build{
@ -369,21 +371,21 @@ func TestDefaultFillSingleBuild(t *testing.T) {
}
func TestDefaultFailSingleBuild(t *testing.T) {
var folder = testlib.Mktmp(t)
var config = config.Project{
folder := testlib.Mktmp(t)
config := config.Project{
Dist: folder,
SingleBuild: config.Build{
Lang: "fakeFailDefault",
},
}
var ctx = context.New(config)
ctx := context.New(config)
require.EqualError(t, Pipe{}.Default(ctx), errFailedDefault.Error())
require.Empty(t, ctx.Artifacts.List())
}
func TestSkipBuild(t *testing.T) {
var folder = testlib.Mktmp(t)
var config = config.Project{
folder := testlib.Mktmp(t)
config := config.Project{
Dist: folder,
Builds: []config.Build{
{
@ -391,7 +393,7 @@ func TestSkipBuild(t *testing.T) {
},
},
}
var ctx = context.New(config)
ctx := context.New(config)
ctx.Git.CurrentTag = "2.4.5"
require.NoError(t, Pipe{}.Run(ctx))
require.Len(t, ctx.Artifacts.List(), 0)
@ -418,7 +420,7 @@ func TestExtOthers(t *testing.T) {
}
func TestTemplate(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Git = context.GitInfo{
CurrentTag: "v1.2.3",
Commit: "123",
@ -437,16 +439,16 @@ func TestTemplate(t *testing.T) {
}
func TestRunHookEnvs(t *testing.T) {
var tmp = testlib.Mktmp(t)
tmp := testlib.Mktmp(t)
var build = config.Build{
build := config.Build{
Env: []string{
fmt.Sprintf("FOO=%s/foo", tmp),
fmt.Sprintf("BAR=%s/bar", tmp),
},
}
var opts = api.Options{
opts := api.Options{
Name: "binary-name",
Path: "./binary-name",
Target: "darwin_amd64",
@ -457,7 +459,7 @@ func TestRunHookEnvs(t *testing.T) {
}
t.Run("valid cmd template with ctx env", func(t *testing.T) {
var err = runHook(context.New(config.Project{
err := runHook(context.New(config.Project{
Builds: []config.Build{
build,
},
@ -470,7 +472,7 @@ func TestRunHookEnvs(t *testing.T) {
})
t.Run("valid cmd template with build env", func(t *testing.T) {
var err = runHook(context.New(config.Project{
err := runHook(context.New(config.Project{
Builds: []config.Build{
build,
},
@ -480,7 +482,7 @@ func TestRunHookEnvs(t *testing.T) {
})
t.Run("valid cmd template with hook env", func(t *testing.T) {
var err = runHook(context.New(config.Project{
err := runHook(context.New(config.Project{
Builds: []config.Build{
build,
},
@ -495,7 +497,7 @@ func TestRunHookEnvs(t *testing.T) {
})
t.Run("valid cmd template with ctx and build env", func(t *testing.T) {
var err = runHook(context.New(config.Project{
err := runHook(context.New(config.Project{
Builds: []config.Build{
build,
},
@ -512,7 +514,7 @@ func TestRunHookEnvs(t *testing.T) {
})
t.Run("valid cmd template with ctx and hook env", func(t *testing.T) {
var err = runHook(context.New(config.Project{
err := runHook(context.New(config.Project{
Builds: []config.Build{
build,
},
@ -531,7 +533,7 @@ func TestRunHookEnvs(t *testing.T) {
})
t.Run("valid cmd template with build and hook env", func(t *testing.T) {
var err = runHook(context.New(config.Project{
err := runHook(context.New(config.Project{
Builds: []config.Build{
build,
},
@ -549,7 +551,7 @@ func TestRunHookEnvs(t *testing.T) {
})
t.Run("valid cmd template with ctx, build and hook env", func(t *testing.T) {
var err = runHook(context.New(config.Project{
err := runHook(context.New(config.Project{
Builds: []config.Build{
build,
},
@ -571,7 +573,7 @@ func TestRunHookEnvs(t *testing.T) {
})
t.Run("invalid cmd template", func(t *testing.T) {
var err = runHook(context.New(config.Project{
err := runHook(context.New(config.Project{
Builds: []config.Build{
build,
},
@ -580,7 +582,7 @@ func TestRunHookEnvs(t *testing.T) {
})
t.Run("invalid dir template", func(t *testing.T) {
var err = runHook(context.New(config.Project{
err := runHook(context.New(config.Project{
Builds: []config.Build{
build,
},
@ -592,7 +594,7 @@ func TestRunHookEnvs(t *testing.T) {
})
t.Run("invalid hook env template", func(t *testing.T) {
var err = runHook(context.New(config.Project{
err := runHook(context.New(config.Project{
Builds: []config.Build{
build,
},
@ -606,9 +608,9 @@ func TestRunHookEnvs(t *testing.T) {
})
t.Run("build env inside shell", func(t *testing.T) {
var shell = `#!/bin/sh -e
shell := `#!/bin/sh -e
touch "$BAR"`
err := os.WriteFile(filepath.Join(tmp, "test.sh"), []byte(shell), 0750)
err := os.WriteFile(filepath.Join(tmp, "test.sh"), []byte(shell), 0o750)
require.NoError(t, err)
err = runHook(context.New(config.Project{
Builds: []config.Build{
@ -621,7 +623,7 @@ touch "$BAR"`
}
func TestBuild_hooksKnowGoosGoarch(t *testing.T) {
var tmpDir = testlib.Mktmp(t)
tmpDir := testlib.Mktmp(t)
build := config.Build{
Lang: "fake",
Goarch: []string{"amd64"},
@ -652,7 +654,7 @@ func TestBuild_hooksKnowGoosGoarch(t *testing.T) {
}
func TestPipeOnBuild_hooksRunPerTarget(t *testing.T) {
var tmpDir = testlib.Mktmp(t)
tmpDir := testlib.Mktmp(t)
build := config.Build{
Lang: "fake",
@ -704,7 +706,7 @@ func TestPipeOnBuild_invalidBinaryTpl(t *testing.T) {
}
func TestBuildOptionsForTarget(t *testing.T) {
var tmpDir = testlib.Mktmp(t)
tmpDir := testlib.Mktmp(t)
testCases := []struct {
name string
@ -761,7 +763,7 @@ func TestBuildOptionsForTarget(t *testing.T) {
}
func TestHookComplex(t *testing.T) {
var tmp = testlib.Mktmp(t)
tmp := testlib.Mktmp(t)
require.NoError(t, runHook(context.New(config.Project{}), api.Options{}, []string{}, config.BuildHooks{
{
@ -785,8 +787,8 @@ func TestHookInvalidShelCommand(t *testing.T) {
}
func TestRunHookFailWithLogs(t *testing.T) {
var folder = testlib.Mktmp(t)
var config = config.Project{
folder := testlib.Mktmp(t)
config := config.Project{
Dist: folder,
Builds: []config.Build{
{
@ -802,7 +804,7 @@ func TestRunHookFailWithLogs(t *testing.T) {
},
},
}
var ctx = context.New(config)
ctx := context.New(config)
ctx.Git.CurrentTag = "2.4.5"
require.EqualError(t, Pipe{}.Run(ctx), "pre hook failed: \"foo\\n\": exit status 1")
require.Empty(t, ctx.Artifacts.List())

View File

@ -17,14 +17,14 @@ func TestDescription(t *testing.T) {
}
func TestChangelogProvidedViaFlag(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.ReleaseNotes = "testdata/changes.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "c0ff33 coffeee\n", ctx.ReleaseNotes)
}
func TestTemplatedChangelogProvidedViaFlag(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.ReleaseNotes = "testdata/changes-templated.md"
ctx.Git.CurrentTag = "v0.0.1"
require.NoError(t, Pipe{}.Run(ctx))
@ -32,7 +32,7 @@ func TestTemplatedChangelogProvidedViaFlag(t *testing.T) {
}
func TestChangelogProvidedViaFlagAndSkipEnabled(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Changelog: config.Changelog{
Skip: true,
},
@ -43,37 +43,37 @@ func TestChangelogProvidedViaFlagAndSkipEnabled(t *testing.T) {
}
func TestChangelogProvidedViaFlagDoesntExist(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.ReleaseNotes = "testdata/changes.nope"
require.EqualError(t, Pipe{}.Run(ctx), "open testdata/changes.nope: no such file or directory")
}
func TestChangelogSkip(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Config.Changelog.Skip = true
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
}
func TestReleaseHeaderProvidedViaFlagDoesntExist(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.ReleaseHeader = "testdata/header.nope"
require.EqualError(t, Pipe{}.Run(ctx), "open testdata/header.nope: no such file or directory")
}
func TestReleaseFooterProvidedViaFlagDoesntExist(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.ReleaseFooter = "testdata/footer.nope"
require.EqualError(t, Pipe{}.Run(ctx), "open testdata/footer.nope: no such file or directory")
}
func TestSnapshot(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Snapshot = true
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
}
func TestChangelog(t *testing.T) {
var folder = testlib.Mktmp(t)
folder := testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitCommit(t, "first")
testlib.GitTag(t, "v0.0.1")
@ -86,7 +86,7 @@ func TestChangelog(t *testing.T) {
testlib.GitCommit(t, "Merge pull request #999 from goreleaser/some-branch")
testlib.GitCommit(t, "this is not a Merge pull request")
testlib.GitTag(t, "v0.0.2")
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Dist: folder,
Changelog: config.Changelog{
Filters: config.Filters{
@ -116,7 +116,7 @@ func TestChangelog(t *testing.T) {
}
func TestChangelogPreviousTagEnv(t *testing.T) {
var folder = testlib.Mktmp(t)
folder := testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitCommit(t, "first")
testlib.GitTag(t, "v0.0.1")
@ -124,7 +124,7 @@ func TestChangelogPreviousTagEnv(t *testing.T) {
testlib.GitTag(t, "v0.0.2")
testlib.GitCommit(t, "third")
testlib.GitTag(t, "v0.0.3")
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Dist: folder,
Changelog: config.Changelog{Filters: config.Filters{}},
})
@ -139,7 +139,7 @@ func TestChangelogPreviousTagEnv(t *testing.T) {
}
func TestChangelogForGitlab(t *testing.T) {
var folder = testlib.Mktmp(t)
folder := testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitCommit(t, "first")
testlib.GitTag(t, "v0.0.1")
@ -152,7 +152,7 @@ func TestChangelogForGitlab(t *testing.T) {
testlib.GitCommit(t, "Merge pull request #999 from goreleaser/some-branch")
testlib.GitCommit(t, "this is not a Merge pull request")
testlib.GitTag(t, "v0.0.2")
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Dist: folder,
Changelog: config.Changelog{
Filters: config.Filters{
@ -191,7 +191,7 @@ func TestChangelogSort(t *testing.T) {
testlib.GitCommit(t, "a: commit")
testlib.GitCommit(t, "b: commit")
testlib.GitTag(t, "v1.0.0")
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Changelog: config.Changelog{},
})
ctx.Git.CurrentTag = "v1.0.0"
@ -240,7 +240,7 @@ func TestChangelogSort(t *testing.T) {
}
func TestChangelogInvalidSort(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Changelog: config.Changelog{
Sort: "dope",
},
@ -251,7 +251,7 @@ func TestChangelogInvalidSort(t *testing.T) {
func TestChangelogOfFirstRelease(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
var msgs = []string{
msgs := []string{
"initial commit",
"another one",
"one more",
@ -261,7 +261,7 @@ func TestChangelogOfFirstRelease(t *testing.T) {
testlib.GitCommit(t, msg)
}
testlib.GitTag(t, "v0.0.1")
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Git.CurrentTag = "v0.0.1"
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
@ -277,7 +277,7 @@ func TestChangelogFilterInvalidRegex(t *testing.T) {
testlib.GitTag(t, "v0.0.3")
testlib.GitCommit(t, "commitzzz")
testlib.GitTag(t, "v0.0.4")
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Changelog: config.Changelog{
Filters: config.Filters{
Exclude: []string{
@ -294,7 +294,7 @@ func TestChangelogNoTags(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitCommit(t, "first")
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
require.Error(t, Pipe{}.Run(ctx))
require.Empty(t, ctx.ReleaseNotes)
}
@ -302,7 +302,7 @@ func TestChangelogNoTags(t *testing.T) {
func TestChangelogOnBranchWithSameNameAsTag(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
var msgs = []string{
msgs := []string{
"initial commit",
"another one",
"one more",
@ -313,7 +313,7 @@ func TestChangelogOnBranchWithSameNameAsTag(t *testing.T) {
}
testlib.GitTag(t, "v0.0.1")
testlib.GitCheckoutBranch(t, "v0.0.1")
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Git.CurrentTag = "v0.0.1"
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
@ -325,10 +325,10 @@ func TestChangelogOnBranchWithSameNameAsTag(t *testing.T) {
func TestChangeLogWithReleaseHeader(t *testing.T) {
current, err := os.Getwd()
require.NoError(t, err)
var tmpdir = testlib.Mktmp(t)
tmpdir := testlib.Mktmp(t)
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
testlib.GitInit(t)
var msgs = []string{
msgs := []string{
"initial commit",
"another one",
"one more",
@ -339,7 +339,7 @@ func TestChangeLogWithReleaseHeader(t *testing.T) {
}
testlib.GitTag(t, "v0.0.1")
testlib.GitCheckoutBranch(t, "v0.0.1")
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Git.CurrentTag = "v0.0.1"
ctx.ReleaseHeader = "testdata/release-header.md"
require.NoError(t, Pipe{}.Run(ctx))
@ -350,10 +350,10 @@ func TestChangeLogWithReleaseHeader(t *testing.T) {
func TestChangeLogWithTemplatedReleaseHeader(t *testing.T) {
current, err := os.Getwd()
require.NoError(t, err)
var tmpdir = testlib.Mktmp(t)
tmpdir := testlib.Mktmp(t)
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
testlib.GitInit(t)
var msgs = []string{
msgs := []string{
"initial commit",
"another one",
"one more",
@ -364,20 +364,21 @@ func TestChangeLogWithTemplatedReleaseHeader(t *testing.T) {
}
testlib.GitTag(t, "v0.0.1")
testlib.GitCheckoutBranch(t, "v0.0.1")
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Git.CurrentTag = "v0.0.1"
ctx.ReleaseHeader = "testdata/release-header-templated.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
require.Contains(t, ctx.ReleaseNotes, "test header with tag v0.0.1")
}
func TestChangeLogWithReleaseFooter(t *testing.T) {
current, err := os.Getwd()
require.NoError(t, err)
var tmpdir = testlib.Mktmp(t)
tmpdir := testlib.Mktmp(t)
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
testlib.GitInit(t)
var msgs = []string{
msgs := []string{
"initial commit",
"another one",
"one more",
@ -388,7 +389,7 @@ func TestChangeLogWithReleaseFooter(t *testing.T) {
}
testlib.GitTag(t, "v0.0.1")
testlib.GitCheckoutBranch(t, "v0.0.1")
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Git.CurrentTag = "v0.0.1"
ctx.ReleaseFooter = "testdata/release-footer.md"
require.NoError(t, Pipe{}.Run(ctx))
@ -400,10 +401,10 @@ func TestChangeLogWithReleaseFooter(t *testing.T) {
func TestChangeLogWithTemplatedReleaseFooter(t *testing.T) {
current, err := os.Getwd()
require.NoError(t, err)
var tmpdir = testlib.Mktmp(t)
tmpdir := testlib.Mktmp(t)
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
testlib.GitInit(t)
var msgs = []string{
msgs := []string{
"initial commit",
"another one",
"one more",
@ -414,7 +415,7 @@ func TestChangeLogWithTemplatedReleaseFooter(t *testing.T) {
}
testlib.GitTag(t, "v0.0.1")
testlib.GitCheckoutBranch(t, "v0.0.1")
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Git.CurrentTag = "v0.0.1"
ctx.ReleaseFooter = "testdata/release-footer-templated.md"
require.NoError(t, Pipe{}.Run(ctx))
@ -426,10 +427,10 @@ func TestChangeLogWithTemplatedReleaseFooter(t *testing.T) {
func TestChangeLogWithoutReleaseFooter(t *testing.T) {
current, err := os.Getwd()
require.NoError(t, err)
var tmpdir = testlib.Mktmp(t)
tmpdir := testlib.Mktmp(t)
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
testlib.GitInit(t)
var msgs = []string{
msgs := []string{
"initial commit",
"another one",
"one more",
@ -440,7 +441,7 @@ func TestChangeLogWithoutReleaseFooter(t *testing.T) {
}
testlib.GitTag(t, "v0.0.1")
testlib.GitCheckoutBranch(t, "v0.0.1")
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Git.CurrentTag = "v0.0.1"
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")

View File

@ -48,10 +48,10 @@ func TestPipe(t *testing.T) {
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
var folder = t.TempDir()
var file = filepath.Join(folder, binary)
require.NoError(t, os.WriteFile(file, []byte("some string"), 0644))
var ctx = context.New(
folder := t.TempDir()
file := filepath.Join(folder, binary)
require.NoError(t, os.WriteFile(file, []byte("some string"), 0o644))
ctx := context.New(
config.Project{
Dist: folder,
ProjectName: binary,
@ -101,12 +101,11 @@ func TestPipe(t *testing.T) {
}
})
}
}
func TestPipeSkipTrue(t *testing.T) {
var folder = t.TempDir()
var ctx = context.New(
folder := t.TempDir()
ctx := context.New(
config.Project{
Dist: folder,
Checksum: config.Checksum{
@ -114,14 +113,14 @@ func TestPipeSkipTrue(t *testing.T) {
},
},
)
var err = Pipe{}.Run(ctx)
err := Pipe{}.Run(ctx)
testlib.AssertSkipped(t, err)
require.EqualError(t, err, pipe.ErrSkipDisabledPipe.Error())
}
func TestPipeFileNotExist(t *testing.T) {
var folder = t.TempDir()
var ctx = context.New(
folder := t.TempDir()
ctx := context.New(
config.Project{
Dist: folder,
Checksum: config.Checksum{
@ -135,7 +134,7 @@ func TestPipeFileNotExist(t *testing.T) {
Path: "/nope",
Type: artifact.UploadableBinary,
})
var err = Pipe{}.Run(ctx)
err := Pipe{}.Run(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), "/nope: no such file or directory")
}
@ -152,8 +151,8 @@ func TestPipeInvalidNameTemplate(t *testing.T) {
"{{.Env.NOPE}}": `template: tmpl:1:6: executing "tmpl" at <.Env.NOPE>: map has no entry for key "NOPE"`,
} {
t.Run(template, func(t *testing.T) {
var folder = t.TempDir()
var ctx = context.New(
folder := t.TempDir()
ctx := context.New(
config.Project{
Dist: folder,
ProjectName: "name",
@ -177,16 +176,16 @@ func TestPipeInvalidNameTemplate(t *testing.T) {
}
func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) {
var folder = t.TempDir()
folder := t.TempDir()
binFile, err := ioutil.TempFile(folder, "goreleasertest-bin")
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, binFile.Close()) })
_, err = binFile.WriteString("fake artifact")
require.NoError(t, err)
var file = filepath.Join(folder, "checksums.txt")
require.NoError(t, os.WriteFile(file, []byte("some string"), 0000))
var ctx = context.New(
file := filepath.Join(folder, "checksums.txt")
require.NoError(t, os.WriteFile(file, []byte("some string"), 0o000))
ctx := context.New(
config.Project{
Dist: folder,
Checksum: config.Checksum{
@ -207,13 +206,13 @@ func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) {
}
func TestPipeWhenNoArtifacts(t *testing.T) {
var ctx = &context.Context{}
ctx := &context.Context{}
require.NoError(t, Pipe{}.Run(ctx))
require.Len(t, ctx.Artifacts.List(), 0)
}
func TestDefault(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Checksum: config.Checksum{},
},
@ -228,7 +227,7 @@ func TestDefault(t *testing.T) {
}
func TestDefaultSet(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Checksum: config.Checksum{
NameTemplate: "checksums.txt",

View File

@ -18,7 +18,7 @@ func TestFillBasicData(t *testing.T) {
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
var ctx = &context.Context{
ctx := &context.Context{
TokenType: context.TokenTypeGitHub,
Config: config.Project{},
}
@ -47,7 +47,7 @@ func TestFillPartial(t *testing.T) {
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
GitHubURLs: config.GitHubURLs{
Download: "https://github.company.com",

View File

@ -49,5 +49,5 @@ func (Pipe) Run(ctx *context.Context) (err error) {
func mkdir(ctx *context.Context) error {
// #nosec
return os.MkdirAll(ctx.Config.Dist, 0755)
return os.MkdirAll(ctx.Config.Dist, 0o755)
}

View File

@ -11,8 +11,8 @@ import (
)
func TestDistDoesNotExist(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(
t,
Pipe{}.Run(
@ -26,13 +26,13 @@ func TestDistDoesNotExist(t *testing.T) {
}
func TestPopulatedDistExists(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
f, err := os.Create(filepath.Join(dist, "mybin"))
require.NoError(t, err)
require.NoError(t, f.Close())
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Dist: dist,
},
@ -45,10 +45,10 @@ func TestPopulatedDistExists(t *testing.T) {
}
func TestEmptyDistExists(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
var ctx = &context.Context{
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := &context.Context{
Config: config.Project{
Dist: dist,
},

View File

@ -10,8 +10,7 @@ import (
)
// Pipe that writes the effective config file to dist.
type Pipe struct {
}
type Pipe struct{}
func (Pipe) String() string {
return "writing effective config file"
@ -19,11 +18,11 @@ func (Pipe) String() string {
// Run the pipe.
func (Pipe) Run(ctx *context.Context) (err error) {
var path = filepath.Join(ctx.Config.Dist, "config.yaml")
path := filepath.Join(ctx.Config.Dist, "config.yaml")
bts, err := yaml.Marshal(ctx.Config)
if err != nil {
return err
}
log.WithField("config", path).Info("writing")
return os.WriteFile(path, bts, 0644) //nolint: gosec
return os.WriteFile(path, bts, 0o644) //nolint: gosec
}

View File

@ -16,10 +16,10 @@ func TestPipeDescription(t *testing.T) {
}
func TestRun(t *testing.T) {
var folder = testlib.Mktmp(t)
folder := testlib.Mktmp(t)
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
var ctx = context.New(
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := context.New(
config.Project{
Dist: dist,
},

View File

@ -28,7 +28,7 @@ func (Pipe) String() string {
}
func setDefaultTokenFiles(ctx *context.Context) {
var env = &ctx.Config.EnvFiles
env := &ctx.Config.EnvFiles
if env.GitHubToken == "" {
env.GitHubToken = "~/.config/goreleaser/github_token"
}

View File

@ -37,7 +37,7 @@ func TestSetDefaultTokenFiles(t *testing.T) {
func TestValidGithubEnv(t *testing.T) {
require.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf"))
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
require.NoError(t, Pipe{}.Run(ctx))
@ -49,7 +49,7 @@ func TestValidGithubEnv(t *testing.T) {
func TestValidGitlabEnv(t *testing.T) {
require.NoError(t, os.Setenv("GITLAB_TOKEN", "qwertz"))
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
require.NoError(t, Pipe{}.Run(ctx))
@ -61,7 +61,7 @@ func TestValidGitlabEnv(t *testing.T) {
func TestValidGiteaEnv(t *testing.T) {
require.NoError(t, os.Setenv("GITEA_TOKEN", "token"))
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
require.NoError(t, Pipe{}.Run(ctx))
@ -74,7 +74,7 @@ func TestValidGiteaEnv(t *testing.T) {
func TestInvalidEnv(t *testing.T) {
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
require.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
require.Error(t, Pipe{}.Run(ctx))
@ -85,7 +85,7 @@ func TestMultipleEnvTokens(t *testing.T) {
require.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf"))
require.NoError(t, os.Setenv("GITLAB_TOKEN", "qwertz"))
require.NoError(t, os.Setenv("GITEA_TOKEN", "token"))
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
require.Error(t, Pipe{}.Run(ctx))
@ -98,7 +98,7 @@ func TestMultipleEnvTokens(t *testing.T) {
func TestEmptyGithubFileEnv(t *testing.T) {
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
require.Error(t, Pipe{}.Run(ctx))
@ -106,7 +106,7 @@ func TestEmptyGithubFileEnv(t *testing.T) {
func TestEmptyGitlabFileEnv(t *testing.T) {
require.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
require.Error(t, Pipe{}.Run(ctx))
@ -114,7 +114,7 @@ func TestEmptyGitlabFileEnv(t *testing.T) {
func TestEmptyGiteaFileEnv(t *testing.T) {
require.NoError(t, os.Unsetenv("GITEA_TOKEN"))
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
require.Error(t, Pipe{}.Run(ctx))
@ -125,8 +125,8 @@ func TestEmptyGithubEnvFile(t *testing.T) {
f, err := ioutil.TempFile(t.TempDir(), "token")
require.NoError(t, err)
require.NoError(t, f.Close())
require.NoError(t, os.Chmod(f.Name(), 0377))
var ctx = &context.Context{
require.NoError(t, os.Chmod(f.Name(), 0o377))
ctx := &context.Context{
Config: config.Project{
EnvFiles: config.EnvFiles{
GitHubToken: f.Name(),
@ -141,8 +141,8 @@ func TestEmptyGitlabEnvFile(t *testing.T) {
f, err := ioutil.TempFile(t.TempDir(), "token")
require.NoError(t, err)
require.NoError(t, f.Close())
require.NoError(t, os.Chmod(f.Name(), 0377))
var ctx = &context.Context{
require.NoError(t, os.Chmod(f.Name(), 0o377))
ctx := &context.Context{
Config: config.Project{
EnvFiles: config.EnvFiles{
GitLabToken: f.Name(),
@ -157,8 +157,8 @@ func TestEmptyGiteaEnvFile(t *testing.T) {
f, err := ioutil.TempFile(t.TempDir(), "token")
require.NoError(t, err)
require.NoError(t, f.Close())
require.NoError(t, os.Chmod(f.Name(), 0377))
var ctx = &context.Context{
require.NoError(t, os.Chmod(f.Name(), 0o377))
ctx := &context.Context{
Config: config.Project{
EnvFiles: config.EnvFiles{
GiteaToken: f.Name(),
@ -170,7 +170,7 @@ func TestEmptyGiteaEnvFile(t *testing.T) {
func TestInvalidEnvChecksSkipped(t *testing.T) {
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
SkipPublish: true,
}
@ -179,7 +179,7 @@ func TestInvalidEnvChecksSkipped(t *testing.T) {
func TestInvalidEnvReleaseDisabled(t *testing.T) {
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Release: config.Release{
Disable: true,
@ -191,14 +191,14 @@ func TestInvalidEnvReleaseDisabled(t *testing.T) {
func TestLoadEnv(t *testing.T) {
t.Run("env exists", func(t *testing.T) {
var env = "SUPER_SECRET_ENV"
env := "SUPER_SECRET_ENV"
require.NoError(t, os.Setenv(env, "1"))
v, err := loadEnv(env, "nope")
require.NoError(t, err)
require.Equal(t, "1", v)
})
t.Run("env file exists", func(t *testing.T) {
var env = "SUPER_SECRET_ENV_NOPE"
env := "SUPER_SECRET_ENV_NOPE"
require.NoError(t, os.Unsetenv(env))
f, err := ioutil.TempFile(t.TempDir(), "token")
require.NoError(t, err)
@ -209,7 +209,7 @@ func TestLoadEnv(t *testing.T) {
require.Equal(t, "123", v)
})
t.Run("env file with an empty line at the end", func(t *testing.T) {
var env = "SUPER_SECRET_ENV_NOPE"
env := "SUPER_SECRET_ENV_NOPE"
require.NoError(t, os.Unsetenv(env))
f, err := ioutil.TempFile(t.TempDir(), "token")
require.NoError(t, err)
@ -220,13 +220,13 @@ func TestLoadEnv(t *testing.T) {
require.Equal(t, "123", v)
})
t.Run("env file is not readable", func(t *testing.T) {
var env = "SUPER_SECRET_ENV_NOPE"
env := "SUPER_SECRET_ENV_NOPE"
require.NoError(t, os.Unsetenv(env))
f, err := ioutil.TempFile(t.TempDir(), "token")
require.NoError(t, err)
fmt.Fprintf(f, "123")
require.NoError(t, f.Close())
err = os.Chmod(f.Name(), 0377)
err = os.Chmod(f.Name(), 0o377)
require.NoError(t, err)
v, err := loadEnv(env, f.Name())
require.EqualError(t, err, fmt.Sprintf("open %s: permission denied", f.Name()))

View File

@ -18,7 +18,7 @@ func TestDefaultWithRepoConfig(t *testing.T) {
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "git@github.com:githubowner/githubrepo.git")
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Milestones: []config.Milestone{
{
@ -41,7 +41,7 @@ func TestDefaultWithRepoRemote(t *testing.T) {
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "git@github.com:githubowner/githubrepo.git")
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.TokenType = context.TokenTypeGitHub
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "githubrepo", ctx.Config.Milestones[0].Repo.Name)
@ -49,7 +49,7 @@ func TestDefaultWithRepoRemote(t *testing.T) {
}
func TestDefaultWithNameTemplate(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Milestones: []config.Milestone{
{
@ -64,7 +64,7 @@ func TestDefaultWithNameTemplate(t *testing.T) {
func TestDefaultWithoutGitRepo(t *testing.T) {
testlib.Mktmp(t)
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
ctx.TokenType = context.TokenTypeGitHub
@ -74,7 +74,7 @@ func TestDefaultWithoutGitRepo(t *testing.T) {
func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
testlib.Mktmp(t)
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
ctx.TokenType = context.TokenTypeGitHub
@ -85,7 +85,7 @@ func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
func TestDefaultWithoutGitRepoSnapshot(t *testing.T) {
testlib.Mktmp(t)
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{},
}
ctx.TokenType = context.TokenTypeGitHub
@ -95,7 +95,7 @@ func TestDefaultWithoutGitRepoSnapshot(t *testing.T) {
}
func TestDefaultWithoutNameTemplate(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Milestones: []config.Milestone{},
},
@ -109,7 +109,7 @@ func TestString(t *testing.T) {
}
func TestPublishCloseDisabled(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Milestones: []config.Milestone{
{
Close: false,
@ -122,7 +122,7 @@ func TestPublishCloseDisabled(t *testing.T) {
}
func TestPublishCloseEnabled(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Milestones: []config.Milestone{
{
Close: true,
@ -141,7 +141,7 @@ func TestPublishCloseEnabled(t *testing.T) {
}
func TestPublishCloseError(t *testing.T) {
var config = config.Project{
config := config.Project{
Milestones: []config.Milestone{
{
Close: true,
@ -153,7 +153,7 @@ func TestPublishCloseError(t *testing.T) {
},
},
}
var ctx = context.New(config)
ctx := context.New(config)
ctx.Git.CurrentTag = "v1.0.0"
client := &DummyClient{
FailToCloseMilestone: true,
@ -163,7 +163,7 @@ func TestPublishCloseError(t *testing.T) {
}
func TestPublishCloseFailOnError(t *testing.T) {
var config = config.Project{
config := config.Project{
Milestones: []config.Milestone{
{
Close: true,
@ -176,7 +176,7 @@ func TestPublishCloseFailOnError(t *testing.T) {
},
},
}
var ctx = context.New(config)
ctx := context.New(config)
ctx.Git.CurrentTag = "v1.0.0"
client := &DummyClient{
FailToCloseMilestone: true,

View File

@ -10,7 +10,7 @@ import (
)
func TestCustomProjectName(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "foo",
Release: config.Release{
GitHub: config.Repo{
@ -24,7 +24,7 @@ func TestCustomProjectName(t *testing.T) {
}
func TestEmptyProjectName_DefaultsToGitHubRelease(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Release: config.Release{
GitHub: config.Repo{
Owner: "bar",
@ -37,7 +37,7 @@ func TestEmptyProjectName_DefaultsToGitHubRelease(t *testing.T) {
}
func TestEmptyProjectName_DefaultsToGitLabRelease(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Release: config.Release{
GitLab: config.Repo{
Owner: "bar",
@ -50,7 +50,7 @@ func TestEmptyProjectName_DefaultsToGitLabRelease(t *testing.T) {
}
func TestEmptyProjectName_DefaultsToGiteaRelease(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Release: config.Release{
Gitea: config.Repo{
Owner: "bar",
@ -63,7 +63,7 @@ func TestEmptyProjectName_DefaultsToGiteaRelease(t *testing.T) {
}
func TestEmptyProjectNameAndRelease(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Release: config.Release{
GitHub: config.Repo{},
},

View File

@ -13,7 +13,7 @@ func TestDescription(t *testing.T) {
}
func TestPublish(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Config.Release.Disable = true
ctx.TokenType = context.TokenTypeGitHub
for i := range ctx.Config.Dockers {

View File

@ -31,7 +31,7 @@ func describeBody(ctx *context.Context) (bytes.Buffer, error) {
dockers = append(dockers, a.Name)
}
}
var bodyTemplate = template.Must(template.New("release").Parse(bodyTemplateText))
bodyTemplate := template.Must(template.New("release").Parse(bodyTemplateText))
err := bodyTemplate.Execute(&out, struct {
ReleaseNotes string
DockerImages []string

View File

@ -14,8 +14,8 @@ import (
var update = flag.Bool("update", false, "update .golden files")
func TestDescribeBody(t *testing.T) {
var changelog = "feature1: description\nfeature2: other description"
var ctx = context.New(config.Project{})
changelog := "feature1: description\nfeature2: other description"
ctx := context.New(config.Project{})
ctx.ReleaseNotes = changelog
for _, d := range []string{
"goreleaser/goreleaser:0.40.0",
@ -30,9 +30,9 @@ func TestDescribeBody(t *testing.T) {
out, err := describeBody(ctx)
require.NoError(t, err)
var golden = "testdata/release1.golden"
golden := "testdata/release1.golden"
if *update {
_ = os.WriteFile(golden, out.Bytes(), 0755)
_ = os.WriteFile(golden, out.Bytes(), 0o755)
}
bts, err := os.ReadFile(golden)
require.NoError(t, err)
@ -40,8 +40,8 @@ func TestDescribeBody(t *testing.T) {
}
func TestDescribeBodyWithDockerManifest(t *testing.T) {
var changelog = "feature1: description\nfeature2: other description"
var ctx = context.New(config.Project{})
changelog := "feature1: description\nfeature2: other description"
ctx := context.New(config.Project{})
ctx.ReleaseNotes = changelog
for _, d := range []string{
"goreleaser/goreleaser:0.40.0",
@ -69,9 +69,9 @@ func TestDescribeBodyWithDockerManifest(t *testing.T) {
out, err := describeBody(ctx)
require.NoError(t, err)
var golden = "testdata/release3.golden"
golden := "testdata/release3.golden"
if *update {
_ = os.WriteFile(golden, out.Bytes(), 0755)
_ = os.WriteFile(golden, out.Bytes(), 0o755)
}
bts, err := os.ReadFile(golden)
require.NoError(t, err)
@ -79,16 +79,16 @@ func TestDescribeBodyWithDockerManifest(t *testing.T) {
}
func TestDescribeBodyNoDockerImagesNoBrews(t *testing.T) {
var changelog = "feature1: description\nfeature2: other description"
var ctx = &context.Context{
changelog := "feature1: description\nfeature2: other description"
ctx := &context.Context{
ReleaseNotes: changelog,
}
out, err := describeBody(ctx)
require.NoError(t, err)
var golden = "testdata/release2.golden"
golden := "testdata/release2.golden"
if *update {
_ = os.WriteFile(golden, out.Bytes(), 0655)
_ = os.WriteFile(golden, out.Bytes(), 0o655)
}
bts, err := os.ReadFile(golden)
require.NoError(t, err)
@ -97,8 +97,8 @@ func TestDescribeBodyNoDockerImagesNoBrews(t *testing.T) {
}
func TestDontEscapeHTML(t *testing.T) {
var changelog = "<h1>test</h1>"
var ctx = context.New(config.Project{})
changelog := "<h1>test</h1>"
ctx := context.New(config.Project{})
ctx.ReleaseNotes = changelog
out, err := describeBody(ctx)

View File

@ -25,7 +25,7 @@ func TestDescription(t *testing.T) {
func TestDefault(t *testing.T) {
testlib.Mktmp(t)
var ctx = &context.Context{
ctx := &context.Context{
TokenType: context.TokenTypeGitHub,
Config: config.Project{
ProjectName: "barr",
@ -59,19 +59,19 @@ func TestDefault(t *testing.T) {
}
func Test_doRun(t *testing.T) {
var folder = testlib.Mktmp(t)
var file = filepath.Join(folder, "archive")
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0644))
folder := testlib.Mktmp(t)
file := filepath.Join(folder, "archive")
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
type errChecker func(*testing.T, error)
var shouldErr = func(msg string) errChecker {
shouldErr := func(msg string) errChecker {
return func(t *testing.T, err error) {
t.Helper()
require.Error(t, err)
require.EqualError(t, err, msg)
}
}
var shouldNotErr = func(t *testing.T, err error) {
shouldNotErr := func(t *testing.T, err error) {
t.Helper()
require.NoError(t, err)
}
@ -731,7 +731,7 @@ func Test_doRun(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var ctx = tt.args.ctx
ctx := tt.args.ctx
for _, a := range tt.artifacts {
ctx.Artifacts.Add(a)
}
@ -743,9 +743,9 @@ func Test_doRun(t *testing.T) {
}
func Test_buildManifest(t *testing.T) {
var folder = t.TempDir()
var file = filepath.Join(folder, "archive")
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0644))
folder := t.TempDir()
file := filepath.Join(folder, "archive")
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
tests := []struct {
filename string
@ -915,7 +915,7 @@ func Test_buildManifest(t *testing.T) {
for _, tt := range tests {
t.Run(tt.filename, func(t *testing.T) {
var ctx = tt.ctx
ctx := tt.ctx
err := Pipe{}.Default(ctx)
require.NoError(t, err)
@ -981,7 +981,7 @@ func Test_buildManifest(t *testing.T) {
require.NoError(t, err)
if *update {
require.NoError(t, os.WriteFile(tt.filename, out.Bytes(), 0655))
require.NoError(t, os.WriteFile(tt.filename, out.Bytes(), 0o655))
}
bts, err := os.ReadFile(tt.filename)
require.NoError(t, err)
@ -991,10 +991,10 @@ func Test_buildManifest(t *testing.T) {
}
func TestWrapInDirectory(t *testing.T) {
var folder = t.TempDir()
var file = filepath.Join(folder, "archive")
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0644))
var ctx = &context.Context{
folder := t.TempDir()
file := filepath.Join(folder, "archive")
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
ctx := &context.Context{
TokenType: context.TokenTypeGitLab,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
@ -1060,9 +1060,9 @@ func TestWrapInDirectory(t *testing.T) {
out, err := doBuildManifest(mf)
require.NoError(t, err)
var golden = "testdata/test_buildmanifest_wrap.json.golden"
golden := "testdata/test_buildmanifest_wrap.json.golden"
if *update {
require.NoError(t, os.WriteFile(golden, out.Bytes(), 0655))
require.NoError(t, os.WriteFile(golden, out.Bytes(), 0o655))
}
bts, err := os.ReadFile(golden)
require.NoError(t, err)

View File

@ -28,7 +28,7 @@ func (Pipe) String() string {
// Default sets the Pipes defaults.
func (Pipe) Default(ctx *context.Context) error {
var ids = ids.New("signs")
ids := ids.New("signs")
for i := range ctx.Config.Signs {
cfg := &ctx.Config.Signs[i]
if cfg.Cmd == "" {
@ -57,7 +57,7 @@ func (Pipe) Run(ctx *context.Context) error {
return pipe.ErrSkipSignEnabled
}
var g = semerrgroup.New(ctx.Parallelism)
g := semerrgroup.New(ctx.Parallelism)
for i := range ctx.Config.Signs {
cfg := ctx.Config.Signs[i]
g.Go(func() error {
@ -114,7 +114,7 @@ func signone(ctx *context.Context, cfg config.Sign, a *artifact.Artifact) (*arti
// nolint:prealloc
var args []string
for _, a := range cfg.Args {
var arg = expand(a, env)
arg := expand(a, env)
arg, err := tmpl.New(ctx).WithEnv(env).Apply(arg)
if err != nil {
return nil, fmt.Errorf("sign failed: %s: invalid template: %w", a, err)

View File

@ -74,9 +74,9 @@ func (Pipe) String() string {
// Default sets the pipe defaults.
func (Pipe) Default(ctx *context.Context) error {
var ids = ids.New("snapcrafts")
ids := ids.New("snapcrafts")
for i := range ctx.Config.Snapcrafts {
var snap = &ctx.Config.Snapcrafts[i]
snap := &ctx.Config.Snapcrafts[i]
if snap.NameTemplate == "" {
snap.NameTemplate = defaultNameTemplate
}
@ -116,7 +116,7 @@ func doRun(ctx *context.Context, snap config.Snapcraft) error {
return ErrNoSnapcraft
}
var g = semerrgroup.New(ctx.Parallelism)
g := semerrgroup.New(ctx.Parallelism)
for platform, binaries := range ctx.Artifacts.Filter(
artifact.And(
artifact.ByGoos("linux"),
@ -153,7 +153,7 @@ func (Pipe) Publish(ctx *context.Context) error {
return pipe.ErrSkipPublishEnabled
}
snaps := ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableSnapcraft)).List()
var g = semerrgroup.New(ctx.Parallelism)
g := semerrgroup.New(ctx.Parallelism)
for _, snap := range snaps {
snap := snap
g.Go(func() error {
@ -164,7 +164,7 @@ func (Pipe) Publish(ctx *context.Context) error {
}
func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries []*artifact.Artifact) error {
var log = log.WithField("arch", arch)
log := log.WithField("arch", arch)
folder, err := tmpl.New(ctx).
WithArtifact(binaries[0], snap.Replacements).
Apply(snap.NameTemplate)
@ -173,11 +173,11 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
}
// prime is the directory that then will be compressed to make the .snap package.
var folderDir = filepath.Join(ctx.Config.Dist, folder)
var primeDir = filepath.Join(folderDir, "prime")
var metaDir = filepath.Join(primeDir, "meta")
folderDir := filepath.Join(ctx.Config.Dist, folder)
primeDir := filepath.Join(folderDir, "prime")
metaDir := filepath.Join(primeDir, "meta")
// #nosec
if err = os.MkdirAll(metaDir, 0755); err != nil {
if err = os.MkdirAll(metaDir, 0o755); err != nil {
return err
}
@ -186,9 +186,9 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
file.Destination = file.Source
}
if file.Mode == 0 {
file.Mode = 0644
file.Mode = 0o644
}
if err := os.MkdirAll(filepath.Join(primeDir, filepath.Dir(file.Destination)), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(primeDir, filepath.Dir(file.Destination)), 0o755); err != nil {
return fmt.Errorf("failed to link extra file '%s': %w", file.Source, err)
}
if err := link(file.Source, filepath.Join(primeDir, file.Destination), os.FileMode(file.Mode)); err != nil {
@ -196,10 +196,10 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
}
}
var file = filepath.Join(primeDir, "meta", "snap.yaml")
file := filepath.Join(primeDir, "meta", "snap.yaml")
log.WithField("file", file).Debug("creating snap metadata")
var metadata = &Metadata{
metadata := &Metadata{
Version: ctx.Version,
Summary: snap.Summary,
Description: snap.Description,
@ -235,7 +235,7 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
// if the user didn't specify any apps then
// default to the main binary being the command:
if len(snap.Apps) == 0 {
var name = snap.Name
name := snap.Name
if name == "" {
name = binaries[0].Name
}
@ -254,7 +254,7 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
if err = os.Link(binary.Path, destBinaryPath); err != nil {
return fmt.Errorf("failed to link binary: %w", err)
}
if err := os.Chmod(destBinaryPath, 0555); err != nil {
if err := os.Chmod(destBinaryPath, 0o555); err != nil {
return fmt.Errorf("failed to change binary permissions: %w", err)
}
}
@ -280,7 +280,7 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
if config.Completer != "" {
destCompleterPath := filepath.Join(primeDir, config.Completer)
if err := os.MkdirAll(filepath.Dir(destCompleterPath), 0755); err != nil {
if err := os.MkdirAll(filepath.Dir(destCompleterPath), 0o755); err != nil {
return fmt.Errorf("failed to create folder: %w", err)
}
log.WithField("src", config.Completer).
@ -289,7 +289,7 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
if err := os.Link(config.Completer, destCompleterPath); err != nil {
return fmt.Errorf("failed to link completer: %w", err)
}
if err := os.Chmod(destCompleterPath, 0644); err != nil {
if err := os.Chmod(destCompleterPath, 0o644); err != nil {
return fmt.Errorf("failed to change completer permissions: %w", err)
}
appMetadata.Completer = config.Completer
@ -305,14 +305,14 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
}
log.WithField("file", file).Debugf("writing metadata file")
if err = os.WriteFile(file, out, 0644); err != nil { //nolint: gosec
if err = os.WriteFile(file, out, 0o644); err != nil { //nolint: gosec
return err
}
var snapFile = filepath.Join(ctx.Config.Dist, folder+".snap")
snapFile := filepath.Join(ctx.Config.Dist, folder+".snap")
log.WithField("snap", snapFile).Info("creating")
/* #nosec */
var cmd = exec.CommandContext(ctx, "snapcraft", "pack", primeDir, "--output", snapFile)
cmd := exec.CommandContext(ctx, "snapcraft", "pack", primeDir, "--output", snapFile)
if out, err = cmd.CombinedOutput(); err != nil {
return fmt.Errorf("failed to generate snap package: %s", string(out))
}
@ -333,11 +333,11 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
const reviewWaitMsg = `Waiting for previous upload(s) to complete their review process.`
func push(ctx *context.Context, snap *artifact.Artifact) error {
var log = log.WithField("snap", snap.Name)
log := log.WithField("snap", snap.Name)
log.Info("pushing snap")
// TODO: customize --release based on snap.Grade?
/* #nosec */
var cmd = exec.CommandContext(ctx, "snapcraft", "upload", "--release=stable", snap.Path)
cmd := exec.CommandContext(ctx, "snapcraft", "upload", "--release=stable", snap.Path)
if out, err := cmd.CombinedOutput(); err != nil {
if strings.Contains(string(out), reviewWaitMsg) {
log.Warn(reviewWaitMsg)
@ -361,7 +361,7 @@ func link(src, dest string, mode os.FileMode) error {
// - dest = "dist/linuxamd64/b"
// - path = "a/b/c.txt"
// So we join "a/b" with "c.txt" and use it as the destination.
var dst = filepath.Join(dest, strings.Replace(path, src, "", 1))
dst := filepath.Join(dest, strings.Replace(path, src, "", 1))
log.WithFields(log.Fields{
"src": path,
"dst": dst,

View File

@ -31,7 +31,7 @@ func TestRunPipeMissingInfo(t *testing.T) {
pipe.Skip("no summary nor description were provided"): {},
} {
t.Run(fmt.Sprintf("testing if %v happens", eerr), func(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Snapcrafts: []config.Snapcraft{
snap,
@ -44,10 +44,10 @@ func TestRunPipeMissingInfo(t *testing.T) {
}
func TestRunPipe(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
var ctx = context.New(config.Project{
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := context.New(config.Project{
ProjectName: "mybin",
Dist: dist,
Snapcrafts: []config.Snapcraft{
@ -84,10 +84,10 @@ func TestRunPipe(t *testing.T) {
}
func TestRunPipeInvalidNameTemplate(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
var ctx = context.New(config.Project{
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := context.New(config.Project{
ProjectName: "foo",
Dist: dist,
Snapcrafts: []config.Snapcraft{
@ -106,10 +106,10 @@ func TestRunPipeInvalidNameTemplate(t *testing.T) {
}
func TestRunPipeWithName(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
var ctx = context.New(config.Project{
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := context.New(config.Project{
ProjectName: "testprojectname",
Dist: dist,
Snapcrafts: []config.Snapcraft{
@ -140,10 +140,10 @@ func TestRunPipeWithName(t *testing.T) {
}
func TestRunPipeMetadata(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
var ctx = context.New(config.Project{
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := context.New(config.Project{
ProjectName: "testprojectname",
Dist: dist,
Snapcrafts: []config.Snapcraft{
@ -193,12 +193,12 @@ func TestRunPipeMetadata(t *testing.T) {
}
func TestNoSnapcraftInPath(t *testing.T) {
var path = os.Getenv("PATH")
path := os.Getenv("PATH")
defer func() {
require.NoError(t, os.Setenv("PATH", path))
}()
require.NoError(t, os.Setenv("PATH", ""))
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Snapcrafts: []config.Snapcraft{
{
Summary: "dummy",
@ -210,10 +210,10 @@ func TestNoSnapcraftInPath(t *testing.T) {
}
func TestRunNoArguments(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
var ctx = context.New(config.Project{
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := context.New(config.Project{
ProjectName: "testprojectname",
Dist: dist,
Snapcrafts: []config.Snapcraft{
@ -244,10 +244,10 @@ func TestRunNoArguments(t *testing.T) {
}
func TestCompleter(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
var ctx = context.New(config.Project{
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := context.New(config.Project{
ProjectName: "testprojectname",
Dist: dist,
Snapcrafts: []config.Snapcraft{
@ -281,10 +281,10 @@ func TestCompleter(t *testing.T) {
}
func TestCommand(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
var ctx = context.New(config.Project{
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := context.New(config.Project{
ProjectName: "testprojectname",
Dist: dist,
Snapcrafts: []config.Snapcraft{
@ -316,10 +316,10 @@ func TestCommand(t *testing.T) {
}
func TestExtraFile(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
var ctx = context.New(config.Project{
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := context.New(config.Project{
ProjectName: "testprojectname",
Dist: dist,
Snapcrafts: []config.Snapcraft{
@ -331,7 +331,7 @@ func TestExtraFile(t *testing.T) {
{
Source: "testdata/extra-file.txt",
Destination: "a/b/c/extra-file.txt",
Mode: 0755,
Mode: 0o755,
},
{
Source: "testdata/extra-file-2.txt",
@ -351,18 +351,18 @@ func TestExtraFile(t *testing.T) {
destFile, err := os.Stat(filepath.Join(dist, "foo_amd64", "prime", "a", "b", "c", "extra-file.txt"))
require.NoError(t, err)
require.Equal(t, inode(srcFile), inode(destFile))
require.Equal(t, destFile.Mode(), os.FileMode(0755))
require.Equal(t, destFile.Mode(), os.FileMode(0o755))
srcFile, err = os.Stat("testdata/extra-file-2.txt")
require.NoError(t, err)
destFileWithDefaults, err := os.Stat(filepath.Join(dist, "foo_amd64", "prime", "testdata", "extra-file-2.txt"))
require.NoError(t, err)
require.Equal(t, destFileWithDefaults.Mode(), os.FileMode(0644))
require.Equal(t, destFileWithDefaults.Mode(), os.FileMode(0o644))
require.Equal(t, inode(srcFile), inode(destFileWithDefaults))
}
func TestDefault(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Builds: []config.Build{
{
ID: "foo",
@ -378,7 +378,7 @@ func TestDefault(t *testing.T) {
}
func TestPublish(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.Artifacts.Add(&artifact.Artifact{
Name: "mybin",
Path: "nope.snap",
@ -391,7 +391,7 @@ func TestPublish(t *testing.T) {
}
func TestPublishSkip(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
ctx.SkipPublish = true
ctx.Artifacts.Add(&artifact.Artifact{
Name: "mybin",
@ -404,7 +404,7 @@ func TestPublishSkip(t *testing.T) {
}
func TestDefaultSet(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Snapcrafts: []config.Snapcraft{
{
NameTemplate: "foo",
@ -419,9 +419,9 @@ func addBinaries(t *testing.T, ctx *context.Context, name, dist string) {
t.Helper()
for _, goos := range []string{"linux", "darwin"} {
for _, goarch := range []string{"amd64", "386", "arm6"} {
var folder = goos + goarch
require.NoError(t, os.MkdirAll(filepath.Join(dist, folder), 0755))
var binPath = filepath.Join(dist, folder, name)
folder := goos + goarch
require.NoError(t, os.MkdirAll(filepath.Join(dist, folder), 0o755))
binPath := filepath.Join(dist, folder, name)
f, err := os.Create(binPath)
require.NoError(t, err)
require.NoError(t, f.Close())
@ -440,7 +440,7 @@ func addBinaries(t *testing.T, ctx *context.Context, name, dist string) {
}
func TestSeveralSnapssWithTheSameID(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Snapcrafts: []config.Snapcraft{
{

View File

@ -12,8 +12,9 @@ import (
func TestStringer(t *testing.T) {
require.NotEmpty(t, Pipe{}.String())
}
func TestDefault(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Snapshot: config.Snapshot{},
},
@ -23,7 +24,7 @@ func TestDefault(t *testing.T) {
}
func TestDefaultSet(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Snapshot: config.Snapshot{
NameTemplate: "snap",
@ -35,7 +36,7 @@ func TestDefaultSet(t *testing.T) {
}
func TestSnapshotInvalidNametemplate(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Snapshot: config.Snapshot{
NameTemplate: "{{.ShortCommit}{{{sss}}}",
},
@ -45,7 +46,7 @@ func TestSnapshotInvalidNametemplate(t *testing.T) {
}
func TestSnapshotEmptyFinalName(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Snapshot: config.Snapshot{
NameTemplate: "{{ .Commit }}",
},
@ -56,6 +57,6 @@ func TestSnapshotEmptyFinalName(t *testing.T) {
}
func TestNotASnapshot(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
}

View File

@ -15,16 +15,16 @@ import (
func TestArchive(t *testing.T) {
for _, format := range []string{"tar.gz", "tar", "zip"} {
t.Run(format, func(t *testing.T) {
var tmp = testlib.Mktmp(t)
require.NoError(t, os.Mkdir("dist", 0744))
tmp := testlib.Mktmp(t)
require.NoError(t, os.Mkdir("dist", 0o744))
testlib.GitInit(t)
require.NoError(t, os.WriteFile("code.txt", []byte("not really code"), 0655))
require.NoError(t, os.WriteFile("README.md", []byte("# my dope fake project"), 0655))
require.NoError(t, os.WriteFile("code.txt", []byte("not really code"), 0o655))
require.NoError(t, os.WriteFile("README.md", []byte("# my dope fake project"), 0o655))
testlib.GitAdd(t)
testlib.GitCommit(t, "feat: first")
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "foo",
Dist: "dist",
Source: config.Source{
@ -38,7 +38,7 @@ func TestArchive(t *testing.T) {
require.NoError(t, Pipe{}.Default(ctx))
require.NoError(t, Pipe{}.Run(ctx))
var artifacts = ctx.Artifacts.List()
artifacts := ctx.Artifacts.List()
require.Len(t, artifacts, 1)
require.Equal(t, artifact.Artifact{
Type: artifact.UploadableSourceArchive,
@ -56,7 +56,7 @@ func TestArchive(t *testing.T) {
}
func TestDefault(t *testing.T) {
var ctx = context.New(config.Project{})
ctx := context.New(config.Project{})
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, config.Source{
NameTemplate: "{{ .ProjectName }}-{{ .Version }}",
@ -65,7 +65,7 @@ func TestDefault(t *testing.T) {
}
func TestInvalidNameTemplate(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Source: config.Source{
Enabled: true,
NameTemplate: "{{ .foo }-asdda",

View File

@ -36,18 +36,14 @@ func teardown() {
server.Close()
}
func testMethod(t *testing.T, r *http.Request, want string) {
func requireMethodPut(t *testing.T, r *http.Request) {
t.Helper()
if got := r.Method; got != want {
t.Errorf("Request method: %v, want %v", got, want)
}
require.Equal(t, http.MethodPut, r.Method)
}
func testHeader(t *testing.T, r *http.Request, header, want string) {
func requireHeader(t *testing.T, r *http.Request, header, want string) {
t.Helper()
if got := r.Header.Get(header); got != want {
t.Errorf("Header.Get(%q) returned %q, want %q", header, got, want)
}
require.Equal(t, want, r.Header.Get(header))
}
// TODO: improve all tests bellow by checking wether the mocked handlers
@ -57,53 +53,53 @@ func TestRunPipe_ModeBinary(t *testing.T) {
setup()
defer teardown()
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var binPath = filepath.Join(dist, "mybin", "mybin")
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0o755))
binPath := filepath.Join(dist, "mybin", "mybin")
d1 := []byte("hello\ngo\n")
require.NoError(t, os.WriteFile(binPath, d1, 0666))
require.NoError(t, os.WriteFile(binPath, d1, 0o666))
// Dummy http server
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.Header().Set("Location", "/production-repo-remote/mybin/linux/amd64/mybin")
w.WriteHeader(http.StatusCreated)
})
mux.HandleFunc("/example-repo-local/mybin/linux/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.Header().Set("Location", "/production-repo-remote/mybin/linux/amd64/mybin")
w.WriteHeader(http.StatusCreated)
})
mux.HandleFunc("/production-repo-remote/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "productionuser" with secret "productionuser-apikey"
testHeader(t, r, "Authorization", "Basic cHJvZHVjdGlvbnVzZXI6cHJvZHVjdGlvbnVzZXItYXBpa2V5")
requireHeader(t, r, "Authorization", "Basic cHJvZHVjdGlvbnVzZXI6cHJvZHVjdGlvbnVzZXItYXBpa2V5")
w.Header().Set("Location", "/production-repo-remote/mybin/linux/amd64/mybin")
w.WriteHeader(http.StatusCreated)
})
mux.HandleFunc("/production-repo-remote/mybin/linux/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "productionuser" with secret "productionuser-apikey"
testHeader(t, r, "Authorization", "Basic cHJvZHVjdGlvbnVzZXI6cHJvZHVjdGlvbnVzZXItYXBpa2V5")
requireHeader(t, r, "Authorization", "Basic cHJvZHVjdGlvbnVzZXI6cHJvZHVjdGlvbnVzZXItYXBpa2V5")
w.Header().Set("Location", "/production-repo-remote/mybin/linux/amd64/mybin")
w.WriteHeader(http.StatusCreated)
})
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "mybin",
Dist: dist,
Uploads: []config.Upload{
@ -147,7 +143,7 @@ func TestRunPipe_ModeArchive(t *testing.T) {
setup()
defer teardown()
var folder = t.TempDir()
folder := t.TempDir()
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
require.NoError(t, err)
require.NoError(t, tarfile.Close())
@ -155,7 +151,7 @@ func TestRunPipe_ModeArchive(t *testing.T) {
require.NoError(t, err)
require.NoError(t, debfile.Close())
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "goreleaser",
Dist: folder,
Uploads: []config.Upload{
@ -190,18 +186,18 @@ func TestRunPipe_ModeArchive(t *testing.T) {
// Dummy http server
mux.HandleFunc("/example-repo-local/goreleaser/1.0.0/bin.tar.gz", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
requireMethodPut(t, r)
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.Header().Set("Location", "/example-repo-local/goreleaser/1.0.0/bin.tar.gz")
w.WriteHeader(http.StatusCreated)
uploads.Store("targz", true)
})
mux.HandleFunc("/example-repo-local/goreleaser/1.0.0/bin.deb", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
requireMethodPut(t, r)
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.Header().Set("Location", "/example-repo-local/goreleaser/1.0.0/bin.deb")
w.WriteHeader(http.StatusCreated)
@ -219,35 +215,35 @@ func TestRunPipe_ModeBinary_CustomArtifactName(t *testing.T) {
setup()
defer teardown()
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var binPath = filepath.Join(dist, "mybin", "mybin")
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0o755))
binPath := filepath.Join(dist, "mybin", "mybin")
d1 := []byte("hello\ngo\n")
require.NoError(t, os.WriteFile(binPath, d1, 0666))
require.NoError(t, os.WriteFile(binPath, d1, 0o666))
// Dummy http server
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin;deb.distribution=xenial", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.Header().Set("Location", "/production-repo-remote/mybin/linux/amd64/mybin;deb.distribution=xenial")
w.WriteHeader(http.StatusCreated)
})
mux.HandleFunc("/example-repo-local/mybin/linux/amd64/mybin;deb.distribution=xenial", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.Header().Set("Location", "/example-repo-local/mybin/linux/amd64/mybin;deb.distribution=xenial")
w.WriteHeader(http.StatusCreated)
})
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "mybin",
Dist: dist,
Uploads: []config.Upload{
@ -284,7 +280,7 @@ func TestRunPipe_ModeArchive_CustomArtifactName(t *testing.T) {
setup()
defer teardown()
var folder = t.TempDir()
folder := t.TempDir()
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
require.NoError(t, err)
require.NoError(t, tarfile.Close())
@ -292,7 +288,7 @@ func TestRunPipe_ModeArchive_CustomArtifactName(t *testing.T) {
require.NoError(t, err)
require.NoError(t, debfile.Close())
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "goreleaser",
Dist: folder,
Uploads: []config.Upload{
@ -328,18 +324,18 @@ func TestRunPipe_ModeArchive_CustomArtifactName(t *testing.T) {
// Dummy http server
mux.HandleFunc("/example-repo-local/goreleaser/1.0.0/bin.tar.gz;deb.distribution=xenial", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
requireMethodPut(t, r)
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.Header().Set("Location", "/example-repo-local/goreleaser/1.0.0/bin.tar.gz;deb.distribution=xenial")
w.WriteHeader(http.StatusCreated)
uploads.Store("targz", true)
})
mux.HandleFunc("/example-repo-local/goreleaser/1.0.0/bin.deb;deb.distribution=xenial", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
requireMethodPut(t, r)
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.Header().Set("Location", "/example-repo-local/goreleaser/1.0.0/bin.deb;deb.distribution=xenial")
w.WriteHeader(http.StatusCreated)
@ -354,12 +350,12 @@ func TestRunPipe_ModeArchive_CustomArtifactName(t *testing.T) {
}
func TestRunPipe_ArtifactoryDown(t *testing.T) {
var folder = t.TempDir()
folder := t.TempDir()
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
require.NoError(t, err)
require.NoError(t, tarfile.Close())
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "goreleaser",
Dist: folder,
Uploads: []config.Upload{
@ -387,11 +383,11 @@ func TestRunPipe_ArtifactoryDown(t *testing.T) {
}
func TestRunPipe_TargetTemplateError(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
var binPath = filepath.Join(dist, "mybin", "mybin")
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
binPath := filepath.Join(dist, "mybin", "mybin")
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "mybin",
Dist: dist,
Uploads: []config.Upload{
@ -418,7 +414,7 @@ func TestRunPipe_TargetTemplateError(t *testing.T) {
Goos: "darwin",
Type: artifact.UploadableBinary,
})
var err = Pipe{}.Publish(ctx)
err := Pipe{}.Publish(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), `upload: error while building the target url: template: tmpl:1: unexpected "/" in operand`)
}
@ -427,25 +423,25 @@ func TestRunPipe_BadCredentials(t *testing.T) {
setup()
defer teardown()
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var binPath = filepath.Join(dist, "mybin", "mybin")
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0o755))
binPath := filepath.Join(dist, "mybin", "mybin")
d1 := []byte("hello\ngo\n")
require.NoError(t, os.WriteFile(binPath, d1, 0666))
require.NoError(t, os.WriteFile(binPath, d1, 0o666))
// Dummy http server
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
requireMethodPut(t, r)
requireHeader(t, r, "Content-Length", "9")
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.WriteHeader(http.StatusUnauthorized)
})
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "mybin",
Dist: dist,
Uploads: []config.Upload{
@ -472,13 +468,13 @@ func TestRunPipe_BadCredentials(t *testing.T) {
Type: artifact.UploadableBinary,
})
var err = Pipe{}.Publish(ctx)
err := Pipe{}.Publish(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), "Unauthorized")
}
func TestRunPipe_FileNotFound(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "mybin",
Dist: "archivetest/dist",
Uploads: []config.Upload{
@ -509,15 +505,15 @@ func TestRunPipe_FileNotFound(t *testing.T) {
}
func TestRunPipe_UnparsableTarget(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var binPath = filepath.Join(dist, "mybin", "mybin")
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0o755))
binPath := filepath.Join(dist, "mybin", "mybin")
d1 := []byte("hello\ngo\n")
require.NoError(t, os.WriteFile(binPath, d1, 0666))
require.NoError(t, os.WriteFile(binPath, d1, 0o666))
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "mybin",
Dist: dist,
Uploads: []config.Upload{
@ -548,7 +544,7 @@ func TestRunPipe_UnparsableTarget(t *testing.T) {
}
func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
Uploads: []config.Upload{
{
Name: "production",
@ -572,13 +568,13 @@ func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
}
func TestRunPipe_DirUpload(t *testing.T) {
var folder = t.TempDir()
var dist = filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var binPath = filepath.Join(dist, "mybin")
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0o755))
binPath := filepath.Join(dist, "mybin")
var ctx = context.New(config.Project{
ctx := context.New(config.Project{
ProjectName: "mybin",
Dist: dist,
Uploads: []config.Upload{
@ -617,7 +613,7 @@ func TestNoPuts(t *testing.T) {
}
func TestPutsWithoutTarget(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Env: map[string]string{
"UPLOAD_PRODUCTION_SECRET": "deployuser-secret",
},
@ -636,7 +632,7 @@ func TestPutsWithoutTarget(t *testing.T) {
}
func TestPutsWithoutUsername(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Env: map[string]string{
"UPLOAD_PRODUCTION_SECRET": "deployuser-secret",
},
@ -680,7 +676,7 @@ func TestPutsWithoutSecret(t *testing.T) {
}
func TestPutsWithInvalidMode(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Env: map[string]string{
"UPLOAD_PRODUCTION_SECRET": "deployuser-secret",
},
@ -700,7 +696,7 @@ func TestPutsWithInvalidMode(t *testing.T) {
}
func TestDefault(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Uploads: []config.Upload{
{
@ -713,13 +709,13 @@ func TestDefault(t *testing.T) {
}
require.NoError(t, Pipe{}.Default(ctx))
require.Len(t, ctx.Config.Uploads, 1)
var upload = ctx.Config.Uploads[0]
upload := ctx.Config.Uploads[0]
require.Equal(t, "archive", upload.Mode)
require.Equal(t, h.MethodPut, upload.Method)
}
func TestDefaultNoPuts(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Uploads: []config.Upload{},
},
@ -729,7 +725,7 @@ func TestDefaultNoPuts(t *testing.T) {
}
func TestDefaultSet(t *testing.T) {
var ctx = &context.Context{
ctx := &context.Context{
Config: config.Project{
Uploads: []config.Upload{
{
@ -741,7 +737,7 @@ func TestDefaultSet(t *testing.T) {
}
require.NoError(t, Pipe{}.Default(ctx))
require.Len(t, ctx.Config.Uploads, 1)
var upload = ctx.Config.Uploads[0]
upload := ctx.Config.Uploads[0]
require.Equal(t, "custom", upload.Mode)
require.Equal(t, h.MethodPost, upload.Method)
}

View File

@ -89,7 +89,7 @@ type skipAwareGroup struct {
// Go execs runs `fn` and saves the result if no error has been encountered.
func (s *skipAwareGroup) Go(fn func() error) {
s.g.Go(func() error {
var err = fn()
err := fn()
// if the err is a skip, set it for later, but return nil for now so the
// the group proceeds.
if pipe.IsSkip(err) {

View File

@ -11,7 +11,7 @@ import (
)
func TestSemaphore(t *testing.T) {
var g = New(4)
g := New(4)
var lock sync.Mutex
var counter int
for i := 0; i < 10; i++ {
@ -28,9 +28,9 @@ func TestSemaphore(t *testing.T) {
}
func TestSemaphoreOrder(t *testing.T) {
var num = 10
var g = New(1)
var output = []int{}
num := 10
g := New(1)
output := []int{}
for i := 0; i < num; i++ {
i := i
g.Go(func() error {
@ -43,8 +43,8 @@ func TestSemaphoreOrder(t *testing.T) {
}
func TestSemaphoreOrderError(t *testing.T) {
var g = New(1)
var output = []int{}
g := New(1)
output := []int{}
for i := 0; i < 10; i++ {
i := i
g.Go(func() error {
@ -57,7 +57,7 @@ func TestSemaphoreOrderError(t *testing.T) {
}
func TestSemaphoreSkipAware(t *testing.T) {
var g = NewSkipAware(New(1))
g := NewSkipAware(New(1))
var lock sync.Mutex
var counter int
for i := 0; i < 10; i++ {
@ -74,7 +74,7 @@ func TestSemaphoreSkipAware(t *testing.T) {
}
func TestSemaphoreSkipAndRealError(t *testing.T) {
var g = NewSkipAware(New(10))
g := NewSkipAware(New(10))
for i := 0; i < 100; i++ {
g.Go(func() error {
time.Sleep(10 * time.Millisecond)

View File

@ -13,6 +13,7 @@ import (
)
func TestWithArtifact(t *testing.T) {
t.Parallel()
ctx := context.New(config.Project{
ProjectName: "proj",
})

View File

@ -8,18 +8,18 @@ import (
)
func TestArchive(t *testing.T) {
var folder = t.TempDir()
folder := t.TempDir()
empty, err := os.Create(folder + "/empty.txt")
require.NoError(t, err)
require.NoError(t, empty.Close())
require.NoError(t, os.Mkdir(folder+"/folder-inside", 0755))
require.NoError(t, os.Mkdir(folder+"/folder-inside", 0o755))
for _, format := range []string{"tar.gz", "zip", "gz", "tar.xz", "willbeatargzanyway"} {
format := format
t.Run(format, func(t *testing.T) {
file, err := os.Create(folder + "/folder." + format)
require.NoError(t, err)
var archive = New(file)
archive := New(file)
t.Cleanup(func() {
require.NoError(t, archive.Close())
require.NoError(t, file.Close())

View File

@ -11,7 +11,7 @@ import (
)
func TestGzFile(t *testing.T) {
var tmp = t.TempDir()
tmp := t.TempDir()
f, err := os.Create(filepath.Join(tmp, "test.gz"))
require.NoError(t, err)
defer f.Close() // nolint: errcheck

View File

@ -12,7 +12,7 @@ import (
)
func TestTarGzFile(t *testing.T) {
var tmp = t.TempDir()
tmp := t.TempDir()
f, err := os.Create(filepath.Join(tmp, "test.tar.gz"))
require.NoError(t, err)
defer f.Close() // nolint: errcheck
@ -55,7 +55,7 @@ func TestTarGzFile(t *testing.T) {
paths = append(paths, next.Name)
t.Logf("%s: %v", next.Name, next.FileInfo().Mode())
if next.Name == "sub1/executable" {
var ex = next.FileInfo().Mode() | 0111
ex := next.FileInfo().Mode() | 0o111
require.Equal(t, next.FileInfo().Mode().String(), ex.String())
}
}

View File

@ -12,7 +12,7 @@ import (
)
func TestTarXzFile(t *testing.T) {
var tmp = t.TempDir()
tmp := t.TempDir()
f, err := os.Create(filepath.Join(tmp, "test.tar.xz"))
require.NoError(t, err)
defer f.Close() // nolint: errcheck
@ -53,7 +53,7 @@ func TestTarXzFile(t *testing.T) {
paths = append(paths, next.Name)
t.Logf("%s: %v", next.Name, next.FileInfo().Mode())
if next.Name == "sub1/executable" {
var ex = next.FileInfo().Mode() | 0111
ex := next.FileInfo().Mode() | 0o111
require.Equal(t, next.FileInfo().Mode().String(), ex.String())
}
}

View File

@ -10,7 +10,7 @@ import (
)
func TestZipFile(t *testing.T) {
var tmp = t.TempDir()
tmp := t.TempDir()
f, err := os.Create(filepath.Join(tmp, "test.zip"))
require.NoError(t, err)
defer f.Close() // nolint: errcheck
@ -40,12 +40,12 @@ func TestZipFile(t *testing.T) {
r, err := zip.NewReader(f, info.Size())
require.NoError(t, err)
var paths = make([]string, len(r.File))
paths := make([]string, len(r.File))
for i, zf := range r.File {
paths[i] = zf.Name
t.Logf("%s: %v", zf.Name, zf.Mode())
if zf.Name == "sub1/executable" {
var ex = zf.Mode() | 0111
ex := zf.Mode() | 0o111
require.Equal(t, zf.Mode().String(), ex.String())
}
}

View File

@ -13,12 +13,13 @@ type dummy struct{}
func (*dummy) WithDefaults(build config.Build) (config.Build, error) {
return build, nil
}
func (*dummy) Build(ctx *context.Context, build config.Build, options Options) error {
return nil
}
func TestRegisterAndGet(t *testing.T) {
var builder = &dummy{}
builder := &dummy{}
Register("dummy", builder)
require.Equal(t, builder, For("dummy"))
}

View File

@ -9,7 +9,7 @@ import (
func TestUnmarshalHomebrewDependency(t *testing.T) {
t.Run("string arr", func(t *testing.T) {
var conf = `
conf := `
brews:
- name: foo
dependencies:
@ -30,7 +30,7 @@ brews:
})
t.Run("mixed", func(t *testing.T) {
var conf = `
conf := `
brews:
- name: foo
dependencies:
@ -56,7 +56,7 @@ brews:
})
t.Run("mixed", func(t *testing.T) {
var conf = `
conf := `
brews:
- name: foo
dependencies:

View File

@ -23,7 +23,7 @@ func TestEmptyRepoNameAndOwner(t *testing.T) {
}
func TestLoadReader(t *testing.T) {
var conf = `
conf := `
nfpms:
- homepage: http://goreleaser.github.io
`
@ -39,6 +39,7 @@ type errorReader struct{}
func (errorReader) Read(p []byte) (n int, err error) {
return 1, fmt.Errorf("error")
}
func TestLoadBadReader(t *testing.T) {
_, err := LoadReader(errorReader{})
require.Error(t, err)

View File

@ -12,7 +12,7 @@ import (
func TestNew(t *testing.T) {
require.NoError(t, os.Setenv("FOO", "NOT BAR"))
require.NoError(t, os.Setenv("BAR", "1"))
var ctx = New(config.Project{
ctx := New(config.Project{
Env: []string{
"FOO=BAR",
},