mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-26 04:22:05 +02:00
feat(ci): compile with go 1.19 (#3278)
* feat(ci): compile with go 1.19 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: fixing template test Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: improve check Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: more test and docs fixes Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: fix Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: fix * test: fix * fix: lint Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: docker templates Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: godoc for RequireTemplateError
This commit is contained in:
parent
f71230272b
commit
ee17c9583d
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -64,7 +64,7 @@ jobs:
|
||||
mkdir -p $HOME/.cache/snapcraft/stage-packages
|
||||
- uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a # v3
|
||||
with:
|
||||
go-version: '1.18'
|
||||
go-version: '1.19'
|
||||
- uses: actions/cache@661fd3eb7f2f20d8c7c84bc2b0509efd7a826628 # v2
|
||||
with:
|
||||
path: |
|
||||
|
2
.github/workflows/docs.yml
vendored
2
.github/workflows/docs.yml
vendored
@ -23,7 +23,7 @@ jobs:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a # v3
|
||||
with:
|
||||
go-version: 1.18
|
||||
go-version: 1.19
|
||||
- run: task docs:build
|
||||
- uses: wjdp/htmltest-action@09118714cd26bef56bd3d0819e4f9b1dce6f60a9 # master
|
||||
with:
|
||||
|
2
.github/workflows/generate.yml
vendored
2
.github/workflows/generate.yml
vendored
@ -24,7 +24,7 @@ jobs:
|
||||
token: ${{ secrets.GH_PAT }}
|
||||
- uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a # v3
|
||||
with:
|
||||
go-version: 1.18
|
||||
go-version: 1.19
|
||||
- uses: arduino/setup-task@ca745e18916de727f841ec824ac20a615f1cddea # v1
|
||||
- run: task docs:generate
|
||||
- run: task schema:generate
|
||||
|
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
@ -19,7 +19,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a # v3
|
||||
with:
|
||||
go-version: ~1.18
|
||||
go-version: ~1.19
|
||||
- uses: actions/checkout@b0e28b5ac45a892f91e7d036f8200cf5ed489415 # v3
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@537aa1903e5d359d0b27dbc19ddd22c5087f3fbc # v3
|
||||
|
@ -1,5 +1,5 @@
|
||||
run:
|
||||
go: 1.18
|
||||
go: 1.19
|
||||
linters:
|
||||
enable:
|
||||
- thelper
|
||||
|
@ -9,7 +9,7 @@ By participating to this project, you agree to abide our [code of conduct](https
|
||||
Prerequisites:
|
||||
|
||||
- [Task](https://taskfile.dev/#/installation)
|
||||
- [Go 1.18+](https://golang.org/doc/install)
|
||||
- [Go 1.19+](https://golang.org/doc/install)
|
||||
|
||||
Other things you might need to run the tests:
|
||||
|
||||
|
@ -62,7 +62,7 @@ func goModInit(tb testing.TB) {
|
||||
tb.Helper()
|
||||
createFile(tb, "go.mod", `module foo
|
||||
|
||||
go 1.18
|
||||
go 1.19
|
||||
`)
|
||||
}
|
||||
|
||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
||||
module github.com/goreleaser/goreleaser
|
||||
|
||||
go 1.18
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
code.gitea.io/sdk/gitea v0.15.1
|
||||
|
@ -405,7 +405,7 @@ func TestExtra(t *testing.T) {
|
||||
|
||||
t.Run("unmarshal error", func(t *testing.T) {
|
||||
_, err := Extra[config.Docker](a, "fail-plz")
|
||||
require.EqualError(t, err, "json: unknown field \"Name\"")
|
||||
require.EqualError(t, err, "json: unknown field \"tap\"")
|
||||
})
|
||||
|
||||
t.Run("marshal error", func(t *testing.T) {
|
||||
|
@ -258,8 +258,9 @@ func TestDefaults(t *testing.T) {
|
||||
|
||||
// createFakeGoBinaryWithVersion creates a temporary executable with the
|
||||
// given name, which will output a go version string with the given version.
|
||||
// The temporary directory created by this function will be placed in the PATH
|
||||
// variable for the duration of (and cleaned up at the end of) the
|
||||
//
|
||||
// The temporary directory created by this function will be placed in the
|
||||
// PATH variable for the duration of (and cleaned up at the end of) the
|
||||
// current test run.
|
||||
func createFakeGoBinaryWithVersion(tb testing.TB, name, version string) {
|
||||
tb.Helper()
|
||||
@ -626,7 +627,7 @@ func TestRunInvalidAsmflags(t *testing.T) {
|
||||
err := Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||
Target: runtimeTarget,
|
||||
})
|
||||
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, err)
|
||||
}
|
||||
|
||||
func TestRunInvalidGcflags(t *testing.T) {
|
||||
@ -650,7 +651,7 @@ func TestRunInvalidGcflags(t *testing.T) {
|
||||
err := Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||
Target: runtimeTarget,
|
||||
})
|
||||
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, err)
|
||||
}
|
||||
|
||||
func TestRunInvalidLdflags(t *testing.T) {
|
||||
@ -675,7 +676,7 @@ func TestRunInvalidLdflags(t *testing.T) {
|
||||
err := Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||
Target: runtimeTarget,
|
||||
})
|
||||
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, err)
|
||||
}
|
||||
|
||||
func TestRunInvalidFlags(t *testing.T) {
|
||||
@ -698,7 +699,7 @@ func TestRunInvalidFlags(t *testing.T) {
|
||||
err := Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||
Target: runtimeTarget,
|
||||
})
|
||||
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, err)
|
||||
}
|
||||
|
||||
func TestRunPipeWithoutMainFunc(t *testing.T) {
|
||||
@ -903,15 +904,15 @@ func TestLdFlagsFullTemplate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInvalidTemplate(t *testing.T) {
|
||||
for template, eerr := range map[string]string{
|
||||
"{{ .Nope }": `template: tmpl:1: unexpected "}" in operand`,
|
||||
"{{.Env.NOPE}}": `template: tmpl:1:6: executing "tmpl" at <.Env.NOPE>: map has no entry for key "NOPE"`,
|
||||
for _, template := range []string{
|
||||
"{{ .Nope }",
|
||||
"{{.Env.NOPE}}",
|
||||
} {
|
||||
t.Run(template, func(t *testing.T) {
|
||||
ctx := context.New(config.Project{})
|
||||
ctx.Git.CurrentTag = "3.4.1"
|
||||
flags, err := tmpl.New(ctx).Apply(template)
|
||||
require.EqualError(t, err, eerr)
|
||||
testlib.RequireTemplateError(t, err)
|
||||
require.Empty(t, flags)
|
||||
})
|
||||
}
|
||||
@ -966,10 +967,8 @@ func TestProcessFlagsInvalid(t *testing.T) {
|
||||
"{{.Version}",
|
||||
}
|
||||
|
||||
expected := `template: tmpl:1: unexpected "}" in operand`
|
||||
|
||||
flags, err := processFlags(ctx, &artifact.Artifact{}, []string{}, source, "-testflag=")
|
||||
require.EqualError(t, err, expected)
|
||||
testlib.RequireTemplateError(t, err)
|
||||
require.Nil(t, flags)
|
||||
}
|
||||
|
||||
@ -1291,7 +1290,7 @@ func TestOverrides(t *testing.T) {
|
||||
Goarch: runtime.GOARCH,
|
||||
},
|
||||
)
|
||||
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, err)
|
||||
})
|
||||
|
||||
t.Run("with goarm", func(t *testing.T) {
|
||||
|
@ -536,7 +536,7 @@ func TestRunPipeInvalidNameTemplate(t *testing.T) {
|
||||
artifact.ExtraID: "default",
|
||||
},
|
||||
})
|
||||
require.EqualError(t, Pipe{}.Run(ctx), `template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestRunPipeInvalidFilesNameTemplate(t *testing.T) {
|
||||
@ -574,7 +574,7 @@ func TestRunPipeInvalidFilesNameTemplate(t *testing.T) {
|
||||
artifact.ExtraID: "default",
|
||||
},
|
||||
})
|
||||
require.EqualError(t, Pipe{}.Run(ctx), `failed to find files to archive: failed to apply template {{.asdsd}: template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestRunPipeInvalidWrapInDirectoryTemplate(t *testing.T) {
|
||||
|
@ -358,7 +358,7 @@ func TestRunPipe_TargetTemplateError(t *testing.T) {
|
||||
Name: "production",
|
||||
Mode: "binary",
|
||||
// This template is not correct and should fail
|
||||
Target: "http://storage.company.com/example-repo-local/{{ .ProjectName /{{ .Version }}/",
|
||||
Target: "http://storage.company.com/example-repo-local/{{.Name}",
|
||||
Username: "deployuser",
|
||||
},
|
||||
},
|
||||
@ -378,7 +378,7 @@ func TestRunPipe_TargetTemplateError(t *testing.T) {
|
||||
})
|
||||
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.EqualError(t, Pipe{}.Publish(ctx), `artifactory: error while building the target url: template: tmpl:1: unexpected "/" in operand`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Publish(ctx))
|
||||
}
|
||||
|
||||
func TestRunPipe_BadCredentials(t *testing.T) {
|
||||
|
@ -81,13 +81,17 @@ func TestRunPipe(t *testing.T) {
|
||||
t.Helper()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
shouldTemplateErr := func(t *testing.T, err error) {
|
||||
t.Helper()
|
||||
testlib.RequireTemplateError(t, err)
|
||||
}
|
||||
type imageLabelFinder func(*testing.T, string)
|
||||
shouldFindImagesWithLabels := func(image string, filters ...string) func(*testing.T, string) {
|
||||
return func(t *testing.T, use string) {
|
||||
t.Helper()
|
||||
for _, filter := range filters {
|
||||
cmd := exec.Command("docker", "images", "-q", "--filter", "reference=*/"+image, "--filter", filter)
|
||||
t.Log("running", cmd)
|
||||
// t.Log("running", cmd)
|
||||
output, err := cmd.CombinedOutput()
|
||||
require.NoError(t, err, string(output))
|
||||
uniqueIDs := map[string]string{}
|
||||
@ -272,7 +276,7 @@ func TestRunPipe(t *testing.T) {
|
||||
fmt.Sprintf("docker push %sgoreleaser/dummy:v1", registry),
|
||||
fmt.Sprintf("docker manifest create %sgoreleaser/test_multiarch:2test --amend %sgoreleaser/dummy:v1 --insecure", registry, registry),
|
||||
} {
|
||||
t.Log("running", cmd)
|
||||
// t.Log("running", cmd)
|
||||
parts := strings.Fields(cmd)
|
||||
out, err := exec.CommandContext(ctx, parts[0], parts[1:]...).CombinedOutput()
|
||||
require.NoError(t, err, cmd+": "+string(out))
|
||||
@ -319,7 +323,7 @@ func TestRunPipe(t *testing.T) {
|
||||
expect: []string{registry + "goreleaser/test_multiarch_manifest_tmpl_error"},
|
||||
assertError: shouldNotErr,
|
||||
pubAssertError: shouldNotErr,
|
||||
manifestAssertError: shouldErr(`template: tmpl:1: unexpected "}" in operand`),
|
||||
manifestAssertError: shouldTemplateErr,
|
||||
assertImageLabels: noLabels,
|
||||
},
|
||||
"multiarch image template error": {
|
||||
@ -340,7 +344,7 @@ func TestRunPipe(t *testing.T) {
|
||||
expect: []string{registry + "goreleaser/test_multiarch_img_tmpl_error"},
|
||||
assertError: shouldNotErr,
|
||||
pubAssertError: shouldNotErr,
|
||||
manifestAssertError: shouldErr(`template: tmpl:1: unexpected "}" in operand`),
|
||||
manifestAssertError: shouldTemplateErr,
|
||||
assertImageLabels: noLabels,
|
||||
},
|
||||
"multiarch missing manifest name": {
|
||||
@ -478,7 +482,7 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
},
|
||||
expect: []string{},
|
||||
assertError: shouldErr(`template: tmpl:1:7: executing "tmpl" at <.Env.Dockerfile>: map has no entry for key "Dockerfile"`),
|
||||
assertError: shouldTemplateErr,
|
||||
assertImageLabels: noLabels,
|
||||
pubAssertError: shouldNotErr,
|
||||
manifestAssertError: shouldNotErr,
|
||||
@ -771,7 +775,7 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
},
|
||||
assertImageLabels: noLabels,
|
||||
assertError: shouldErr(`template: tmpl:1: unexpected "}" in operand`),
|
||||
assertError: shouldTemplateErr,
|
||||
},
|
||||
"build_flag_template_error": {
|
||||
dockers: []config.Docker{
|
||||
@ -788,7 +792,7 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
},
|
||||
assertImageLabels: noLabels,
|
||||
assertError: shouldErr(`template: tmpl:1: unexpected "}" in operand`),
|
||||
assertError: shouldTemplateErr,
|
||||
},
|
||||
"missing_env_on_tag_template": {
|
||||
dockers: []config.Docker{
|
||||
@ -802,7 +806,7 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
},
|
||||
assertImageLabels: noLabels,
|
||||
assertError: shouldErr(`template: tmpl:1:46: executing "tmpl" at <.Env.NOPE>: map has no entry for key "NOPE"`),
|
||||
assertError: shouldTemplateErr,
|
||||
},
|
||||
"missing_env_on_build_flag_template": {
|
||||
dockers: []config.Docker{
|
||||
@ -819,7 +823,7 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
},
|
||||
assertImageLabels: noLabels,
|
||||
assertError: shouldErr(`template: tmpl:1:19: executing "tmpl" at <.Env.NOPE>: map has no entry for key "NOPE"`),
|
||||
assertError: shouldTemplateErr,
|
||||
},
|
||||
"image_has_projectname_template_variable": {
|
||||
dockers: []config.Docker{
|
||||
@ -1087,7 +1091,7 @@ func TestRunPipe(t *testing.T) {
|
||||
// this might should not fail as the image should have been created when
|
||||
// the step ran
|
||||
for _, img := range docker.expect {
|
||||
t.Log("removing docker image", img)
|
||||
// t.Log("removing docker image", img)
|
||||
require.NoError(t, rmi(img), "could not delete image %s", img)
|
||||
}
|
||||
})
|
||||
|
@ -227,7 +227,7 @@ func requireGoMod(tb testing.TB, module, version string) {
|
||||
require.NoError(tb, err)
|
||||
require.Contains(tb, string(mod), fmt.Sprintf(`module foo
|
||||
|
||||
go 1.18
|
||||
go 1.19
|
||||
|
||||
require %s %s
|
||||
`, module, version))
|
||||
|
@ -429,7 +429,7 @@ func TestInvalidTemplate(t *testing.T) {
|
||||
FileNameTemplate: "{{.Foo}",
|
||||
}
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("source", func(t *testing.T) {
|
||||
@ -442,7 +442,7 @@ func TestInvalidTemplate(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_SOURCE>: map has no entry for key "NOPE_SOURCE"`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("target", func(t *testing.T) {
|
||||
@ -455,49 +455,49 @@ func TestInvalidTemplate(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_TARGET>: map has no entry for key "NOPE_TARGET"`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("description", func(t *testing.T) {
|
||||
ctx := makeCtx()
|
||||
ctx.Config.NFPMs[0].Description = "{{ .NOPE_DESC }}"
|
||||
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_DESC>: map has no entry for key "NOPE_DESC"`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("maintainer", func(t *testing.T) {
|
||||
ctx := makeCtx()
|
||||
ctx.Config.NFPMs[0].Maintainer = "{{ .NOPE_DESC }}"
|
||||
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_DESC>: map has no entry for key "NOPE_DESC"`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("homepage", func(t *testing.T) {
|
||||
ctx := makeCtx()
|
||||
ctx.Config.NFPMs[0].Homepage = "{{ .NOPE_HOMEPAGE }}"
|
||||
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_HOMEPAGE>: map has no entry for key "NOPE_HOMEPAGE"`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("deb key file", func(t *testing.T) {
|
||||
ctx := makeCtx()
|
||||
ctx.Config.NFPMs[0].Deb.Signature.KeyFile = "{{ .NOPE_KEY_FILE }}"
|
||||
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_KEY_FILE>: map has no entry for key "NOPE_KEY_FILE"`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("rpm key file", func(t *testing.T) {
|
||||
ctx := makeCtx()
|
||||
ctx.Config.NFPMs[0].RPM.Signature.KeyFile = "{{ .NOPE_KEY_FILE }}"
|
||||
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_KEY_FILE>: map has no entry for key "NOPE_KEY_FILE"`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("apk key file", func(t *testing.T) {
|
||||
ctx := makeCtx()
|
||||
ctx.Config.NFPMs[0].APK.Signature.KeyFile = "{{ .NOPE_KEY_FILE }}"
|
||||
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_KEY_FILE>: map has no entry for key "NOPE_KEY_FILE"`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("bindir", func(t *testing.T) {
|
||||
ctx := makeCtx()
|
||||
ctx.Config.NFPMs[0].Bindir = "/usr/{{ .NOPE }}"
|
||||
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:8: executing "tmpl" at <.NOPE>: map has no entry for key "NOPE"`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
@ -532,7 +532,7 @@ func TestRunPipeInvalidContentsSourceTemplate(t *testing.T) {
|
||||
artifact.ExtraID: "default",
|
||||
},
|
||||
})
|
||||
require.EqualError(t, Pipe{}.Run(ctx), `template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestNoBuildsFound(t *testing.T) {
|
||||
|
@ -142,7 +142,7 @@ func TestRunPipeInvalidNameTemplate(t *testing.T) {
|
||||
ctx.Git.CurrentTag = "v1.2.3"
|
||||
ctx.Version = "1.2.3"
|
||||
addBinaries(t, ctx, "foo", dist)
|
||||
require.EqualError(t, Pipe{}.Run(ctx), `template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestRunPipeWithName(t *testing.T) {
|
||||
|
@ -3,6 +3,7 @@ package snapshot
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -40,7 +41,7 @@ func TestSnapshotInvalidNametemplate(t *testing.T) {
|
||||
NameTemplate: "{{.ShortCommit}{{{sss}}}",
|
||||
},
|
||||
})
|
||||
require.EqualError(t, Pipe{}.Run(ctx), `failed to generate snapshot name: template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestSnapshotEmptyFinalName(t *testing.T) {
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -267,13 +268,13 @@ func TestRun(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("bad template", func(t *testing.T) {
|
||||
require.EqualError(t, Pipe{}.Run(context.New(config.Project{
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(context.New(config.Project{
|
||||
UniversalBinaries: []config.UniversalBinary{
|
||||
{
|
||||
NameTemplate: "{{.Name}",
|
||||
},
|
||||
},
|
||||
})), `template: tmpl:1: unexpected "}" in operand`)
|
||||
})))
|
||||
})
|
||||
|
||||
t.Run("no darwin builds", func(t *testing.T) {
|
||||
@ -326,7 +327,7 @@ func TestRun(t *testing.T) {
|
||||
Env: []string{"FOO=foo-{{.Tag}"},
|
||||
}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{}
|
||||
require.EqualError(t, Pipe{}.Run(ctx), `pre hook failed: template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("hook with bad dir tmpl", func(t *testing.T) {
|
||||
@ -336,7 +337,7 @@ func TestRun(t *testing.T) {
|
||||
Dir: "{{.Tag}",
|
||||
}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{}
|
||||
require.EqualError(t, Pipe{}.Run(ctx), `pre hook failed: template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("hook with bad cmd tmpl", func(t *testing.T) {
|
||||
@ -345,7 +346,7 @@ func TestRun(t *testing.T) {
|
||||
Cmd: "echo blah-{{.Tag }",
|
||||
}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{}
|
||||
require.EqualError(t, Pipe{}.Run(ctx), `pre hook failed: template: tmpl:1: unexpected "}" in operand`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -396,7 +397,7 @@ func TestRunPipe_TargetTemplateError(t *testing.T) {
|
||||
Name: "production",
|
||||
Mode: "binary",
|
||||
// This template is not correct and should fail
|
||||
Target: "http://storage.company.com/example-repo-local/{{ .ProjectName /{{ .Version }}/",
|
||||
Target: "http://storage.company.com/example-repo-local/{{ .ProjectName}",
|
||||
Username: "deployuser",
|
||||
},
|
||||
},
|
||||
@ -414,9 +415,7 @@ func TestRunPipe_TargetTemplateError(t *testing.T) {
|
||||
Goos: "darwin",
|
||||
Type: artifact.UploadableBinary,
|
||||
})
|
||||
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`)
|
||||
testlib.RequireTemplateError(t, Pipe{}.Publish(ctx))
|
||||
}
|
||||
|
||||
func TestRunPipe_BadCredentials(t *testing.T) {
|
||||
|
16
internal/testlib/tmpl.go
Normal file
16
internal/testlib/tmpl.go
Normal file
@ -0,0 +1,16 @@
|
||||
package testlib
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// RequireTemplateError requires thqt an error happens and that it is an template error.
|
||||
func RequireTemplateError(tb testing.TB, err error) {
|
||||
tb.Helper()
|
||||
|
||||
require.Error(tb, err)
|
||||
require.Contains(tb, err.Error(), "template:")
|
||||
require.Regexp(tb, "bad character|map has no entry|unexpected \"}\" in operand", err.Error())
|
||||
}
|
@ -42,7 +42,7 @@ jobs:
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.18
|
||||
go-version: 1.19
|
||||
-
|
||||
name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
|
@ -69,7 +69,7 @@ trigger:
|
||||
- refs/tags/*
|
||||
|
||||
variables:
|
||||
GO_VERSION: "1.18"
|
||||
GO_VERSION: "1.19"
|
||||
|
||||
pool:
|
||||
vmImage: ubuntu-latest
|
||||
|
@ -18,7 +18,7 @@ workflows:
|
||||
jobs:
|
||||
release:
|
||||
docker:
|
||||
- image: cimg/go:1.18
|
||||
- image: cimg/go:1.19
|
||||
steps:
|
||||
- checkout
|
||||
- run: curl -sfL https://goreleaser.com/static/run | bash
|
||||
|
@ -23,7 +23,7 @@ steps:
|
||||
BuildMyApp:
|
||||
title: Compiling go code
|
||||
stage: build
|
||||
image: 'golang:1.18'
|
||||
image: 'golang:1.19'
|
||||
commands:
|
||||
- go build
|
||||
ReleaseMyApp:
|
||||
|
Loading…
x
Reference in New Issue
Block a user