You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-03 00:57:43 +02:00
refactor: use require on all tests (#1839)
* refactor: use require on all tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * refactor: use require on all tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
2c487bc478
commit
979f8632b7
@ -6,7 +6,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
@ -41,8 +40,8 @@ func TestAdd(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
assert.NoError(t, g.Wait())
|
require.NoError(t, g.Wait())
|
||||||
assert.Len(t, artifacts.List(), 4)
|
require.Len(t, artifacts.List(), 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilter(t *testing.T) {
|
func TestFilter(t *testing.T) {
|
||||||
@ -74,21 +73,21 @@ func TestFilter(t *testing.T) {
|
|||||||
artifacts.Add(a)
|
artifacts.Add(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Len(t, artifacts.Filter(ByGoos("linux")).items, 1)
|
require.Len(t, artifacts.Filter(ByGoos("linux")).items, 1)
|
||||||
assert.Len(t, artifacts.Filter(ByGoos("darwin")).items, 0)
|
require.Len(t, artifacts.Filter(ByGoos("darwin")).items, 0)
|
||||||
|
|
||||||
assert.Len(t, artifacts.Filter(ByGoarch("amd64")).items, 1)
|
require.Len(t, artifacts.Filter(ByGoarch("amd64")).items, 1)
|
||||||
assert.Len(t, artifacts.Filter(ByGoarch("386")).items, 0)
|
require.Len(t, artifacts.Filter(ByGoarch("386")).items, 0)
|
||||||
|
|
||||||
assert.Len(t, artifacts.Filter(ByGoarm("6")).items, 1)
|
require.Len(t, artifacts.Filter(ByGoarm("6")).items, 1)
|
||||||
assert.Len(t, artifacts.Filter(ByGoarm("7")).items, 0)
|
require.Len(t, artifacts.Filter(ByGoarm("7")).items, 0)
|
||||||
|
|
||||||
assert.Len(t, artifacts.Filter(ByType(Checksum)).items, 2)
|
require.Len(t, artifacts.Filter(ByType(Checksum)).items, 2)
|
||||||
assert.Len(t, artifacts.Filter(ByType(Binary)).items, 0)
|
require.Len(t, artifacts.Filter(ByType(Binary)).items, 0)
|
||||||
|
|
||||||
assert.Len(t, artifacts.Filter(nil).items, 5)
|
require.Len(t, artifacts.Filter(nil).items, 5)
|
||||||
|
|
||||||
assert.Len(t, artifacts.Filter(
|
require.Len(t, artifacts.Filter(
|
||||||
And(
|
And(
|
||||||
ByType(Checksum),
|
ByType(Checksum),
|
||||||
func(a *Artifact) bool {
|
func(a *Artifact) bool {
|
||||||
@ -97,7 +96,7 @@ func TestFilter(t *testing.T) {
|
|||||||
),
|
),
|
||||||
).List(), 1)
|
).List(), 1)
|
||||||
|
|
||||||
assert.Len(t, artifacts.Filter(
|
require.Len(t, artifacts.Filter(
|
||||||
Or(
|
Or(
|
||||||
ByType(Checksum),
|
ByType(Checksum),
|
||||||
And(
|
And(
|
||||||
@ -149,10 +148,10 @@ func TestGroupByPlatform(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var groups = artifacts.GroupByPlatform()
|
var groups = artifacts.GroupByPlatform()
|
||||||
assert.Len(t, groups["linuxamd64"], 2)
|
require.Len(t, groups["linuxamd64"], 2)
|
||||||
assert.Len(t, groups["linuxarm6"], 1)
|
require.Len(t, groups["linuxarm6"], 1)
|
||||||
assert.Len(t, groups["linuxmipssoftfloat"], 1)
|
require.Len(t, groups["linuxmipssoftfloat"], 1)
|
||||||
assert.Len(t, groups["linuxmipshardfloat"], 1)
|
require.Len(t, groups["linuxmipshardfloat"], 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChecksum(t *testing.T) {
|
func TestChecksum(t *testing.T) {
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
api "github.com/goreleaser/goreleaser/pkg/build"
|
api "github.com/goreleaser/goreleaser/pkg/build"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -96,8 +95,8 @@ func TestWithDefaults(t *testing.T) {
|
|||||||
var ctx = context.New(config)
|
var ctx = context.New(config)
|
||||||
ctx.Git.CurrentTag = "5.6.7"
|
ctx.Git.CurrentTag = "5.6.7"
|
||||||
var build = Default.WithDefaults(ctx.Config.Builds[0])
|
var build = Default.WithDefaults(ctx.Config.Builds[0])
|
||||||
assert.ElementsMatch(t, build.Targets, testcase.targets)
|
require.ElementsMatch(t, build.Targets, testcase.targets)
|
||||||
assert.EqualValues(t, testcase.goBinary, build.GoBinary)
|
require.EqualValues(t, testcase.goBinary, build.GoBinary)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,9 +151,9 @@ func TestBuild(t *testing.T) {
|
|||||||
Path: filepath.Join(folder, "dist", target, bin+ext),
|
Path: filepath.Join(folder, "dist", target, bin+ext),
|
||||||
Ext: ext,
|
Ext: ext,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
assert.ElementsMatch(t, ctx.Artifacts.List(), []*artifact.Artifact{
|
require.ElementsMatch(t, ctx.Artifacts.List(), []*artifact.Artifact{
|
||||||
{
|
{
|
||||||
Name: "bin/foo-v5.6.7",
|
Name: "bin/foo-v5.6.7",
|
||||||
Path: filepath.Join(folder, "dist", "linux_amd64", "bin", "foo-v5.6.7"),
|
Path: filepath.Join(folder, "dist", "linux_amd64", "bin", "foo-v5.6.7"),
|
||||||
@ -251,7 +250,7 @@ func TestBuild(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fi, err := os.Stat(bin.Path)
|
fi, err := os.Stat(bin.Path)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// make this a suitable map key, per docs: https://golang.org/pkg/time/#Time
|
// make this a suitable map key, per docs: https://golang.org/pkg/time/#Time
|
||||||
modTime := fi.ModTime().UTC().Round(0)
|
modTime := fi.ModTime().UTC().Round(0)
|
||||||
@ -268,7 +267,7 @@ func TestBuildCodeInSubdir(t *testing.T) {
|
|||||||
defer back()
|
defer back()
|
||||||
subdir := filepath.Join(folder, "bar")
|
subdir := filepath.Join(folder, "bar")
|
||||||
err := os.Mkdir(subdir, 0755)
|
err := os.Mkdir(subdir, 0755)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
writeGoodMain(t, subdir)
|
writeGoodMain(t, subdir)
|
||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
Builds: []config.Build{
|
Builds: []config.Build{
|
||||||
@ -293,7 +292,7 @@ func TestBuildCodeInSubdir(t *testing.T) {
|
|||||||
Path: filepath.Join(folder, "dist", runtimeTarget, build.Binary),
|
Path: filepath.Join(folder, "dist", runtimeTarget, build.Binary),
|
||||||
Ext: "",
|
Ext: "",
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildFailed(t *testing.T) {
|
func TestBuildFailed(t *testing.T) {
|
||||||
@ -318,7 +317,7 @@ func TestBuildFailed(t *testing.T) {
|
|||||||
Target: "darwin_amd64",
|
Target: "darwin_amd64",
|
||||||
})
|
})
|
||||||
assertContainsError(t, err, `flag provided but not defined: -flag-that-dont-exists-to-force-failure`)
|
assertContainsError(t, err, `flag provided but not defined: -flag-that-dont-exists-to-force-failure`)
|
||||||
assert.Empty(t, ctx.Artifacts.List())
|
require.Empty(t, ctx.Artifacts.List())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildInvalidTarget(t *testing.T) {
|
func TestBuildInvalidTarget(t *testing.T) {
|
||||||
@ -343,8 +342,8 @@ func TestBuildInvalidTarget(t *testing.T) {
|
|||||||
Name: build.Binary,
|
Name: build.Binary,
|
||||||
Path: filepath.Join(folder, "dist", target, build.Binary),
|
Path: filepath.Join(folder, "dist", target, build.Binary),
|
||||||
})
|
})
|
||||||
assert.EqualError(t, err, "linux is not a valid build target")
|
require.EqualError(t, err, "linux is not a valid build target")
|
||||||
assert.Len(t, ctx.Artifacts.List(), 0)
|
require.Len(t, ctx.Artifacts.List(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunInvalidAsmflags(t *testing.T) {
|
func TestRunInvalidAsmflags(t *testing.T) {
|
||||||
@ -367,7 +366,7 @@ func TestRunInvalidAsmflags(t *testing.T) {
|
|||||||
var err = Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
var err = Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||||
Target: runtimeTarget,
|
Target: runtimeTarget,
|
||||||
})
|
})
|
||||||
assert.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunInvalidGcflags(t *testing.T) {
|
func TestRunInvalidGcflags(t *testing.T) {
|
||||||
@ -390,7 +389,7 @@ func TestRunInvalidGcflags(t *testing.T) {
|
|||||||
var err = Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
var err = Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||||
Target: runtimeTarget,
|
Target: runtimeTarget,
|
||||||
})
|
})
|
||||||
assert.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunInvalidLdflags(t *testing.T) {
|
func TestRunInvalidLdflags(t *testing.T) {
|
||||||
@ -414,7 +413,7 @@ func TestRunInvalidLdflags(t *testing.T) {
|
|||||||
var err = Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
var err = Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||||
Target: runtimeTarget,
|
Target: runtimeTarget,
|
||||||
})
|
})
|
||||||
assert.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunInvalidFlags(t *testing.T) {
|
func TestRunInvalidFlags(t *testing.T) {
|
||||||
@ -436,7 +435,7 @@ func TestRunInvalidFlags(t *testing.T) {
|
|||||||
var err = Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
var err = Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||||
Target: runtimeTarget,
|
Target: runtimeTarget,
|
||||||
})
|
})
|
||||||
assert.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeWithoutMainFunc(t *testing.T) {
|
func TestRunPipeWithoutMainFunc(t *testing.T) {
|
||||||
@ -458,25 +457,25 @@ func TestRunPipeWithoutMainFunc(t *testing.T) {
|
|||||||
ctx.Git.CurrentTag = "5.6.7"
|
ctx.Git.CurrentTag = "5.6.7"
|
||||||
t.Run("empty", func(t *testing.T) {
|
t.Run("empty", func(t *testing.T) {
|
||||||
ctx.Config.Builds[0].Main = ""
|
ctx.Config.Builds[0].Main = ""
|
||||||
assert.EqualError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
require.EqualError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||||
Target: runtimeTarget,
|
Target: runtimeTarget,
|
||||||
}), `build for no-main does not contain a main function`)
|
}), `build for no-main does not contain a main function`)
|
||||||
})
|
})
|
||||||
t.Run("not main.go", func(t *testing.T) {
|
t.Run("not main.go", func(t *testing.T) {
|
||||||
ctx.Config.Builds[0].Main = "foo.go"
|
ctx.Config.Builds[0].Main = "foo.go"
|
||||||
assert.EqualError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
require.EqualError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||||
Target: runtimeTarget,
|
Target: runtimeTarget,
|
||||||
}), `stat foo.go: no such file or directory`)
|
}), `stat foo.go: no such file or directory`)
|
||||||
})
|
})
|
||||||
t.Run("glob", func(t *testing.T) {
|
t.Run("glob", func(t *testing.T) {
|
||||||
ctx.Config.Builds[0].Main = "."
|
ctx.Config.Builds[0].Main = "."
|
||||||
assert.EqualError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
require.EqualError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||||
Target: runtimeTarget,
|
Target: runtimeTarget,
|
||||||
}), `build for no-main does not contain a main function`)
|
}), `build for no-main does not contain a main function`)
|
||||||
})
|
})
|
||||||
t.Run("fixed main.go", func(t *testing.T) {
|
t.Run("fixed main.go", func(t *testing.T) {
|
||||||
ctx.Config.Builds[0].Main = "main.go"
|
ctx.Config.Builds[0].Main = "main.go"
|
||||||
assert.EqualError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
require.EqualError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||||
Target: runtimeTarget,
|
Target: runtimeTarget,
|
||||||
}), `build for no-main does not contain a main function`)
|
}), `build for no-main does not contain a main function`)
|
||||||
})
|
})
|
||||||
@ -485,7 +484,7 @@ func TestRunPipeWithoutMainFunc(t *testing.T) {
|
|||||||
func TestRunPipeWithMainFuncNotInMainGoFile(t *testing.T) {
|
func TestRunPipeWithMainFuncNotInMainGoFile(t *testing.T) {
|
||||||
folder, back := testlib.Mktmp(t)
|
folder, back := testlib.Mktmp(t)
|
||||||
defer back()
|
defer back()
|
||||||
assert.NoError(t, ioutil.WriteFile(
|
require.NoError(t, ioutil.WriteFile(
|
||||||
filepath.Join(folder, "foo.go"),
|
filepath.Join(folder, "foo.go"),
|
||||||
[]byte("package main\nfunc main() {println(0)}"),
|
[]byte("package main\nfunc main() {println(0)}"),
|
||||||
0644,
|
0644,
|
||||||
@ -507,19 +506,19 @@ func TestRunPipeWithMainFuncNotInMainGoFile(t *testing.T) {
|
|||||||
ctx.Git.CurrentTag = "5.6.7"
|
ctx.Git.CurrentTag = "5.6.7"
|
||||||
t.Run("empty", func(t *testing.T) {
|
t.Run("empty", func(t *testing.T) {
|
||||||
ctx.Config.Builds[0].Main = ""
|
ctx.Config.Builds[0].Main = ""
|
||||||
assert.NoError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
require.NoError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||||
Target: runtimeTarget,
|
Target: runtimeTarget,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
t.Run("foo.go", func(t *testing.T) {
|
t.Run("foo.go", func(t *testing.T) {
|
||||||
ctx.Config.Builds[0].Main = "foo.go"
|
ctx.Config.Builds[0].Main = "foo.go"
|
||||||
assert.NoError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
require.NoError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||||
Target: runtimeTarget,
|
Target: runtimeTarget,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
t.Run("glob", func(t *testing.T) {
|
t.Run("glob", func(t *testing.T) {
|
||||||
ctx.Config.Builds[0].Main = "."
|
ctx.Config.Builds[0].Main = "."
|
||||||
assert.NoError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
require.NoError(t, Default.Build(ctx, ctx.Config.Builds[0], api.Options{
|
||||||
Target: runtimeTarget,
|
Target: runtimeTarget,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
@ -542,16 +541,16 @@ func TestLdFlagsFullTemplate(t *testing.T) {
|
|||||||
var artifact = &artifact.Artifact{Goarch: "amd64"}
|
var artifact = &artifact.Artifact{Goarch: "amd64"}
|
||||||
flags, err := tmpl.New(ctx).WithArtifact(artifact, map[string]string{}).
|
flags, err := tmpl.New(ctx).WithArtifact(artifact, map[string]string{}).
|
||||||
Apply(`-s -w -X main.version={{.Version}} -X main.tag={{.Tag}} -X main.date={{.Date}} -X main.commit={{.Commit}} -X "main.foo={{.Env.FOO}}" -X main.time={{ time "20060102" }} -X main.arch={{.Arch}} -X main.commitDate={{.CommitDate}}`)
|
Apply(`-s -w -X main.version={{.Version}} -X main.tag={{.Tag}} -X main.date={{.Date}} -X main.commit={{.Commit}} -X "main.foo={{.Env.FOO}}" -X main.time={{ time "20060102" }} -X main.arch={{.Arch}} -X main.commitDate={{.CommitDate}}`)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Contains(t, flags, "-s -w")
|
require.Contains(t, flags, "-s -w")
|
||||||
assert.Contains(t, flags, "-X main.version=1.2.3")
|
require.Contains(t, flags, "-X main.version=1.2.3")
|
||||||
assert.Contains(t, flags, "-X main.tag=v1.2.3")
|
require.Contains(t, flags, "-X main.tag=v1.2.3")
|
||||||
assert.Contains(t, flags, "-X main.commit=123")
|
require.Contains(t, flags, "-X main.commit=123")
|
||||||
assert.Contains(t, flags, fmt.Sprintf("-X main.date=%d", run.Year()))
|
require.Contains(t, flags, fmt.Sprintf("-X main.date=%d", run.Year()))
|
||||||
assert.Contains(t, flags, fmt.Sprintf("-X main.time=%d", run.Year()))
|
require.Contains(t, flags, fmt.Sprintf("-X main.time=%d", run.Year()))
|
||||||
assert.Contains(t, flags, `-X "main.foo=123"`)
|
require.Contains(t, flags, `-X "main.foo=123"`)
|
||||||
assert.Contains(t, flags, `-X main.arch=amd64`)
|
require.Contains(t, flags, `-X main.arch=amd64`)
|
||||||
assert.Contains(t, flags, fmt.Sprintf("-X main.commitDate=%d", commit.Year()))
|
require.Contains(t, flags, fmt.Sprintf("-X main.commitDate=%d", commit.Year()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidTemplate(t *testing.T) {
|
func TestInvalidTemplate(t *testing.T) {
|
||||||
@ -563,8 +562,8 @@ func TestInvalidTemplate(t *testing.T) {
|
|||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
ctx.Git.CurrentTag = "3.4.1"
|
ctx.Git.CurrentTag = "3.4.1"
|
||||||
flags, err := tmpl.New(ctx).Apply(template)
|
flags, err := tmpl.New(ctx).Apply(template)
|
||||||
assert.EqualError(tt, err, eerr)
|
require.EqualError(tt, err, eerr)
|
||||||
assert.Empty(tt, flags)
|
require.Empty(tt, flags)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -606,9 +605,9 @@ func TestProcessFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags, err := processFlags(ctx, artifact, []string{}, source, "-testflag=")
|
flags, err := processFlags(ctx, artifact, []string{}, source, "-testflag=")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, flags, 7)
|
require.Len(t, flags, 7)
|
||||||
assert.Equal(t, expected, flags)
|
require.Equal(t, expected, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProcessFlagsInvalid(t *testing.T) {
|
func TestProcessFlagsInvalid(t *testing.T) {
|
||||||
@ -621,8 +620,8 @@ func TestProcessFlagsInvalid(t *testing.T) {
|
|||||||
var expected = `template: tmpl:1: unexpected "}" in operand`
|
var expected = `template: tmpl:1: unexpected "}" in operand`
|
||||||
|
|
||||||
flags, err := processFlags(ctx, &artifact.Artifact{}, []string{}, source, "-testflag=")
|
flags, err := processFlags(ctx, &artifact.Artifact{}, []string{}, source, "-testflag=")
|
||||||
assert.EqualError(t, err, expected)
|
require.EqualError(t, err, expected)
|
||||||
assert.Nil(t, flags)
|
require.Nil(t, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJoinLdFlags(t *testing.T) {
|
func TestJoinLdFlags(t *testing.T) {
|
||||||
@ -636,7 +635,7 @@ func TestJoinLdFlags(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
joinedLdFlags := joinLdFlags(test.input)
|
joinedLdFlags := joinLdFlags(test.input)
|
||||||
assert.Equal(t, joinedLdFlags, test.output)
|
require.Equal(t, joinedLdFlags, test.output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -695,7 +694,7 @@ func TestBuildModTimestamp(t *testing.T) {
|
|||||||
Path: filepath.Join(folder, "dist", target, bin+ext),
|
Path: filepath.Join(folder, "dist", target, bin+ext),
|
||||||
Ext: ext,
|
Ext: ext,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, bin := range ctx.Artifacts.List() {
|
for _, bin := range ctx.Artifacts.List() {
|
||||||
@ -704,8 +703,8 @@ func TestBuildModTimestamp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fi, err := os.Stat(bin.Path)
|
fi, err := os.Stat(bin.Path)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.True(t, modTime.Equal(fi.ModTime()), "inconsistent mod times found when specifying ModTimestamp")
|
require.True(t, modTime.Equal(fi.ModTime()), "inconsistent mod times found when specifying ModTimestamp")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -714,7 +713,7 @@ func TestBuildModTimestamp(t *testing.T) {
|
|||||||
//
|
//
|
||||||
|
|
||||||
func writeMainWithoutMainFunc(t *testing.T, folder string) {
|
func writeMainWithoutMainFunc(t *testing.T, folder string) {
|
||||||
assert.NoError(t, ioutil.WriteFile(
|
require.NoError(t, ioutil.WriteFile(
|
||||||
filepath.Join(folder, "main.go"),
|
filepath.Join(folder, "main.go"),
|
||||||
[]byte("package main\nconst a = 2\nfunc notMain() {println(0)}"),
|
[]byte("package main\nconst a = 2\nfunc notMain() {println(0)}"),
|
||||||
0644,
|
0644,
|
||||||
@ -722,7 +721,7 @@ func writeMainWithoutMainFunc(t *testing.T, folder string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeGoodMain(t *testing.T, folder string) {
|
func writeGoodMain(t *testing.T, folder string) {
|
||||||
assert.NoError(t, ioutil.WriteFile(
|
require.NoError(t, ioutil.WriteFile(
|
||||||
filepath.Join(folder, "main.go"),
|
filepath.Join(folder, "main.go"),
|
||||||
[]byte("package main\nvar a = 1\nfunc main() {println(0)}"),
|
[]byte("package main\nvar a = 1\nfunc main() {println(0)}"),
|
||||||
0644,
|
0644,
|
||||||
@ -730,6 +729,6 @@ func writeGoodMain(t *testing.T, folder string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func assertContainsError(t *testing.T, err error, s string) {
|
func assertContainsError(t *testing.T, err error, s string) {
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), s)
|
require.Contains(t, err.Error(), s)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAllBuildTargets(t *testing.T) {
|
func TestAllBuildTargets(t *testing.T) {
|
||||||
@ -53,7 +53,7 @@ func TestAllBuildTargets(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.Equal(t, []string{
|
require.Equal(t, []string{
|
||||||
"linux_386",
|
"linux_386",
|
||||||
"linux_amd64",
|
"linux_amd64",
|
||||||
"linux_arm_6",
|
"linux_arm_6",
|
||||||
@ -128,7 +128,7 @@ func TestGoosGoarchCombos(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, p := range platforms {
|
for _, p := range platforms {
|
||||||
t.Run(fmt.Sprintf("%v %v valid=%v", p.os, p.arch, p.valid), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%v %v valid=%v", p.os, p.arch, p.valid), func(t *testing.T) {
|
||||||
assert.Equal(t, p.valid, valid(target{p.os, p.arch, "", ""}))
|
require.Equal(t, p.valid, valid(target{p.os, p.arch, "", ""}))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,14 @@ import (
|
|||||||
|
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClientEmpty(t *testing.T) {
|
func TestClientEmpty(t *testing.T) {
|
||||||
ctx := &context.Context{}
|
ctx := &context.Context{}
|
||||||
client, err := New(ctx)
|
client, err := New(ctx)
|
||||||
assert.Nil(t, client)
|
require.Nil(t, client)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClientNewGitea(t *testing.T) {
|
func TestClientNewGitea(t *testing.T) {
|
||||||
@ -26,9 +26,9 @@ func TestClientNewGitea(t *testing.T) {
|
|||||||
Token: "giteatoken",
|
Token: "giteatoken",
|
||||||
}
|
}
|
||||||
client, err := New(ctx)
|
client, err := New(ctx)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, ok := client.(*giteaClient)
|
_, ok := client.(*giteaClient)
|
||||||
assert.True(t, ok)
|
require.True(t, ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClientNewGiteaInvalidURL(t *testing.T) {
|
func TestClientNewGiteaInvalidURL(t *testing.T) {
|
||||||
@ -42,8 +42,8 @@ func TestClientNewGiteaInvalidURL(t *testing.T) {
|
|||||||
Token: "giteatoken",
|
Token: "giteatoken",
|
||||||
}
|
}
|
||||||
client, err := New(ctx)
|
client, err := New(ctx)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Nil(t, client)
|
require.Nil(t, client)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClientNewGitLab(t *testing.T) {
|
func TestClientNewGitLab(t *testing.T) {
|
||||||
@ -52,7 +52,7 @@ func TestClientNewGitLab(t *testing.T) {
|
|||||||
Token: "gitlabtoken",
|
Token: "gitlabtoken",
|
||||||
}
|
}
|
||||||
client, err := New(ctx)
|
client, err := New(ctx)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, ok := client.(*gitlabClient)
|
_, ok := client.(*gitlabClient)
|
||||||
assert.True(t, ok)
|
require.True(t, ok)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
@ -25,31 +24,31 @@ func (s *GetInstanceURLSuite) TestWithScheme() {
|
|||||||
t := s.T()
|
t := s.T()
|
||||||
rootURL := "https://git.dtluna.net"
|
rootURL := "https://git.dtluna.net"
|
||||||
result, err := getInstanceURL(rootURL + "/api/v1")
|
result, err := getInstanceURL(rootURL + "/api/v1")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, rootURL, result)
|
require.Equal(t, rootURL, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GetInstanceURLSuite) TestParseError() {
|
func (s *GetInstanceURLSuite) TestParseError() {
|
||||||
t := s.T()
|
t := s.T()
|
||||||
host := "://.dtluna.net"
|
host := "://.dtluna.net"
|
||||||
result, err := getInstanceURL(host)
|
result, err := getInstanceURL(host)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Empty(t, result)
|
require.Empty(t, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GetInstanceURLSuite) TestNoScheme() {
|
func (s *GetInstanceURLSuite) TestNoScheme() {
|
||||||
t := s.T()
|
t := s.T()
|
||||||
host := "git.dtluna.net"
|
host := "git.dtluna.net"
|
||||||
result, err := getInstanceURL(host)
|
result, err := getInstanceURL(host)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Empty(t, result)
|
require.Empty(t, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GetInstanceURLSuite) TestEmpty() {
|
func (s *GetInstanceURLSuite) TestEmpty() {
|
||||||
t := s.T()
|
t := s.T()
|
||||||
result, err := getInstanceURL("")
|
result, err := getInstanceURL("")
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Empty(t, result)
|
require.Empty(t, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetInstanceURLSuite(t *testing.T) {
|
func TestGetInstanceURLSuite(t *testing.T) {
|
||||||
@ -122,7 +121,7 @@ func (s *GiteaReleasesTestSuite) SetupTest() {
|
|||||||
s.releaseURL = fmt.Sprintf("%v/%v", s.releasesURL, s.releaseID)
|
s.releaseURL = fmt.Sprintf("%v/%v", s.releasesURL, s.releaseID)
|
||||||
httpmock.RegisterResponder("GET", fmt.Sprintf("%s/api/v1/version", s.url), httpmock.NewStringResponder(200, "{\"version\":\"1.12.0\"}"))
|
httpmock.RegisterResponder("GET", fmt.Sprintf("%s/api/v1/version", s.url), httpmock.NewStringResponder(200, "{\"version\":\"1.12.0\"}"))
|
||||||
newClient, err := gitea.NewClient(s.url)
|
newClient, err := gitea.NewClient(s.url)
|
||||||
assert.NoError(s.T(), err)
|
require.NoError(s.T(), err)
|
||||||
s.client = &giteaClient{client: newClient}
|
s.client = &giteaClient{client: newClient}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,8 +138,8 @@ func (s *GetExistingReleaseSuite) TestNoReleases() {
|
|||||||
httpmock.RegisterResponder("GET", s.releasesURL, httpmock.NewStringResponder(200, "[]"))
|
httpmock.RegisterResponder("GET", s.releasesURL, httpmock.NewStringResponder(200, "[]"))
|
||||||
|
|
||||||
release, err := s.client.getExistingRelease(s.owner, s.repoName, s.tag)
|
release, err := s.client.getExistingRelease(s.owner, s.repoName, s.tag)
|
||||||
assert.Nil(t, release)
|
require.Nil(t, release)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GetExistingReleaseSuite) TestNoRepo() {
|
func (s *GetExistingReleaseSuite) TestNoRepo() {
|
||||||
@ -148,8 +147,8 @@ func (s *GetExistingReleaseSuite) TestNoRepo() {
|
|||||||
httpmock.RegisterResponder("GET", s.releasesURL, httpmock.NewStringResponder(404, ""))
|
httpmock.RegisterResponder("GET", s.releasesURL, httpmock.NewStringResponder(404, ""))
|
||||||
|
|
||||||
release, err := s.client.getExistingRelease(s.owner, s.repoName, s.tag)
|
release, err := s.client.getExistingRelease(s.owner, s.repoName, s.tag)
|
||||||
assert.Nil(t, release)
|
require.Nil(t, release)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GetExistingReleaseSuite) TestReleaseExists() {
|
func (s *GetExistingReleaseSuite) TestReleaseExists() {
|
||||||
@ -160,9 +159,9 @@ func (s *GetExistingReleaseSuite) TestReleaseExists() {
|
|||||||
httpmock.RegisterResponder("GET", s.releasesURL, resp)
|
httpmock.RegisterResponder("GET", s.releasesURL, resp)
|
||||||
|
|
||||||
result, err := s.client.getExistingRelease(s.owner, s.repoName, s.tag)
|
result, err := s.client.getExistingRelease(s.owner, s.repoName, s.tag)
|
||||||
assert.NotNil(t, result)
|
require.NotNil(t, result)
|
||||||
assert.Equal(t, *result, release)
|
require.Equal(t, *result, release)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,9 +187,9 @@ func (s *GiteacreateReleaseSuite) TestSuccess() {
|
|||||||
httpmock.RegisterResponder("POST", s.releasesURL, resp)
|
httpmock.RegisterResponder("POST", s.releasesURL, resp)
|
||||||
|
|
||||||
release, err := s.client.createRelease(s.ctx, s.title, s.description)
|
release, err := s.client.createRelease(s.ctx, s.title, s.description)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, release)
|
require.NotNil(t, release)
|
||||||
assert.Equal(t, expectedRelease, *release)
|
require.Equal(t, expectedRelease, *release)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GiteacreateReleaseSuite) TestError() {
|
func (s *GiteacreateReleaseSuite) TestError() {
|
||||||
@ -198,8 +197,8 @@ func (s *GiteacreateReleaseSuite) TestError() {
|
|||||||
httpmock.RegisterResponder("POST", s.releasesURL, httpmock.NewStringResponder(400, ""))
|
httpmock.RegisterResponder("POST", s.releasesURL, httpmock.NewStringResponder(400, ""))
|
||||||
|
|
||||||
release, err := s.client.createRelease(s.ctx, s.title, s.description)
|
release, err := s.client.createRelease(s.ctx, s.title, s.description)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Nil(t, release)
|
require.Nil(t, release)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGiteacreateReleaseSuite(t *testing.T) {
|
func TestGiteacreateReleaseSuite(t *testing.T) {
|
||||||
@ -228,8 +227,8 @@ func (s *GiteaupdateReleaseSuite) TestSuccess() {
|
|||||||
httpmock.RegisterResponder("PATCH", s.releaseURL, resp)
|
httpmock.RegisterResponder("PATCH", s.releaseURL, resp)
|
||||||
|
|
||||||
release, err := s.client.updateRelease(s.ctx, s.title, s.description, s.releaseID)
|
release, err := s.client.updateRelease(s.ctx, s.title, s.description, s.releaseID)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, release)
|
require.NotNil(t, release)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GiteaupdateReleaseSuite) TestError() {
|
func (s *GiteaupdateReleaseSuite) TestError() {
|
||||||
@ -237,8 +236,8 @@ func (s *GiteaupdateReleaseSuite) TestError() {
|
|||||||
httpmock.RegisterResponder("PATCH", s.releaseURL, httpmock.NewStringResponder(400, ""))
|
httpmock.RegisterResponder("PATCH", s.releaseURL, httpmock.NewStringResponder(400, ""))
|
||||||
|
|
||||||
release, err := s.client.updateRelease(s.ctx, s.title, s.description, s.releaseID)
|
release, err := s.client.updateRelease(s.ctx, s.title, s.description, s.releaseID)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Nil(t, release)
|
require.Nil(t, release)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGiteaupdateReleaseSuite(t *testing.T) {
|
func TestGiteaupdateReleaseSuite(t *testing.T) {
|
||||||
@ -254,7 +253,7 @@ func TestGiteaCreateFile(t *testing.T) {
|
|||||||
path := ""
|
path := ""
|
||||||
message := ""
|
message := ""
|
||||||
file := client.CreateFile(&ctx, author, repo, content, path, message)
|
file := client.CreateFile(&ctx, author, repo, content, path, message)
|
||||||
assert.Nil(t, file)
|
require.Nil(t, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
type GiteaCreateReleaseSuite struct {
|
type GiteaCreateReleaseSuite struct {
|
||||||
@ -266,8 +265,8 @@ func (s *GiteaCreateReleaseSuite) TestTemplateError() {
|
|||||||
s.ctx.Config.Release.NameTemplate = "{{ .NoKeyLikeThat }}"
|
s.ctx.Config.Release.NameTemplate = "{{ .NoKeyLikeThat }}"
|
||||||
|
|
||||||
releaseID, err := s.client.CreateRelease(s.ctx, s.description)
|
releaseID, err := s.client.CreateRelease(s.ctx, s.description)
|
||||||
assert.Empty(t, releaseID)
|
require.Empty(t, releaseID)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GiteaCreateReleaseSuite) TestErrorGettingExisitngRelease() {
|
func (s *GiteaCreateReleaseSuite) TestErrorGettingExisitngRelease() {
|
||||||
@ -275,8 +274,8 @@ func (s *GiteaCreateReleaseSuite) TestErrorGettingExisitngRelease() {
|
|||||||
httpmock.RegisterResponder("GET", s.releasesURL, httpmock.NewStringResponder(404, ""))
|
httpmock.RegisterResponder("GET", s.releasesURL, httpmock.NewStringResponder(404, ""))
|
||||||
|
|
||||||
releaseID, err := s.client.CreateRelease(s.ctx, s.description)
|
releaseID, err := s.client.CreateRelease(s.ctx, s.description)
|
||||||
assert.Empty(t, releaseID)
|
require.Empty(t, releaseID)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GiteaCreateReleaseSuite) TestErrorUpdatingRelease() {
|
func (s *GiteaCreateReleaseSuite) TestErrorUpdatingRelease() {
|
||||||
@ -288,8 +287,8 @@ func (s *GiteaCreateReleaseSuite) TestErrorUpdatingRelease() {
|
|||||||
httpmock.RegisterResponder("PATCH", s.releaseURL, httpmock.NewStringResponder(400, ""))
|
httpmock.RegisterResponder("PATCH", s.releaseURL, httpmock.NewStringResponder(400, ""))
|
||||||
|
|
||||||
releaseID, err := s.client.CreateRelease(s.ctx, s.description)
|
releaseID, err := s.client.CreateRelease(s.ctx, s.description)
|
||||||
assert.Empty(t, releaseID)
|
require.Empty(t, releaseID)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GiteaCreateReleaseSuite) TestSuccessUpdatingRelease() {
|
func (s *GiteaCreateReleaseSuite) TestSuccessUpdatingRelease() {
|
||||||
@ -311,8 +310,8 @@ func (s *GiteaCreateReleaseSuite) TestSuccessUpdatingRelease() {
|
|||||||
|
|
||||||
newDescription := "NewDescription"
|
newDescription := "NewDescription"
|
||||||
releaseID, err := s.client.CreateRelease(s.ctx, newDescription)
|
releaseID, err := s.client.CreateRelease(s.ctx, newDescription)
|
||||||
assert.Equal(t, fmt.Sprint(expectedRelease.ID), releaseID)
|
require.Equal(t, fmt.Sprint(expectedRelease.ID), releaseID)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GiteaCreateReleaseSuite) TestErrorCreatingRelease() {
|
func (s *GiteaCreateReleaseSuite) TestErrorCreatingRelease() {
|
||||||
@ -321,8 +320,8 @@ func (s *GiteaCreateReleaseSuite) TestErrorCreatingRelease() {
|
|||||||
httpmock.RegisterResponder("POST", s.releasesURL, httpmock.NewStringResponder(400, ""))
|
httpmock.RegisterResponder("POST", s.releasesURL, httpmock.NewStringResponder(400, ""))
|
||||||
|
|
||||||
releaseID, err := s.client.CreateRelease(s.ctx, s.description)
|
releaseID, err := s.client.CreateRelease(s.ctx, s.description)
|
||||||
assert.Empty(t, releaseID)
|
require.Empty(t, releaseID)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GiteaCreateReleaseSuite) TestSuccessCreatingRelease() {
|
func (s *GiteaCreateReleaseSuite) TestSuccessCreatingRelease() {
|
||||||
@ -341,8 +340,8 @@ func (s *GiteaCreateReleaseSuite) TestSuccessCreatingRelease() {
|
|||||||
httpmock.RegisterResponder("POST", s.releasesURL, resp)
|
httpmock.RegisterResponder("POST", s.releasesURL, resp)
|
||||||
|
|
||||||
releaseID, err := s.client.CreateRelease(s.ctx, s.description)
|
releaseID, err := s.client.CreateRelease(s.ctx, s.description)
|
||||||
assert.Equal(t, fmt.Sprint(expectedRelease.ID), releaseID)
|
require.Equal(t, fmt.Sprint(expectedRelease.ID), releaseID)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGiteaCreateReleaseSuite(t *testing.T) {
|
func TestGiteaCreateReleaseSuite(t *testing.T) {
|
||||||
@ -377,7 +376,7 @@ func (s *GiteaUploadSuite) TearDownTest() {
|
|||||||
func (s *GiteaUploadSuite) TestErrorParsingReleaseID() {
|
func (s *GiteaUploadSuite) TestErrorParsingReleaseID() {
|
||||||
t := s.T()
|
t := s.T()
|
||||||
err := s.client.Upload(s.ctx, "notint", s.artifact, s.file)
|
err := s.client.Upload(s.ctx, "notint", s.artifact, s.file)
|
||||||
assert.EqualError(t, err, "strconv.ParseInt: parsing \"notint\": invalid syntax")
|
require.EqualError(t, err, "strconv.ParseInt: parsing \"notint\": invalid syntax")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GiteaUploadSuite) TestErrorCreatingReleaseAttachment() {
|
func (s *GiteaUploadSuite) TestErrorCreatingReleaseAttachment() {
|
||||||
@ -385,7 +384,7 @@ func (s *GiteaUploadSuite) TestErrorCreatingReleaseAttachment() {
|
|||||||
httpmock.RegisterResponder("POST", s.releaseAttachmentsURL, httpmock.NewStringResponder(400, ""))
|
httpmock.RegisterResponder("POST", s.releaseAttachmentsURL, httpmock.NewStringResponder(400, ""))
|
||||||
|
|
||||||
err := s.client.Upload(s.ctx, fmt.Sprint(s.releaseID), s.artifact, s.file)
|
err := s.client.Upload(s.ctx, fmt.Sprint(s.releaseID), s.artifact, s.file)
|
||||||
assert.True(t, strings.HasPrefix(err.Error(), "Unknown API Error: 400"))
|
require.True(t, strings.HasPrefix(err.Error(), "Unknown API Error: 400"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GiteaUploadSuite) TestSuccess() {
|
func (s *GiteaUploadSuite) TestSuccess() {
|
||||||
@ -396,7 +395,7 @@ func (s *GiteaUploadSuite) TestSuccess() {
|
|||||||
httpmock.RegisterResponder("POST", s.releaseAttachmentsURL, resp)
|
httpmock.RegisterResponder("POST", s.releaseAttachmentsURL, resp)
|
||||||
|
|
||||||
err = s.client.Upload(s.ctx, fmt.Sprint(s.releaseID), s.artifact, s.file)
|
err = s.client.Upload(s.ctx, fmt.Sprint(s.releaseID), s.artifact, s.file)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGiteaUploadSuite(t *testing.T) {
|
func TestGiteaUploadSuite(t *testing.T) {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExtractHashFromProjectFileURL(t *testing.T) {
|
func TestExtractHashFromProjectFileURL(t *testing.T) {
|
||||||
@ -16,7 +16,7 @@ func TestExtractHashFromProjectFileURL(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expexted no error but got: %v", err)
|
t.Errorf("expexted no error but got: %v", err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, givenHash, extractedHash)
|
require.Equal(t, givenHash, extractedHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFailToExtractHashFromProjectFileURL(t *testing.T) {
|
func TestFailToExtractHashFromProjectFileURL(t *testing.T) {
|
||||||
@ -48,11 +48,11 @@ func TestGitLabReleaseURLTemplate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
client, err := NewGitLab(ctx, ctx.Token)
|
client, err := NewGitLab(ctx, ctx.Token)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
urlTpl, err := client.ReleaseURLTemplate(ctx)
|
urlTpl, err := client.ReleaseURLTemplate(ctx)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expectedUrl := "https://gitlab.com/owner/name/uploads/{{ .ArtifactUploadHash }}/{{ .ArtifactName }}"
|
expectedUrl := "https://gitlab.com/owner/name/uploads/{{ .ArtifactUploadHash }}/{{ .ArtifactName }}"
|
||||||
assert.Equal(t, expectedUrl, urlTpl)
|
require.Equal(t, expectedUrl, urlTpl)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -225,9 +224,8 @@ func TestExecute(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if assert.Error(t, err) {
|
require.Error(t, err)
|
||||||
assert.Equal(t, tc.expectErr.Error(), err.Error())
|
require.Equal(t, tc.expectErr.Error(), err.Error())
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,65 +4,59 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestShouldGetAllFiles(t *testing.T) {
|
func TestShouldGetAllFiles(t *testing.T) {
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
globs := []config.ExtraFile{
|
globs := []config.ExtraFile{
|
||||||
{Glob: "./testdata/file1.golden"},
|
{Glob: "./testdata/file1.golden"},
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err := Find(globs)
|
files, err := Find(globs)
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
assert.Equal(1, len(files))
|
require.Equal(t, 1, len(files))
|
||||||
|
|
||||||
path, ok := files["file1.golden"]
|
path, ok := files["file1.golden"]
|
||||||
assert.True(ok)
|
require.True(t, ok)
|
||||||
assert.Equal(path, "./testdata/file1.golden")
|
require.Equal(t, path, "./testdata/file1.golden")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShouldGetAllFilesWithGoldenExtension(t *testing.T) {
|
func TestShouldGetAllFilesWithGoldenExtension(t *testing.T) {
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
globs := []config.ExtraFile{
|
globs := []config.ExtraFile{
|
||||||
{Glob: "./testdata/*.golden"},
|
{Glob: "./testdata/*.golden"},
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err := Find(globs)
|
files, err := Find(globs)
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
assert.Equal(2, len(files))
|
require.Equal(t, 2, len(files))
|
||||||
|
|
||||||
path, ok := files["file1.golden"]
|
path, ok := files["file1.golden"]
|
||||||
assert.True(ok)
|
require.True(t, ok)
|
||||||
assert.Equal(path, "testdata/file1.golden")
|
require.Equal(t, path, "testdata/file1.golden")
|
||||||
|
|
||||||
path, ok = files["file2.golden"]
|
path, ok = files["file2.golden"]
|
||||||
assert.True(ok)
|
require.True(t, ok)
|
||||||
assert.Equal(path, "testdata/file2.golden")
|
require.Equal(t, path, "testdata/file2.golden")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShouldGetAllFilesInsideTestdata(t *testing.T) {
|
func TestShouldGetAllFilesInsideTestdata(t *testing.T) {
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
globs := []config.ExtraFile{
|
globs := []config.ExtraFile{
|
||||||
{Glob: "./testdata/*"},
|
{Glob: "./testdata/*"},
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err := Find(globs)
|
files, err := Find(globs)
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
assert.Equal(3, len(files))
|
require.Equal(t, 3, len(files))
|
||||||
|
|
||||||
path, ok := files["file1.golden"]
|
path, ok := files["file1.golden"]
|
||||||
assert.True(ok)
|
require.True(t, ok)
|
||||||
assert.Equal(path, "testdata/file1.golden")
|
require.Equal(t, path, "testdata/file1.golden")
|
||||||
|
|
||||||
path, ok = files["file2.golden"]
|
path, ok = files["file2.golden"]
|
||||||
assert.True(ok)
|
require.True(t, ok)
|
||||||
assert.Equal(path, "testdata/file2.golden")
|
require.Equal(t, path, "testdata/file2.golden")
|
||||||
|
|
||||||
path, ok = files["file3.gold"]
|
path, ok = files["file3.gold"]
|
||||||
assert.True(ok)
|
require.True(t, ok)
|
||||||
assert.Equal(path, "testdata/file3.gold")
|
require.Equal(t, path, "testdata/file3.gold")
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/goreleaser/goreleaser/internal/git"
|
"github.com/goreleaser/goreleaser/internal/git"
|
||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRepoName(t *testing.T) {
|
func TestRepoName(t *testing.T) {
|
||||||
@ -14,8 +14,8 @@ func TestRepoName(t *testing.T) {
|
|||||||
testlib.GitInit(t)
|
testlib.GitInit(t)
|
||||||
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
||||||
repo, err := git.ExtractRepoFromConfig()
|
repo, err := git.ExtractRepoFromConfig()
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "goreleaser/goreleaser", repo.String())
|
require.Equal(t, "goreleaser/goreleaser", repo.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractRepoFromURL(t *testing.T) {
|
func TestExtractRepoFromURL(t *testing.T) {
|
||||||
@ -29,7 +29,7 @@ func TestExtractRepoFromURL(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
t.Run(url, func(t *testing.T) {
|
t.Run(url, func(t *testing.T) {
|
||||||
repo := git.ExtractRepoFromURL(url)
|
repo := git.ExtractRepoFromURL(url)
|
||||||
assert.Equal(t, "goreleaser/goreleaser", repo.String())
|
require.Equal(t, "goreleaser/goreleaser", repo.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,18 @@ import (
|
|||||||
|
|
||||||
"github.com/goreleaser/goreleaser/internal/git"
|
"github.com/goreleaser/goreleaser/internal/git"
|
||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGit(t *testing.T) {
|
func TestGit(t *testing.T) {
|
||||||
out, err := git.Run("status")
|
out, err := git.Run("status")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotEmpty(t, out)
|
require.NotEmpty(t, out)
|
||||||
|
|
||||||
out, err = git.Run("command-that-dont-exist")
|
out, err = git.Run("command-that-dont-exist")
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Empty(t, out)
|
require.Empty(t, out)
|
||||||
assert.Equal(
|
require.Equal(
|
||||||
t,
|
t,
|
||||||
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.\n",
|
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.\n",
|
||||||
err.Error(),
|
err.Error(),
|
||||||
@ -36,26 +36,26 @@ func TestGitWarning(t *testing.T) {
|
|||||||
testlib.GitTag(t, "1.2.3")
|
testlib.GitTag(t, "1.2.3")
|
||||||
|
|
||||||
out, err := git.Run("describe", "--tags", "--abbrev=0", "tags/1.2.3^")
|
out, err := git.Run("describe", "--tags", "--abbrev=0", "tags/1.2.3^")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "1.2.2\n", out)
|
require.Equal(t, "1.2.2\n", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRepo(t *testing.T) {
|
func TestRepo(t *testing.T) {
|
||||||
assert.True(t, git.IsRepo(), "goreleaser folder should be a git repo")
|
require.True(t, git.IsRepo(), "goreleaser folder should be a git repo")
|
||||||
|
|
||||||
assert.NoError(t, os.Chdir(os.TempDir()))
|
require.NoError(t, os.Chdir(os.TempDir()))
|
||||||
assert.False(t, git.IsRepo(), os.TempDir()+" folder should be a git repo")
|
require.False(t, git.IsRepo(), os.TempDir()+" folder should be a git repo")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClean(t *testing.T) {
|
func TestClean(t *testing.T) {
|
||||||
out, err := git.Clean("asdasd 'ssadas'\nadasd", nil)
|
out, err := git.Clean("asdasd 'ssadas'\nadasd", nil)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "asdasd ssadas", out)
|
require.Equal(t, "asdasd ssadas", out)
|
||||||
|
|
||||||
out, err = git.Clean(git.Run("command-that-dont-exist"))
|
out, err = git.Clean(git.Run("command-that-dont-exist"))
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Empty(t, out)
|
require.Empty(t, out)
|
||||||
assert.Equal(
|
require.Equal(
|
||||||
t,
|
t,
|
||||||
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.",
|
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.",
|
||||||
err.Error(),
|
err.Error(),
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestArch(t *testing.T) {
|
func TestArch(t *testing.T) {
|
||||||
@ -20,7 +20,7 @@ func TestArch(t *testing.T) {
|
|||||||
"linuxwhat": "what",
|
"linuxwhat": "what",
|
||||||
} {
|
} {
|
||||||
t.Run(fmt.Sprintf("%s to %s", from, to), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%s to %s", from, to), func(t *testing.T) {
|
||||||
assert.Equal(t, to, Arch(from))
|
require.Equal(t, to, Arch(from))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -56,14 +56,14 @@ func TestRunPipe_ModeBinary(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||||
d1 := []byte("hello\ngo\n")
|
d1 := []byte("hello\ngo\n")
|
||||||
err = ioutil.WriteFile(binPath, d1, 0666)
|
err = ioutil.WriteFile(binPath, d1, 0666)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Dummy artifactories
|
// Dummy artifactories
|
||||||
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -206,8 +206,8 @@ func TestRunPipe_ModeBinary(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.NoError(t, Pipe{}.Publish(ctx))
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_ModeArchive(t *testing.T) {
|
func TestRunPipe_ModeArchive(t *testing.T) {
|
||||||
@ -215,11 +215,11 @@ func TestRunPipe_ModeArchive(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
ProjectName: "goreleaser",
|
ProjectName: "goreleaser",
|
||||||
@ -307,19 +307,19 @@ func TestRunPipe_ModeArchive(t *testing.T) {
|
|||||||
uploads.Store("deb", true)
|
uploads.Store("deb", true)
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.NoError(t, Pipe{}.Publish(ctx))
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
_, ok := uploads.Load("targz")
|
_, ok := uploads.Load("targz")
|
||||||
assert.True(t, ok, "tar.gz file was not uploaded")
|
require.True(t, ok, "tar.gz file was not uploaded")
|
||||||
_, ok = uploads.Load("deb")
|
_, ok = uploads.Load("deb")
|
||||||
assert.True(t, ok, "deb file was not uploaded")
|
require.True(t, ok, "deb file was not uploaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_ArtifactoryDown(t *testing.T) {
|
func TestRunPipe_ArtifactoryDown(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
ProjectName: "goreleaser",
|
ProjectName: "goreleaser",
|
||||||
@ -343,15 +343,15 @@ func TestRunPipe_ArtifactoryDown(t *testing.T) {
|
|||||||
Path: tarfile.Name(),
|
Path: tarfile.Name(),
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
err = Pipe{}.Publish(ctx)
|
err = Pipe{}.Publish(ctx)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "connection refused")
|
require.Contains(t, err.Error(), "connection refused")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_TargetTemplateError(t *testing.T) {
|
func TestRunPipe_TargetTemplateError(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||||
|
|
||||||
@ -382,8 +382,8 @@ func TestRunPipe_TargetTemplateError(t *testing.T) {
|
|||||||
Type: artifact.UploadableBinary,
|
Type: artifact.UploadableBinary,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.EqualError(t, Pipe{}.Publish(ctx), `artifactory: error while building the target url: template: tmpl:1: unexpected "/" in operand`)
|
require.EqualError(t, Pipe{}.Publish(ctx), `artifactory: error while building the target url: template: tmpl:1: unexpected "/" in operand`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_BadCredentials(t *testing.T) {
|
func TestRunPipe_BadCredentials(t *testing.T) {
|
||||||
@ -391,14 +391,14 @@ func TestRunPipe_BadCredentials(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||||
d1 := []byte("hello\ngo\n")
|
d1 := []byte("hello\ngo\n")
|
||||||
err = ioutil.WriteFile(binPath, d1, 0666)
|
err = ioutil.WriteFile(binPath, d1, 0666)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Dummy artifactories
|
// Dummy artifactories
|
||||||
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -442,10 +442,10 @@ func TestRunPipe_BadCredentials(t *testing.T) {
|
|||||||
Type: artifact.UploadableBinary,
|
Type: artifact.UploadableBinary,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
err = Pipe{}.Publish(ctx)
|
err = Pipe{}.Publish(ctx)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "Bad credentials")
|
require.Contains(t, err.Error(), "Bad credentials")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_UnparsableErrorResponse(t *testing.T) {
|
func TestRunPipe_UnparsableErrorResponse(t *testing.T) {
|
||||||
@ -453,14 +453,14 @@ func TestRunPipe_UnparsableErrorResponse(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||||
d1 := []byte("hello\ngo\n")
|
d1 := []byte("hello\ngo\n")
|
||||||
err = ioutil.WriteFile(binPath, d1, 0666)
|
err = ioutil.WriteFile(binPath, d1, 0666)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Dummy artifactories
|
// Dummy artifactories
|
||||||
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -503,8 +503,8 @@ func TestRunPipe_UnparsableErrorResponse(t *testing.T) {
|
|||||||
Type: artifact.UploadableBinary,
|
Type: artifact.UploadableBinary,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.EqualError(t, Pipe{}.Publish(ctx), `artifactory: upload failed: invalid character '.' looking for beginning of value`)
|
require.EqualError(t, Pipe{}.Publish(ctx), `artifactory: upload failed: invalid character '.' looking for beginning of value`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_FileNotFound(t *testing.T) {
|
func TestRunPipe_FileNotFound(t *testing.T) {
|
||||||
@ -534,20 +534,20 @@ func TestRunPipe_FileNotFound(t *testing.T) {
|
|||||||
Type: artifact.UploadableBinary,
|
Type: artifact.UploadableBinary,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.EqualError(t, Pipe{}.Publish(ctx), `open archivetest/dist/mybin/mybin: no such file or directory`)
|
require.EqualError(t, Pipe{}.Publish(ctx), `open archivetest/dist/mybin/mybin: no such file or directory`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_UnparsableTarget(t *testing.T) {
|
func TestRunPipe_UnparsableTarget(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||||
d1 := []byte("hello\ngo\n")
|
d1 := []byte("hello\ngo\n")
|
||||||
err = ioutil.WriteFile(binPath, d1, 0666)
|
err = ioutil.WriteFile(binPath, d1, 0666)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
ProjectName: "mybin",
|
ProjectName: "mybin",
|
||||||
@ -575,8 +575,8 @@ func TestRunPipe_UnparsableTarget(t *testing.T) {
|
|||||||
Type: artifact.UploadableBinary,
|
Type: artifact.UploadableBinary,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.EqualError(t, Pipe{}.Publish(ctx), `artifactory: upload failed: parse "://artifacts.company.com/example-repo-local/mybin/darwin/amd64/mybin": missing protocol scheme`)
|
require.EqualError(t, Pipe{}.Publish(ctx), `artifactory: upload failed: parse "://artifacts.company.com/example-repo-local/mybin/darwin/amd64/mybin": missing protocol scheme`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
|
func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
|
||||||
@ -598,18 +598,18 @@ func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx.SkipPublish = true
|
ctx.SkipPublish = true
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
err := Pipe{}.Publish(ctx)
|
err := Pipe{}.Publish(ctx)
|
||||||
assert.True(t, pipe.IsSkip(err))
|
require.True(t, pipe.IsSkip(err))
|
||||||
assert.EqualError(t, err, pipe.ErrSkipPublishEnabled.Error())
|
require.EqualError(t, err, pipe.ErrSkipPublishEnabled.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_DirUpload(t *testing.T) {
|
func TestRunPipe_DirUpload(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||||
var binPath = filepath.Join(dist, "mybin")
|
var binPath = filepath.Join(dist, "mybin")
|
||||||
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
@ -638,18 +638,18 @@ func TestRunPipe_DirUpload(t *testing.T) {
|
|||||||
Type: artifact.UploadableBinary,
|
Type: artifact.UploadableBinary,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.EqualError(t, Pipe{}.Publish(ctx), `artifactory: upload failed: the asset to upload can't be a directory`)
|
require.EqualError(t, Pipe{}.Publish(ctx), `artifactory: upload failed: the asset to upload can't be a directory`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoArtifactories(t *testing.T) {
|
func TestNoArtifactories(t *testing.T) {
|
||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
require.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArtifactoriesWithoutTarget(t *testing.T) {
|
func TestArtifactoriesWithoutTarget(t *testing.T) {
|
||||||
@ -667,8 +667,8 @@ func TestArtifactoriesWithoutTarget(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
require.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArtifactoriesWithoutUsername(t *testing.T) {
|
func TestArtifactoriesWithoutUsername(t *testing.T) {
|
||||||
@ -686,8 +686,8 @@ func TestArtifactoriesWithoutUsername(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
require.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArtifactoriesWithoutName(t *testing.T) {
|
func TestArtifactoriesWithoutName(t *testing.T) {
|
||||||
@ -699,8 +699,8 @@ func TestArtifactoriesWithoutName(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
require.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArtifactoriesWithoutSecret(t *testing.T) {
|
func TestArtifactoriesWithoutSecret(t *testing.T) {
|
||||||
@ -713,8 +713,8 @@ func TestArtifactoriesWithoutSecret(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
require.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArtifactoriesWithInvalidMode(t *testing.T) {
|
func TestArtifactoriesWithInvalidMode(t *testing.T) {
|
||||||
@ -734,8 +734,8 @@ func TestArtifactoriesWithInvalidMode(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Error(t, Pipe{}.Publish(ctx))
|
require.Error(t, Pipe{}.Publish(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefault(t *testing.T) {
|
func TestDefault(t *testing.T) {
|
||||||
@ -751,10 +751,10 @@ func TestDefault(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Len(t, ctx.Config.Artifactories, 1)
|
require.Len(t, ctx.Config.Artifactories, 1)
|
||||||
var artifactory = ctx.Config.Artifactories[0]
|
var artifactory = ctx.Config.Artifactories[0]
|
||||||
assert.Equal(t, "archive", artifactory.Mode)
|
require.Equal(t, "archive", artifactory.Mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultNoArtifactories(t *testing.T) {
|
func TestDefaultNoArtifactories(t *testing.T) {
|
||||||
@ -763,8 +763,8 @@ func TestDefaultNoArtifactories(t *testing.T) {
|
|||||||
Artifactories: []config.Upload{},
|
Artifactories: []config.Upload{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Empty(t, ctx.Config.Artifactories)
|
require.Empty(t, ctx.Config.Artifactories)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultSet(t *testing.T) {
|
func TestDefaultSet(t *testing.T) {
|
||||||
@ -777,9 +777,9 @@ func TestDefaultSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Len(t, ctx.Config.Artifactories, 1)
|
require.Len(t, ctx.Config.Artifactories, 1)
|
||||||
var artifactory = ctx.Config.Artifactories[0]
|
var artifactory = ctx.Config.Artifactories[0]
|
||||||
assert.Equal(t, "custom", artifactory.Mode)
|
require.Equal(t, "custom", artifactory.Mode)
|
||||||
assert.Equal(t, "X-Checksum-SHA256", artifactory.ChecksumHeader)
|
require.Equal(t, "X-Checksum-SHA256", artifactory.ChecksumHeader)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"gocloud.dev/blob"
|
"gocloud.dev/blob"
|
||||||
)
|
)
|
||||||
@ -26,15 +25,15 @@ import (
|
|||||||
func TestMinioUpload(t *testing.T) {
|
func TestMinioUpload(t *testing.T) {
|
||||||
var listen = randomListen(t)
|
var listen = randomListen(t)
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
srcpath := filepath.Join(folder, "source.tar.gz")
|
srcpath := filepath.Join(folder, "source.tar.gz")
|
||||||
tgzpath := filepath.Join(folder, "bin.tar.gz")
|
tgzpath := filepath.Join(folder, "bin.tar.gz")
|
||||||
debpath := filepath.Join(folder, "bin.deb")
|
debpath := filepath.Join(folder, "bin.deb")
|
||||||
checkpath := filepath.Join(folder, "check.txt")
|
checkpath := filepath.Join(folder, "check.txt")
|
||||||
assert.NoError(t, ioutil.WriteFile(checkpath, []byte("fake checksums"), 0744))
|
require.NoError(t, ioutil.WriteFile(checkpath, []byte("fake checksums"), 0744))
|
||||||
assert.NoError(t, ioutil.WriteFile(srcpath, []byte("fake\nsrc"), 0744))
|
require.NoError(t, ioutil.WriteFile(srcpath, []byte("fake\nsrc"), 0744))
|
||||||
assert.NoError(t, ioutil.WriteFile(tgzpath, []byte("fake\ntargz"), 0744))
|
require.NoError(t, ioutil.WriteFile(tgzpath, []byte("fake\ntargz"), 0744))
|
||||||
assert.NoError(t, ioutil.WriteFile(debpath, []byte("fake\ndeb"), 0744))
|
require.NoError(t, ioutil.WriteFile(debpath, []byte("fake\ndeb"), 0744))
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
ProjectName: "testupload",
|
ProjectName: "testupload",
|
||||||
@ -82,8 +81,8 @@ func TestMinioUpload(t *testing.T) {
|
|||||||
defer stop(t, name)
|
defer stop(t, name)
|
||||||
start(t, name, listen)
|
start(t, name, listen)
|
||||||
prepareEnv(t, listen)
|
prepareEnv(t, listen)
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.NoError(t, Pipe{}.Publish(ctx))
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
|
|
||||||
require.Subset(t, getFiles(t, ctx, ctx.Config.Blobs[0]), []string{
|
require.Subset(t, getFiles(t, ctx, ctx.Config.Blobs[0]), []string{
|
||||||
"testupload/v1.0.0/bin.deb",
|
"testupload/v1.0.0/bin.deb",
|
||||||
@ -96,14 +95,14 @@ func TestMinioUpload(t *testing.T) {
|
|||||||
func TestMinioUploadCustomBucketID(t *testing.T) {
|
func TestMinioUploadCustomBucketID(t *testing.T) {
|
||||||
var listen = randomListen(t)
|
var listen = randomListen(t)
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tgzpath := filepath.Join(folder, "bin.tar.gz")
|
tgzpath := filepath.Join(folder, "bin.tar.gz")
|
||||||
debpath := filepath.Join(folder, "bin.deb")
|
debpath := filepath.Join(folder, "bin.deb")
|
||||||
assert.NoError(t, ioutil.WriteFile(tgzpath, []byte("fake\ntargz"), 0744))
|
require.NoError(t, ioutil.WriteFile(tgzpath, []byte("fake\ntargz"), 0744))
|
||||||
assert.NoError(t, ioutil.WriteFile(debpath, []byte("fake\ndeb"), 0744))
|
require.NoError(t, ioutil.WriteFile(debpath, []byte("fake\ndeb"), 0744))
|
||||||
// Set custom BUCKET_ID env variable.
|
// Set custom BUCKET_ID env variable.
|
||||||
err = os.Setenv("BUCKET_ID", "test")
|
err = os.Setenv("BUCKET_ID", "test")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
ProjectName: "testupload",
|
ProjectName: "testupload",
|
||||||
@ -130,20 +129,20 @@ func TestMinioUploadCustomBucketID(t *testing.T) {
|
|||||||
defer stop(t, name)
|
defer stop(t, name)
|
||||||
start(t, name, listen)
|
start(t, name, listen)
|
||||||
prepareEnv(t, listen)
|
prepareEnv(t, listen)
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.NoError(t, Pipe{}.Publish(ctx))
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMinioUploadInvalidCustomBucketID(t *testing.T) {
|
func TestMinioUploadInvalidCustomBucketID(t *testing.T) {
|
||||||
var listen = randomListen(t)
|
var listen = randomListen(t)
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tgzpath := filepath.Join(folder, "bin.tar.gz")
|
tgzpath := filepath.Join(folder, "bin.tar.gz")
|
||||||
debpath := filepath.Join(folder, "bin.deb")
|
debpath := filepath.Join(folder, "bin.deb")
|
||||||
assert.NoError(t, ioutil.WriteFile(tgzpath, []byte("fake\ntargz"), 0744))
|
require.NoError(t, ioutil.WriteFile(tgzpath, []byte("fake\ntargz"), 0744))
|
||||||
assert.NoError(t, ioutil.WriteFile(debpath, []byte("fake\ndeb"), 0744))
|
require.NoError(t, ioutil.WriteFile(debpath, []byte("fake\ndeb"), 0744))
|
||||||
// Set custom BUCKET_ID env variable.
|
// Set custom BUCKET_ID env variable.
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
ProjectName: "testupload",
|
ProjectName: "testupload",
|
||||||
@ -170,22 +169,22 @@ func TestMinioUploadInvalidCustomBucketID(t *testing.T) {
|
|||||||
defer stop(t, name)
|
defer stop(t, name)
|
||||||
start(t, name, listen)
|
start(t, name, listen)
|
||||||
prepareEnv(t, listen)
|
prepareEnv(t, listen)
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Error(t, Pipe{}.Publish(ctx))
|
require.Error(t, Pipe{}.Publish(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMinioUploadSkipPublish(t *testing.T) {
|
func TestMinioUploadSkipPublish(t *testing.T) {
|
||||||
var listen = randomListen(t)
|
var listen = randomListen(t)
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
srcpath := filepath.Join(folder, "source.tar.gz")
|
srcpath := filepath.Join(folder, "source.tar.gz")
|
||||||
tgzpath := filepath.Join(folder, "bin.tar.gz")
|
tgzpath := filepath.Join(folder, "bin.tar.gz")
|
||||||
debpath := filepath.Join(folder, "bin.deb")
|
debpath := filepath.Join(folder, "bin.deb")
|
||||||
checkpath := filepath.Join(folder, "check.txt")
|
checkpath := filepath.Join(folder, "check.txt")
|
||||||
assert.NoError(t, ioutil.WriteFile(checkpath, []byte("fake checksums"), 0744))
|
require.NoError(t, ioutil.WriteFile(checkpath, []byte("fake checksums"), 0744))
|
||||||
assert.NoError(t, ioutil.WriteFile(srcpath, []byte("fake\nsrc"), 0744))
|
require.NoError(t, ioutil.WriteFile(srcpath, []byte("fake\nsrc"), 0744))
|
||||||
assert.NoError(t, ioutil.WriteFile(tgzpath, []byte("fake\ntargz"), 0744))
|
require.NoError(t, ioutil.WriteFile(tgzpath, []byte("fake\ntargz"), 0744))
|
||||||
assert.NoError(t, ioutil.WriteFile(debpath, []byte("fake\ndeb"), 0744))
|
require.NoError(t, ioutil.WriteFile(debpath, []byte("fake\ndeb"), 0744))
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
ProjectName: "testupload",
|
ProjectName: "testupload",
|
||||||
@ -234,8 +233,8 @@ func TestMinioUploadSkipPublish(t *testing.T) {
|
|||||||
defer stop(t, name)
|
defer stop(t, name)
|
||||||
start(t, name, listen)
|
start(t, name, listen)
|
||||||
prepareEnv(t, listen)
|
prepareEnv(t, listen)
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.NoError(t, Pipe{}.Publish(ctx))
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
|
|
||||||
require.NotContains(t, getFiles(t, ctx, ctx.Config.Blobs[0]), []string{
|
require.NotContains(t, getFiles(t, ctx, ctx.Config.Blobs[0]), []string{
|
||||||
"testupload/v1.2.0/bin.deb",
|
"testupload/v1.2.0/bin.deb",
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,18 +24,16 @@ func TestNoBlob(t *testing.T) {
|
|||||||
|
|
||||||
func TestDefaultsNoConfig(t *testing.T) {
|
func TestDefaultsNoConfig(t *testing.T) {
|
||||||
errorString := "bucket or provider cannot be empty"
|
errorString := "bucket or provider cannot be empty"
|
||||||
var assert = assert.New(t)
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Blobs: []config.Blob{
|
Blobs: []config.Blob{
|
||||||
{},
|
{},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.EqualError(Pipe{}.Default(ctx), errorString)
|
require.EqualError(t, Pipe{}.Default(ctx), errorString)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultsNoBucket(t *testing.T) {
|
func TestDefaultsNoBucket(t *testing.T) {
|
||||||
errorString := "bucket or provider cannot be empty"
|
errorString := "bucket or provider cannot be empty"
|
||||||
var assert = assert.New(t)
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Blobs: []config.Blob{
|
Blobs: []config.Blob{
|
||||||
{
|
{
|
||||||
@ -44,12 +41,11 @@ func TestDefaultsNoBucket(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.EqualError(Pipe{}.Default(ctx), errorString)
|
require.EqualError(t, Pipe{}.Default(ctx), errorString)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultsNoProvider(t *testing.T) {
|
func TestDefaultsNoProvider(t *testing.T) {
|
||||||
errorString := "bucket or provider cannot be empty"
|
errorString := "bucket or provider cannot be empty"
|
||||||
var assert = assert.New(t)
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Blobs: []config.Blob{
|
Blobs: []config.Blob{
|
||||||
{
|
{
|
||||||
@ -57,7 +53,7 @@ func TestDefaultsNoProvider(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.EqualError(Pipe{}.Default(ctx), errorString)
|
require.EqualError(t, Pipe{}.Default(ctx), errorString)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaults(t *testing.T) {
|
func TestDefaults(t *testing.T) {
|
||||||
@ -91,7 +87,6 @@ func TestDefaults(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultsWithProvider(t *testing.T) {
|
func TestDefaultsWithProvider(t *testing.T) {
|
||||||
var assert = assert.New(t)
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Blobs: []config.Blob{
|
Blobs: []config.Blob{
|
||||||
{
|
{
|
||||||
@ -108,7 +103,7 @@ func TestDefaultsWithProvider(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.Nil(Pipe{}.Default(ctx))
|
require.Nil(t, Pipe{}.Default(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPipe_Publish(t *testing.T) {
|
func TestPipe_Publish(t *testing.T) {
|
||||||
@ -128,11 +123,11 @@ func pipePublish(t *testing.T, extra []config.ExtraFile) {
|
|||||||
gcloudCredentials, _ := filepath.Abs("./testdata/credentials.json")
|
gcloudCredentials, _ := filepath.Abs("./testdata/credentials.json")
|
||||||
|
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tgzpath := filepath.Join(folder, "bin.tar.gz")
|
tgzpath := filepath.Join(folder, "bin.tar.gz")
|
||||||
debpath := filepath.Join(folder, "bin.deb")
|
debpath := filepath.Join(folder, "bin.deb")
|
||||||
assert.NoError(t, ioutil.WriteFile(tgzpath, []byte("fake\ntargz"), 0744))
|
require.NoError(t, ioutil.WriteFile(tgzpath, []byte("fake\ntargz"), 0744))
|
||||||
assert.NoError(t, ioutil.WriteFile(debpath, []byte("fake\ndeb"), 0744))
|
require.NoError(t, ioutil.WriteFile(debpath, []byte("fake\ndeb"), 0744))
|
||||||
|
|
||||||
// Azure Blob Context
|
// Azure Blob Context
|
||||||
var azblobctx = context.New(config.Project{
|
var azblobctx = context.New(config.Project{
|
||||||
|
@ -13,30 +13,29 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var update = flag.Bool("update", false, "update .golden files")
|
var update = flag.Bool("update", false, "update .golden files")
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNameWithDash(t *testing.T) {
|
func TestNameWithDash(t *testing.T) {
|
||||||
assert.Equal(t, formulaNameFor("some-binary"), "SomeBinary")
|
require.Equal(t, formulaNameFor("some-binary"), "SomeBinary")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNameWithUnderline(t *testing.T) {
|
func TestNameWithUnderline(t *testing.T) {
|
||||||
assert.Equal(t, formulaNameFor("some_binary"), "SomeBinary")
|
require.Equal(t, formulaNameFor("some_binary"), "SomeBinary")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNameWithAT(t *testing.T) {
|
func TestNameWithAT(t *testing.T) {
|
||||||
assert.Equal(t, formulaNameFor("some_binary@1"), "SomeBinaryAT1")
|
require.Equal(t, formulaNameFor("some_binary@1"), "SomeBinaryAT1")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSimpleName(t *testing.T) {
|
func TestSimpleName(t *testing.T) {
|
||||||
assert.Equal(t, formulaNameFor("binary"), "Binary")
|
require.Equal(t, formulaNameFor("binary"), "Binary")
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultTemplateData = templateData{
|
var defaultTemplateData = templateData{
|
||||||
@ -64,11 +63,11 @@ var defaultTemplateData = templateData{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func assertDefaultTemplateData(t *testing.T, formulae string) {
|
func assertDefaultTemplateData(t *testing.T, formulae string) {
|
||||||
assert.Contains(t, formulae, "class Test < Formula")
|
require.Contains(t, formulae, "class Test < Formula")
|
||||||
assert.Contains(t, formulae, `homepage "https://google.com"`)
|
require.Contains(t, formulae, `homepage "https://google.com"`)
|
||||||
assert.Contains(t, formulae, `url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`)
|
require.Contains(t, formulae, `url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`)
|
||||||
assert.Contains(t, formulae, `sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`)
|
require.Contains(t, formulae, `sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`)
|
||||||
assert.Contains(t, formulae, `version "0.1.3"`)
|
require.Contains(t, formulae, `version "0.1.3"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFullFormulae(t *testing.T) {
|
func TestFullFormulae(t *testing.T) {
|
||||||
@ -84,34 +83,34 @@ func TestFullFormulae(t *testing.T) {
|
|||||||
formulae, err := doBuildFormula(context.New(config.Project{
|
formulae, err := doBuildFormula(context.New(config.Project{
|
||||||
ProjectName: "foo",
|
ProjectName: "foo",
|
||||||
}), data)
|
}), data)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var golden = "testdata/test.rb.golden"
|
var golden = "testdata/test.rb.golden"
|
||||||
if *update {
|
if *update {
|
||||||
err := ioutil.WriteFile(golden, []byte(formulae), 0655)
|
err := ioutil.WriteFile(golden, []byte(formulae), 0655)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
bts, err := ioutil.ReadFile(golden)
|
bts, err := ioutil.ReadFile(golden)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, string(bts), formulae)
|
require.Equal(t, string(bts), formulae)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFormulaeSimple(t *testing.T) {
|
func TestFormulaeSimple(t *testing.T) {
|
||||||
formulae, err := doBuildFormula(context.New(config.Project{}), defaultTemplateData)
|
formulae, err := doBuildFormula(context.New(config.Project{}), defaultTemplateData)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assertDefaultTemplateData(t, formulae)
|
assertDefaultTemplateData(t, formulae)
|
||||||
assert.NotContains(t, formulae, "def caveats")
|
require.NotContains(t, formulae, "def caveats")
|
||||||
assert.NotContains(t, formulae, "depends_on")
|
require.NotContains(t, formulae, "depends_on")
|
||||||
assert.NotContains(t, formulae, "def plist;")
|
require.NotContains(t, formulae, "def plist;")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSplit(t *testing.T) {
|
func TestSplit(t *testing.T) {
|
||||||
var parts = split("system \"true\"\nsystem \"#{bin}/foo -h\"")
|
var parts = split("system \"true\"\nsystem \"#{bin}/foo -h\"")
|
||||||
assert.Equal(t, []string{"system \"true\"", "system \"#{bin}/foo -h\""}, parts)
|
require.Equal(t, []string{"system \"true\"", "system \"#{bin}/foo -h\""}, parts)
|
||||||
parts = split("")
|
parts = split("")
|
||||||
assert.Equal(t, []string{}, parts)
|
require.Equal(t, []string{}, parts)
|
||||||
parts = split("\n ")
|
parts = split("\n ")
|
||||||
assert.Equal(t, []string{}, parts)
|
require.Equal(t, []string{}, parts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe(t *testing.T) {
|
func TestRunPipe(t *testing.T) {
|
||||||
@ -156,7 +155,7 @@ func TestRunPipe(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Git: context.GitInfo{
|
Git: context.GitInfo{
|
||||||
CurrentTag: "v1.0.1",
|
CurrentTag: "v1.0.1",
|
||||||
@ -214,30 +213,30 @@ func TestRunPipe(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
_, err = os.Create(path)
|
_, err = os.Create(path)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
var distFile = filepath.Join(folder, name+".rb")
|
var distFile = filepath.Join(folder, name+".rb")
|
||||||
|
|
||||||
assert.NoError(t, doRun(ctx, ctx.Config.Brews[0], client))
|
require.NoError(t, doRun(ctx, ctx.Config.Brews[0], client))
|
||||||
assert.True(t, client.CreatedFile)
|
require.True(t, client.CreatedFile)
|
||||||
var golden = fmt.Sprintf("testdata/%s.rb.golden", name)
|
var golden = fmt.Sprintf("testdata/%s.rb.golden", name)
|
||||||
if *update {
|
if *update {
|
||||||
assert.NoError(t, ioutil.WriteFile(golden, []byte(client.Content), 0655))
|
require.NoError(t, ioutil.WriteFile(golden, []byte(client.Content), 0655))
|
||||||
}
|
}
|
||||||
bts, err := ioutil.ReadFile(golden)
|
bts, err := ioutil.ReadFile(golden)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, string(bts), client.Content)
|
require.Equal(t, string(bts), client.Content)
|
||||||
|
|
||||||
distBts, err := ioutil.ReadFile(distFile)
|
distBts, err := ioutil.ReadFile(distFile)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, string(bts), string(distBts))
|
require.Equal(t, string(bts), string(distBts))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeNameTemplate(t *testing.T) {
|
func TestRunPipeNameTemplate(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Git: context.GitInfo{
|
Git: context.GitInfo{
|
||||||
CurrentTag: "v1.0.1",
|
CurrentTag: "v1.0.1",
|
||||||
@ -279,28 +278,28 @@ func TestRunPipeNameTemplate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
_, err = os.Create(path)
|
_, err = os.Create(path)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
var distFile = filepath.Join(folder, "foo_is_bar.rb")
|
var distFile = filepath.Join(folder, "foo_is_bar.rb")
|
||||||
|
|
||||||
assert.NoError(t, doRun(ctx, ctx.Config.Brews[0], client))
|
require.NoError(t, doRun(ctx, ctx.Config.Brews[0], client))
|
||||||
assert.True(t, client.CreatedFile)
|
require.True(t, client.CreatedFile)
|
||||||
var golden = "testdata/foo_is_bar.rb.golden"
|
var golden = "testdata/foo_is_bar.rb.golden"
|
||||||
if *update {
|
if *update {
|
||||||
assert.NoError(t, ioutil.WriteFile(golden, []byte(client.Content), 0655))
|
require.NoError(t, ioutil.WriteFile(golden, []byte(client.Content), 0655))
|
||||||
}
|
}
|
||||||
bts, err := ioutil.ReadFile(golden)
|
bts, err := ioutil.ReadFile(golden)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, string(bts), client.Content)
|
require.Equal(t, string(bts), client.Content)
|
||||||
|
|
||||||
distBts, err := ioutil.ReadFile(distFile)
|
distBts, err := ioutil.ReadFile(distFile)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, string(bts), string(distBts))
|
require.Equal(t, string(bts), string(distBts))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeMultipleBrewsWithSkip(t *testing.T) {
|
func TestRunPipeMultipleBrewsWithSkip(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Git: context.GitInfo{
|
Git: context.GitInfo{
|
||||||
CurrentTag: "v1.0.1",
|
CurrentTag: "v1.0.1",
|
||||||
@ -364,11 +363,11 @@ func TestRunPipeMultipleBrewsWithSkip(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
_, err = os.Create(path)
|
_, err = os.Create(path)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var cli = &DummyClient{}
|
var cli = &DummyClient{}
|
||||||
assert.EqualError(t, publishAll(ctx, cli), `brew.skip_upload is set`)
|
require.EqualError(t, publishAll(ctx, cli), `brew.skip_upload is set`)
|
||||||
assert.True(t, cli.CreatedFile)
|
require.True(t, cli.CreatedFile)
|
||||||
|
|
||||||
for _, brew := range ctx.Config.Brews {
|
for _, brew := range ctx.Config.Brews {
|
||||||
var distFile = filepath.Join(folder, brew.Name+".rb")
|
var distFile = filepath.Join(folder, brew.Name+".rb")
|
||||||
@ -391,7 +390,7 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
TokenType: context.TokenTypeGitHub,
|
TokenType: context.TokenTypeGitHub,
|
||||||
Git: context.GitInfo{
|
Git: context.GitInfo{
|
||||||
@ -483,25 +482,25 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
_, err := os.Create(path)
|
_, err := os.Create(path)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
var distFile = filepath.Join(folder, name+".rb")
|
var distFile = filepath.Join(folder, name+".rb")
|
||||||
|
|
||||||
assert.NoError(t, doRun(ctx, ctx.Config.Brews[0], client))
|
require.NoError(t, doRun(ctx, ctx.Config.Brews[0], client))
|
||||||
assert.True(t, client.CreatedFile)
|
require.True(t, client.CreatedFile)
|
||||||
var golden = fmt.Sprintf("testdata/%s.rb.golden", name)
|
var golden = fmt.Sprintf("testdata/%s.rb.golden", name)
|
||||||
if *update {
|
if *update {
|
||||||
assert.NoError(t, ioutil.WriteFile(golden, []byte(client.Content), 0655))
|
require.NoError(t, ioutil.WriteFile(golden, []byte(client.Content), 0655))
|
||||||
}
|
}
|
||||||
bts, err := ioutil.ReadFile(golden)
|
bts, err := ioutil.ReadFile(golden)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, string(bts), client.Content)
|
require.Equal(t, string(bts), client.Content)
|
||||||
|
|
||||||
distBts, err := ioutil.ReadFile(distFile)
|
distBts, err := ioutil.ReadFile(distFile)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, string(bts), string(distBts))
|
require.Equal(t, string(bts), string(distBts))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,8 +519,8 @@ func TestRunPipeNoDarwin64Build(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
assert.Equal(t, ErrNoArchivesFound, doRun(ctx, ctx.Config.Brews[0], client))
|
require.Equal(t, ErrNoArchivesFound, doRun(ctx, ctx.Config.Brews[0], client))
|
||||||
assert.False(t, client.CreatedFile)
|
require.False(t, client.CreatedFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
|
func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
|
||||||
@ -540,7 +539,7 @@ func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
|
|||||||
|
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
f, err := ioutil.TempFile("", "")
|
f, err := ioutil.TempFile("", "")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -662,8 +661,8 @@ func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
assert.Equal(t, test.expectedError, doRun(ctx, ctx.Config.Brews[0], client))
|
require.Equal(t, test.expectedError, doRun(ctx, ctx.Config.Brews[0], client))
|
||||||
assert.False(t, client.CreatedFile)
|
require.False(t, client.CreatedFile)
|
||||||
// clean the artifacts for the next run
|
// clean the artifacts for the next run
|
||||||
ctx.Artifacts = artifact.New()
|
ctx.Artifacts = artifact.New()
|
||||||
}
|
}
|
||||||
@ -675,7 +674,7 @@ func TestRunPipeBrewNotSetup(t *testing.T) {
|
|||||||
}
|
}
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
testlib.AssertSkipped(t, doRun(ctx, config.Homebrew{}, client))
|
testlib.AssertSkipped(t, doRun(ctx, config.Homebrew{}, client))
|
||||||
assert.False(t, client.CreatedFile)
|
require.False(t, client.CreatedFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeBinaryRelease(t *testing.T) {
|
func TestRunPipeBinaryRelease(t *testing.T) {
|
||||||
@ -699,13 +698,13 @@ func TestRunPipeBinaryRelease(t *testing.T) {
|
|||||||
Type: artifact.Binary,
|
Type: artifact.Binary,
|
||||||
})
|
})
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
assert.Equal(t, ErrNoArchivesFound, doRun(ctx, ctx.Config.Brews[0], client))
|
require.Equal(t, ErrNoArchivesFound, doRun(ctx, ctx.Config.Brews[0], client))
|
||||||
assert.False(t, client.CreatedFile)
|
require.False(t, client.CreatedFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeNoUpload(t *testing.T) {
|
func TestRunPipeNoUpload(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
ProjectName: "foo",
|
ProjectName: "foo",
|
||||||
@ -723,7 +722,7 @@ func TestRunPipeNoUpload(t *testing.T) {
|
|||||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
|
||||||
var path = filepath.Join(folder, "whatever.tar.gz")
|
var path = filepath.Join(folder, "whatever.tar.gz")
|
||||||
_, err = os.Create(path)
|
_, err = os.Create(path)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
ctx.Artifacts.Add(&artifact.Artifact{
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
Name: "bin",
|
Name: "bin",
|
||||||
Path: path,
|
Path: path,
|
||||||
@ -739,7 +738,7 @@ func TestRunPipeNoUpload(t *testing.T) {
|
|||||||
|
|
||||||
var assertNoPublish = func(t *testing.T) {
|
var assertNoPublish = func(t *testing.T) {
|
||||||
testlib.AssertSkipped(t, doRun(ctx, ctx.Config.Brews[0], client))
|
testlib.AssertSkipped(t, doRun(ctx, ctx.Config.Brews[0], client))
|
||||||
assert.False(t, client.CreatedFile)
|
require.False(t, client.CreatedFile)
|
||||||
}
|
}
|
||||||
t.Run("skip upload", func(tt *testing.T) {
|
t.Run("skip upload", func(tt *testing.T) {
|
||||||
ctx.Config.Release.Draft = false
|
ctx.Config.Release.Draft = false
|
||||||
@ -757,7 +756,7 @@ func TestRunPipeNoUpload(t *testing.T) {
|
|||||||
|
|
||||||
func TestRunEmptyTokenType(t *testing.T) {
|
func TestRunEmptyTokenType(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
ProjectName: "foo",
|
ProjectName: "foo",
|
||||||
@ -774,7 +773,7 @@ func TestRunEmptyTokenType(t *testing.T) {
|
|||||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
|
||||||
var path = filepath.Join(folder, "whatever.tar.gz")
|
var path = filepath.Join(folder, "whatever.tar.gz")
|
||||||
_, err = os.Create(path)
|
_, err = os.Create(path)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
ctx.Artifacts.Add(&artifact.Artifact{
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
Name: "bin",
|
Name: "bin",
|
||||||
Path: path,
|
Path: path,
|
||||||
@ -787,12 +786,12 @@ func TestRunEmptyTokenType(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
assert.NoError(t, doRun(ctx, ctx.Config.Brews[0], client))
|
require.NoError(t, doRun(ctx, ctx.Config.Brews[0], client))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
|
func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
ProjectName: "foo",
|
ProjectName: "foo",
|
||||||
@ -810,7 +809,7 @@ func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
|
|||||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
|
||||||
var path = filepath.Join(folder, "whatever.tar.gz")
|
var path = filepath.Join(folder, "whatever.tar.gz")
|
||||||
_, err = os.Create(path)
|
_, err = os.Create(path)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
ctx.Artifacts.Add(&artifact.Artifact{
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
Name: "bin",
|
Name: "bin",
|
||||||
Path: path,
|
Path: path,
|
||||||
@ -823,7 +822,7 @@ func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
client := &DummyClient{NotImplemented: true}
|
client := &DummyClient{NotImplemented: true}
|
||||||
assert.Equal(t, ErrTokenTypeNotImplementedForBrew{TokenType: "gitea"}, doRun(ctx, ctx.Config.Brews[0], client))
|
require.Equal(t, ErrTokenTypeNotImplementedForBrew{TokenType: "gitea"}, doRun(ctx, ctx.Config.Brews[0], client))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefault(t *testing.T) {
|
func TestDefault(t *testing.T) {
|
||||||
@ -859,16 +858,16 @@ func TestDefault(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, ctx.Config.ProjectName, ctx.Config.Brews[0].Name)
|
require.Equal(t, ctx.Config.ProjectName, ctx.Config.Brews[0].Name)
|
||||||
assert.NotEmpty(t, ctx.Config.Brews[0].CommitAuthor.Name)
|
require.NotEmpty(t, ctx.Config.Brews[0].CommitAuthor.Name)
|
||||||
assert.NotEmpty(t, ctx.Config.Brews[0].CommitAuthor.Email)
|
require.NotEmpty(t, ctx.Config.Brews[0].CommitAuthor.Email)
|
||||||
assert.Equal(t, `bin.install "foo"`, ctx.Config.Brews[0].Install)
|
require.Equal(t, `bin.install "foo"`, ctx.Config.Brews[0].Install)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGHFolder(t *testing.T) {
|
func TestGHFolder(t *testing.T) {
|
||||||
assert.Equal(t, "bar.rb", buildFormulaPath("", "bar.rb"))
|
require.Equal(t, "bar.rb", buildFormulaPath("", "bar.rb"))
|
||||||
assert.Equal(t, "fooo/bar.rb", buildFormulaPath("fooo", "bar.rb"))
|
require.Equal(t, "fooo/bar.rb", buildFormulaPath("fooo", "bar.rb"))
|
||||||
}
|
}
|
||||||
|
|
||||||
type DummyClient struct {
|
type DummyClient struct {
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
api "github.com/goreleaser/goreleaser/pkg/build"
|
api "github.com/goreleaser/goreleaser/pkg/build"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPipeDescription(t *testing.T) {
|
func TestPipeDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuild(t *testing.T) {
|
func TestBuild(t *testing.T) {
|
||||||
@ -79,9 +78,9 @@ func TestBuild(t *testing.T) {
|
|||||||
Config: config,
|
Config: config,
|
||||||
}
|
}
|
||||||
opts, err := buildOptionsForTarget(ctx, ctx.Config.Builds[0], "darwin_amd64")
|
opts, err := buildOptionsForTarget(ctx, ctx.Config.Builds[0], "darwin_amd64")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
error := doBuild(ctx, ctx.Config.Builds[0], *opts)
|
error := doBuild(ctx, ctx.Config.Builds[0], *opts)
|
||||||
assert.NoError(t, error)
|
require.NoError(t, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe(t *testing.T) {
|
func TestRunPipe(t *testing.T) {
|
||||||
@ -101,8 +100,8 @@ func TestRunPipe(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var ctx = context.New(config)
|
var ctx = context.New(config)
|
||||||
ctx.Git.CurrentTag = "2.4.5"
|
ctx.Git.CurrentTag = "2.4.5"
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, ctx.Artifacts.List(), []*artifact.Artifact{{
|
require.Equal(t, ctx.Artifacts.List(), []*artifact.Artifact{{
|
||||||
Name: "testing",
|
Name: "testing",
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
@ -135,13 +134,13 @@ func TestRunFullPipe(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var ctx = context.New(config)
|
var ctx = context.New(config)
|
||||||
ctx.Git.CurrentTag = "2.4.5"
|
ctx.Git.CurrentTag = "2.4.5"
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, ctx.Artifacts.List(), []*artifact.Artifact{{
|
require.Equal(t, ctx.Artifacts.List(), []*artifact.Artifact{{
|
||||||
Name: "testing",
|
Name: "testing",
|
||||||
}})
|
}})
|
||||||
assert.FileExists(t, post)
|
require.FileExists(t, post)
|
||||||
assert.FileExists(t, pre)
|
require.FileExists(t, pre)
|
||||||
assert.FileExists(t, filepath.Join(folder, "build1_whatever", "testing"))
|
require.FileExists(t, filepath.Join(folder, "build1_whatever", "testing"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunFullPipeFail(t *testing.T) {
|
func TestRunFullPipeFail(t *testing.T) {
|
||||||
@ -171,9 +170,9 @@ func TestRunFullPipeFail(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var ctx = context.New(config)
|
var ctx = context.New(config)
|
||||||
ctx.Git.CurrentTag = "2.4.5"
|
ctx.Git.CurrentTag = "2.4.5"
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), errFailedBuild.Error())
|
require.EqualError(t, Pipe{}.Run(ctx), errFailedBuild.Error())
|
||||||
assert.Empty(t, ctx.Artifacts.List())
|
require.Empty(t, ctx.Artifacts.List())
|
||||||
assert.FileExists(t, pre)
|
require.FileExists(t, pre)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeFailingHooks(t *testing.T) {
|
func TestRunPipeFailingHooks(t *testing.T) {
|
||||||
@ -195,14 +194,14 @@ func TestRunPipeFailingHooks(t *testing.T) {
|
|||||||
ctx.Git.CurrentTag = "2.3.4"
|
ctx.Git.CurrentTag = "2.3.4"
|
||||||
ctx.Config.Builds[0].Hooks.Pre = []config.BuildHook{{Cmd: "exit 1"}}
|
ctx.Config.Builds[0].Hooks.Pre = []config.BuildHook{{Cmd: "exit 1"}}
|
||||||
ctx.Config.Builds[0].Hooks.Post = []config.BuildHook{{Cmd: "echo post"}}
|
ctx.Config.Builds[0].Hooks.Post = []config.BuildHook{{Cmd: "echo post"}}
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), `pre hook failed: "": exec: "exit": executable file not found in $PATH`)
|
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) {
|
t.Run("post-hook", func(t *testing.T) {
|
||||||
var ctx = context.New(cfg)
|
var ctx = context.New(cfg)
|
||||||
ctx.Git.CurrentTag = "2.3.4"
|
ctx.Git.CurrentTag = "2.3.4"
|
||||||
ctx.Config.Builds[0].Hooks.Pre = []config.BuildHook{{Cmd: "echo pre"}}
|
ctx.Config.Builds[0].Hooks.Pre = []config.BuildHook{{Cmd: "echo pre"}}
|
||||||
ctx.Config.Builds[0].Hooks.Post = []config.BuildHook{{Cmd: "exit 1"}}
|
ctx.Config.Builds[0].Hooks.Post = []config.BuildHook{{Cmd: "exit 1"}}
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), `post hook failed: "": exec: "exit": executable file not found in $PATH`)
|
require.EqualError(t, Pipe{}.Run(ctx), `post hook failed: "": exec: "exit": executable file not found in $PATH`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,11 +209,11 @@ func TestDefaultNoBuilds(t *testing.T) {
|
|||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultExpandEnv(t *testing.T) {
|
func TestDefaultExpandEnv(t *testing.T) {
|
||||||
assert.NoError(t, os.Setenv("XBAR", "FOOBAR"))
|
require.NoError(t, os.Setenv("XBAR", "FOOBAR"))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
Builds: []config.Build{
|
Builds: []config.Build{
|
||||||
@ -226,9 +225,9 @@ func TestDefaultExpandEnv(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
var env = ctx.Config.Builds[0].Env[0]
|
var env = ctx.Config.Builds[0].Env[0]
|
||||||
assert.Equal(t, "XFOO=bar_FOOBAR", env)
|
require.Equal(t, "XFOO=bar_FOOBAR", env)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultEmptyBuild(t *testing.T) {
|
func TestDefaultEmptyBuild(t *testing.T) {
|
||||||
@ -240,17 +239,17 @@ func TestDefaultEmptyBuild(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
var build = ctx.Config.Builds[0]
|
var build = ctx.Config.Builds[0]
|
||||||
assert.Equal(t, ctx.Config.ProjectName, build.ID)
|
require.Equal(t, ctx.Config.ProjectName, build.ID)
|
||||||
assert.Equal(t, ctx.Config.ProjectName, build.Binary)
|
require.Equal(t, ctx.Config.ProjectName, build.Binary)
|
||||||
assert.Equal(t, ".", build.Dir)
|
require.Equal(t, ".", build.Dir)
|
||||||
assert.Equal(t, ".", build.Main)
|
require.Equal(t, ".", build.Main)
|
||||||
assert.Equal(t, []string{"linux", "darwin"}, build.Goos)
|
require.Equal(t, []string{"linux", "darwin"}, build.Goos)
|
||||||
assert.Equal(t, []string{"amd64", "386"}, build.Goarch)
|
require.Equal(t, []string{"amd64", "386"}, build.Goarch)
|
||||||
assert.Equal(t, []string{"6"}, build.Goarm)
|
require.Equal(t, []string{"6"}, build.Goarm)
|
||||||
assert.Len(t, build.Ldflags, 1)
|
require.Len(t, build.Ldflags, 1)
|
||||||
assert.Equal(t, "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser", build.Ldflags[0])
|
require.Equal(t, "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser", build.Ldflags[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultBuildID(t *testing.T) {
|
func TestDefaultBuildID(t *testing.T) {
|
||||||
@ -267,9 +266,9 @@ func TestDefaultBuildID(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.EqualError(t, Pipe{}.Default(ctx), "found 2 builds with the ID 'foo', please fix your config")
|
require.EqualError(t, Pipe{}.Default(ctx), "found 2 builds with the ID 'foo', please fix your config")
|
||||||
var build = ctx.Config.Builds[0]
|
var build = ctx.Config.Builds[0]
|
||||||
assert.Equal(t, ctx.Config.ProjectName, build.ID)
|
require.Equal(t, ctx.Config.ProjectName, build.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSeveralBuildsWithTheSameID(t *testing.T) {
|
func TestSeveralBuildsWithTheSameID(t *testing.T) {
|
||||||
@ -287,7 +286,7 @@ func TestSeveralBuildsWithTheSameID(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.EqualError(t, Pipe{}.Default(ctx), "found 2 builds with the ID 'a', please fix your config")
|
require.EqualError(t, Pipe{}.Default(ctx), "found 2 builds with the ID 'a', please fix your config")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultPartialBuilds(t *testing.T) {
|
func TestDefaultPartialBuilds(t *testing.T) {
|
||||||
@ -310,28 +309,28 @@ func TestDefaultPartialBuilds(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
t.Run("build0", func(t *testing.T) {
|
t.Run("build0", func(t *testing.T) {
|
||||||
var build = ctx.Config.Builds[0]
|
var build = ctx.Config.Builds[0]
|
||||||
assert.Equal(t, "bar", build.Binary)
|
require.Equal(t, "bar", build.Binary)
|
||||||
assert.Equal(t, ".", build.Dir)
|
require.Equal(t, ".", build.Dir)
|
||||||
assert.Equal(t, "./cmd/main.go", build.Main)
|
require.Equal(t, "./cmd/main.go", build.Main)
|
||||||
assert.Equal(t, []string{"linux"}, build.Goos)
|
require.Equal(t, []string{"linux"}, build.Goos)
|
||||||
assert.Equal(t, []string{"amd64", "386"}, build.Goarch)
|
require.Equal(t, []string{"amd64", "386"}, build.Goarch)
|
||||||
assert.Equal(t, []string{"6"}, build.Goarm)
|
require.Equal(t, []string{"6"}, build.Goarm)
|
||||||
assert.Len(t, build.Ldflags, 1)
|
require.Len(t, build.Ldflags, 1)
|
||||||
assert.Equal(t, "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser", build.Ldflags[0])
|
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) {
|
t.Run("build1", func(t *testing.T) {
|
||||||
var build = ctx.Config.Builds[1]
|
var build = ctx.Config.Builds[1]
|
||||||
assert.Equal(t, "foo", build.Binary)
|
require.Equal(t, "foo", build.Binary)
|
||||||
assert.Equal(t, ".", build.Main)
|
require.Equal(t, ".", build.Main)
|
||||||
assert.Equal(t, "baz", build.Dir)
|
require.Equal(t, "baz", build.Dir)
|
||||||
assert.Equal(t, []string{"linux", "darwin"}, build.Goos)
|
require.Equal(t, []string{"linux", "darwin"}, build.Goos)
|
||||||
assert.Equal(t, []string{"386"}, build.Goarch)
|
require.Equal(t, []string{"386"}, build.Goarch)
|
||||||
assert.Equal(t, []string{"6"}, build.Goarm)
|
require.Equal(t, []string{"6"}, build.Goarm)
|
||||||
assert.Len(t, build.Ldflags, 1)
|
require.Len(t, build.Ldflags, 1)
|
||||||
assert.Equal(t, "-s -w", build.Ldflags[0])
|
require.Equal(t, "-s -w", build.Ldflags[0])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,9 +346,9 @@ func TestDefaultFillSingleBuild(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Len(t, ctx.Config.Builds, 1)
|
require.Len(t, ctx.Config.Builds, 1)
|
||||||
assert.Equal(t, ctx.Config.Builds[0].Binary, "foo")
|
require.Equal(t, ctx.Config.Builds[0].Binary, "foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSkipBuild(t *testing.T) {
|
func TestSkipBuild(t *testing.T) {
|
||||||
@ -365,28 +364,28 @@ func TestSkipBuild(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var ctx = context.New(config)
|
var ctx = context.New(config)
|
||||||
ctx.Git.CurrentTag = "2.4.5"
|
ctx.Git.CurrentTag = "2.4.5"
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Len(t, ctx.Artifacts.List(), 0)
|
require.Len(t, ctx.Artifacts.List(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtWindows(t *testing.T) {
|
func TestExtWindows(t *testing.T) {
|
||||||
assert.Equal(t, ".exe", extFor("windows_amd64", config.FlagArray{}))
|
require.Equal(t, ".exe", extFor("windows_amd64", config.FlagArray{}))
|
||||||
assert.Equal(t, ".exe", extFor("windows_386", config.FlagArray{}))
|
require.Equal(t, ".exe", extFor("windows_386", config.FlagArray{}))
|
||||||
assert.Equal(t, ".exe", extFor("windows_amd64", config.FlagArray{"-tags=dev", "-v"}))
|
require.Equal(t, ".exe", extFor("windows_amd64", config.FlagArray{"-tags=dev", "-v"}))
|
||||||
assert.Equal(t, ".dll", extFor("windows_amd64", config.FlagArray{"-tags=dev", "-v", "-buildmode=c-shared"}))
|
require.Equal(t, ".dll", extFor("windows_amd64", config.FlagArray{"-tags=dev", "-v", "-buildmode=c-shared"}))
|
||||||
assert.Equal(t, ".dll", extFor("windows_386", config.FlagArray{"-buildmode=c-shared"}))
|
require.Equal(t, ".dll", extFor("windows_386", config.FlagArray{"-buildmode=c-shared"}))
|
||||||
assert.Equal(t, ".lib", extFor("windows_amd64", config.FlagArray{"-buildmode=c-archive"}))
|
require.Equal(t, ".lib", extFor("windows_amd64", config.FlagArray{"-buildmode=c-archive"}))
|
||||||
assert.Equal(t, ".lib", extFor("windows_386", config.FlagArray{"-tags=dev", "-v", "-buildmode=c-archive"}))
|
require.Equal(t, ".lib", extFor("windows_386", config.FlagArray{"-tags=dev", "-v", "-buildmode=c-archive"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtWasm(t *testing.T) {
|
func TestExtWasm(t *testing.T) {
|
||||||
assert.Equal(t, ".wasm", extFor("js_wasm", config.FlagArray{}))
|
require.Equal(t, ".wasm", extFor("js_wasm", config.FlagArray{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtOthers(t *testing.T) {
|
func TestExtOthers(t *testing.T) {
|
||||||
assert.Empty(t, "", extFor("linux_amd64", config.FlagArray{}))
|
require.Empty(t, "", extFor("linux_amd64", config.FlagArray{}))
|
||||||
assert.Empty(t, "", extFor("linuxwin_386", config.FlagArray{}))
|
require.Empty(t, "", extFor("linuxwin_386", config.FlagArray{}))
|
||||||
assert.Empty(t, "", extFor("winasdasd_sad", config.FlagArray{}))
|
require.Empty(t, "", extFor("winasdasd_sad", config.FlagArray{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTemplate(t *testing.T) {
|
func TestTemplate(t *testing.T) {
|
||||||
@ -399,13 +398,13 @@ func TestTemplate(t *testing.T) {
|
|||||||
ctx.Env = map[string]string{"FOO": "123"}
|
ctx.Env = map[string]string{"FOO": "123"}
|
||||||
binary, err := tmpl.New(ctx).
|
binary, err := tmpl.New(ctx).
|
||||||
Apply(`-s -w -X main.version={{.Version}} -X main.tag={{.Tag}} -X main.date={{.Date}} -X main.commit={{.Commit}} -X "main.foo={{.Env.FOO}}"`)
|
Apply(`-s -w -X main.version={{.Version}} -X main.tag={{.Tag}} -X main.date={{.Date}} -X main.commit={{.Commit}} -X "main.foo={{.Env.FOO}}"`)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Contains(t, binary, "-s -w")
|
require.Contains(t, binary, "-s -w")
|
||||||
assert.Contains(t, binary, "-X main.version=1.2.3")
|
require.Contains(t, binary, "-X main.version=1.2.3")
|
||||||
assert.Contains(t, binary, "-X main.tag=v1.2.3")
|
require.Contains(t, binary, "-X main.tag=v1.2.3")
|
||||||
assert.Contains(t, binary, "-X main.commit=123")
|
require.Contains(t, binary, "-X main.commit=123")
|
||||||
assert.Contains(t, binary, "-X main.date=")
|
require.Contains(t, binary, "-X main.date=")
|
||||||
assert.Contains(t, binary, `-X "main.foo=123"`)
|
require.Contains(t, binary, `-X "main.foo=123"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunHookEnvs(t *testing.T) {
|
func TestRunHookEnvs(t *testing.T) {
|
||||||
@ -438,8 +437,8 @@ func TestRunHookEnvs(t *testing.T) {
|
|||||||
fmt.Sprintf("CTXFOO=%s/foo", tmp),
|
fmt.Sprintf("CTXFOO=%s/foo", tmp),
|
||||||
},
|
},
|
||||||
}), opts, []string{}, simpleHook("touch {{ .Env.CTXFOO }}"))
|
}), opts, []string{}, simpleHook("touch {{ .Env.CTXFOO }}"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.FileExists(t, filepath.Join(tmp, "foo"))
|
require.FileExists(t, filepath.Join(tmp, "foo"))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("valid cmd template with build env", func(t *testing.T) {
|
t.Run("valid cmd template with build env", func(t *testing.T) {
|
||||||
@ -448,8 +447,8 @@ func TestRunHookEnvs(t *testing.T) {
|
|||||||
build,
|
build,
|
||||||
},
|
},
|
||||||
}), opts, build.Env, simpleHook("touch {{ .Env.FOO }}"))
|
}), opts, build.Env, simpleHook("touch {{ .Env.FOO }}"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.FileExists(t, filepath.Join(tmp, "foo"))
|
require.FileExists(t, filepath.Join(tmp, "foo"))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("valid cmd template with hook env", func(t *testing.T) {
|
t.Run("valid cmd template with hook env", func(t *testing.T) {
|
||||||
@ -463,8 +462,8 @@ func TestRunHookEnvs(t *testing.T) {
|
|||||||
fmt.Sprintf("HOOK_ONLY_FOO=%s/hook_only", tmp),
|
fmt.Sprintf("HOOK_ONLY_FOO=%s/hook_only", tmp),
|
||||||
},
|
},
|
||||||
}})
|
}})
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.FileExists(t, filepath.Join(tmp, "hook_only"))
|
require.FileExists(t, filepath.Join(tmp, "hook_only"))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("valid cmd template with ctx and build env", func(t *testing.T) {
|
t.Run("valid cmd template with ctx and build env", func(t *testing.T) {
|
||||||
@ -478,10 +477,10 @@ func TestRunHookEnvs(t *testing.T) {
|
|||||||
}), opts, []string{
|
}), opts, []string{
|
||||||
fmt.Sprintf("OVER_FOO=%s/build_over_ctx", tmp),
|
fmt.Sprintf("OVER_FOO=%s/build_over_ctx", tmp),
|
||||||
}, simpleHook("touch {{ .Env.OVER_FOO }}"))
|
}, simpleHook("touch {{ .Env.OVER_FOO }}"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.FileExists(t, filepath.Join(tmp, "build_over_ctx"))
|
require.FileExists(t, filepath.Join(tmp, "build_over_ctx"))
|
||||||
assert.NoFileExists(t, filepath.Join(tmp, "ctx_over_build"))
|
require.NoFileExists(t, filepath.Join(tmp, "ctx_over_build"))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("valid cmd template with ctx and hook env", func(t *testing.T) {
|
t.Run("valid cmd template with ctx and hook env", func(t *testing.T) {
|
||||||
@ -498,9 +497,9 @@ func TestRunHookEnvs(t *testing.T) {
|
|||||||
fmt.Sprintf("CTX_OR_HOOK_FOO=%s/hook_over_ctx", tmp),
|
fmt.Sprintf("CTX_OR_HOOK_FOO=%s/hook_over_ctx", tmp),
|
||||||
},
|
},
|
||||||
}})
|
}})
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.FileExists(t, filepath.Join(tmp, "hook_over_ctx"))
|
require.FileExists(t, filepath.Join(tmp, "hook_over_ctx"))
|
||||||
assert.NoFileExists(t, filepath.Join(tmp, "ctx_over_hook"))
|
require.NoFileExists(t, filepath.Join(tmp, "ctx_over_hook"))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("valid cmd template with build and hook env", func(t *testing.T) {
|
t.Run("valid cmd template with build and hook env", func(t *testing.T) {
|
||||||
@ -516,9 +515,9 @@ func TestRunHookEnvs(t *testing.T) {
|
|||||||
fmt.Sprintf("BUILD_OR_HOOK_FOO=%s/hook_over_build", tmp),
|
fmt.Sprintf("BUILD_OR_HOOK_FOO=%s/hook_over_build", tmp),
|
||||||
},
|
},
|
||||||
}})
|
}})
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.FileExists(t, filepath.Join(tmp, "hook_over_build"))
|
require.FileExists(t, filepath.Join(tmp, "hook_over_build"))
|
||||||
assert.NoFileExists(t, filepath.Join(tmp, "build_over_hook"))
|
require.NoFileExists(t, filepath.Join(tmp, "build_over_hook"))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("valid cmd template with ctx, build and hook env", func(t *testing.T) {
|
t.Run("valid cmd template with ctx, build and hook env", func(t *testing.T) {
|
||||||
@ -537,10 +536,10 @@ func TestRunHookEnvs(t *testing.T) {
|
|||||||
fmt.Sprintf("CTX_OR_BUILD_OR_HOOK_FOO=%s/hook_wins", tmp),
|
fmt.Sprintf("CTX_OR_BUILD_OR_HOOK_FOO=%s/hook_wins", tmp),
|
||||||
},
|
},
|
||||||
}})
|
}})
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.FileExists(t, filepath.Join(tmp, "hook_wins"))
|
require.FileExists(t, filepath.Join(tmp, "hook_wins"))
|
||||||
assert.NoFileExists(t, filepath.Join(tmp, "ctx_wins"))
|
require.NoFileExists(t, filepath.Join(tmp, "ctx_wins"))
|
||||||
assert.NoFileExists(t, filepath.Join(tmp, "build_wins"))
|
require.NoFileExists(t, filepath.Join(tmp, "build_wins"))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid cmd template", func(t *testing.T) {
|
t.Run("invalid cmd template", func(t *testing.T) {
|
||||||
@ -549,7 +548,7 @@ func TestRunHookEnvs(t *testing.T) {
|
|||||||
build,
|
build,
|
||||||
},
|
},
|
||||||
}), opts, build.Env, simpleHook("touch {{ .Env.FOOss }}"))
|
}), opts, build.Env, simpleHook("touch {{ .Env.FOOss }}"))
|
||||||
assert.EqualError(t, err, `template: tmpl:1:13: executing "tmpl" at <.Env.FOOss>: map has no entry for key "FOOss"`)
|
require.EqualError(t, err, `template: tmpl:1:13: executing "tmpl" at <.Env.FOOss>: map has no entry for key "FOOss"`)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid dir template", func(t *testing.T) {
|
t.Run("invalid dir template", func(t *testing.T) {
|
||||||
@ -561,7 +560,7 @@ func TestRunHookEnvs(t *testing.T) {
|
|||||||
Cmd: "echo something",
|
Cmd: "echo something",
|
||||||
Dir: "{{ .Env.INVALID_ENV }}",
|
Dir: "{{ .Env.INVALID_ENV }}",
|
||||||
}})
|
}})
|
||||||
assert.EqualError(t, err, `template: tmpl:1:7: executing "tmpl" at <.Env.INVALID_ENV>: map has no entry for key "INVALID_ENV"`)
|
require.EqualError(t, err, `template: tmpl:1:7: executing "tmpl" at <.Env.INVALID_ENV>: map has no entry for key "INVALID_ENV"`)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid hook env template", func(t *testing.T) {
|
t.Run("invalid hook env template", func(t *testing.T) {
|
||||||
@ -575,21 +574,21 @@ func TestRunHookEnvs(t *testing.T) {
|
|||||||
"TEST={{ .Env.MISSING_ENV }}",
|
"TEST={{ .Env.MISSING_ENV }}",
|
||||||
},
|
},
|
||||||
}})
|
}})
|
||||||
assert.EqualError(t, err, `template: tmpl:1:12: executing "tmpl" at <.Env.MISSING_ENV>: map has no entry for key "MISSING_ENV"`)
|
require.EqualError(t, err, `template: tmpl:1:12: executing "tmpl" at <.Env.MISSING_ENV>: map has no entry for key "MISSING_ENV"`)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("build env inside shell", func(t *testing.T) {
|
t.Run("build env inside shell", func(t *testing.T) {
|
||||||
var shell = `#!/bin/sh -e
|
var shell = `#!/bin/sh -e
|
||||||
touch "$BAR"`
|
touch "$BAR"`
|
||||||
err := ioutil.WriteFile(filepath.Join(tmp, "test.sh"), []byte(shell), 0750)
|
err := ioutil.WriteFile(filepath.Join(tmp, "test.sh"), []byte(shell), 0750)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = runHook(context.New(config.Project{
|
err = runHook(context.New(config.Project{
|
||||||
Builds: []config.Build{
|
Builds: []config.Build{
|
||||||
build,
|
build,
|
||||||
},
|
},
|
||||||
}), opts, build.Env, simpleHook("sh test.sh"))
|
}), opts, build.Env, simpleHook("sh test.sh"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.FileExists(t, filepath.Join(tmp, "bar"))
|
require.FileExists(t, filepath.Join(tmp, "bar"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,9 +620,9 @@ func TestBuild_hooksKnowGoosGoarch(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
err := runPipeOnBuild(ctx, build)
|
err := runPipeOnBuild(ctx, build)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.FileExists(t, filepath.Join(tmpDir, "pre-hook-amd64-linux"))
|
require.FileExists(t, filepath.Join(tmpDir, "pre-hook-amd64-linux"))
|
||||||
assert.FileExists(t, filepath.Join(tmpDir, "post-hook-amd64-linux"))
|
require.FileExists(t, filepath.Join(tmpDir, "post-hook-amd64-linux"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPipeOnBuild_hooksRunPerTarget(t *testing.T) {
|
func TestPipeOnBuild_hooksRunPerTarget(t *testing.T) {
|
||||||
@ -653,13 +652,13 @@ func TestPipeOnBuild_hooksRunPerTarget(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
err := runPipeOnBuild(ctx, build)
|
err := runPipeOnBuild(ctx, build)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.FileExists(t, filepath.Join(tmpDir, "pre-hook-linux_amd64"))
|
require.FileExists(t, filepath.Join(tmpDir, "pre-hook-linux_amd64"))
|
||||||
assert.FileExists(t, filepath.Join(tmpDir, "pre-hook-darwin_amd64"))
|
require.FileExists(t, filepath.Join(tmpDir, "pre-hook-darwin_amd64"))
|
||||||
assert.FileExists(t, filepath.Join(tmpDir, "pre-hook-windows_amd64"))
|
require.FileExists(t, filepath.Join(tmpDir, "pre-hook-windows_amd64"))
|
||||||
assert.FileExists(t, filepath.Join(tmpDir, "post-hook-linux_amd64"))
|
require.FileExists(t, filepath.Join(tmpDir, "post-hook-linux_amd64"))
|
||||||
assert.FileExists(t, filepath.Join(tmpDir, "post-hook-darwin_amd64"))
|
require.FileExists(t, filepath.Join(tmpDir, "post-hook-darwin_amd64"))
|
||||||
assert.FileExists(t, filepath.Join(tmpDir, "post-hook-windows_amd64"))
|
require.FileExists(t, filepath.Join(tmpDir, "post-hook-windows_amd64"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPipeOnBuild_invalidBinaryTpl(t *testing.T) {
|
func TestPipeOnBuild_invalidBinaryTpl(t *testing.T) {
|
||||||
@ -676,7 +675,7 @@ func TestPipeOnBuild_invalidBinaryTpl(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
err := runPipeOnBuild(ctx, build)
|
err := runPipeOnBuild(ctx, build)
|
||||||
assert.EqualError(t, err, `template: tmpl:1:11: executing "tmpl" at <.XYZ>: map has no entry for key "XYZ"`)
|
require.EqualError(t, err, `template: tmpl:1:11: executing "tmpl" at <.XYZ>: map has no entry for key "XYZ"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildOptionsForTarget(t *testing.T) {
|
func TestBuildOptionsForTarget(t *testing.T) {
|
||||||
@ -697,8 +696,8 @@ func TestBuildOptionsForTarget(t *testing.T) {
|
|||||||
Builds: []config.Build{build},
|
Builds: []config.Build{build},
|
||||||
})
|
})
|
||||||
opts, err := buildOptionsForTarget(ctx, build, "linux_amd64")
|
opts, err := buildOptionsForTarget(ctx, build, "linux_amd64")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, &api.Options{
|
require.Equal(t, &api.Options{
|
||||||
Name: "testbinary",
|
Name: "testbinary",
|
||||||
Path: filepath.Join(tmpDir, "testid_linux_amd64", "testbinary"),
|
Path: filepath.Join(tmpDir, "testid_linux_amd64", "testbinary"),
|
||||||
Target: "linux_amd64",
|
Target: "linux_amd64",
|
||||||
@ -753,6 +752,6 @@ func TestRunHookFailWithLogs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var ctx = context.New(config)
|
var ctx = context.New(config)
|
||||||
ctx.Git.CurrentTag = "2.4.5"
|
ctx.Git.CurrentTag = "2.4.5"
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), "pre hook failed: \"foo\\n\": exit status 1")
|
require.EqualError(t, Pipe{}.Run(ctx), "pre hook failed: \"foo\\n\": exit status 1")
|
||||||
assert.Empty(t, ctx.Artifacts.List())
|
require.Empty(t, ctx.Artifacts.List())
|
||||||
}
|
}
|
||||||
|
@ -9,21 +9,20 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPipe(t *testing.T) {
|
func TestPipe(t *testing.T) {
|
||||||
var binary = "binary"
|
var binary = "binary"
|
||||||
var checksums = binary + "_bar_checksums.txt"
|
var checksums = binary + "_bar_checksums.txt"
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var file = filepath.Join(folder, binary)
|
var file = filepath.Join(folder, binary)
|
||||||
assert.NoError(t, ioutil.WriteFile(file, []byte("some string"), 0644))
|
require.NoError(t, ioutil.WriteFile(file, []byte("some string"), 0644))
|
||||||
var ctx = context.New(
|
var ctx = context.New(
|
||||||
config.Project{
|
config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
@ -46,21 +45,21 @@ func TestPipe(t *testing.T) {
|
|||||||
Path: file,
|
Path: file,
|
||||||
Type: artifact.UploadableArchive,
|
Type: artifact.UploadableArchive,
|
||||||
})
|
})
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
var artifacts []string
|
var artifacts []string
|
||||||
for _, a := range ctx.Artifacts.List() {
|
for _, a := range ctx.Artifacts.List() {
|
||||||
artifacts = append(artifacts, a.Name)
|
artifacts = append(artifacts, a.Name)
|
||||||
}
|
}
|
||||||
assert.Contains(t, artifacts, checksums, binary)
|
require.Contains(t, artifacts, checksums, binary)
|
||||||
bts, err := ioutil.ReadFile(filepath.Join(folder, checksums))
|
bts, err := ioutil.ReadFile(filepath.Join(folder, checksums))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Contains(t, string(bts), "61d034473102d7dac305902770471fd50f4c5b26f6831a56dd90b5184b3c30fc binary")
|
require.Contains(t, string(bts), "61d034473102d7dac305902770471fd50f4c5b26f6831a56dd90b5184b3c30fc binary")
|
||||||
assert.Contains(t, string(bts), "61d034473102d7dac305902770471fd50f4c5b26f6831a56dd90b5184b3c30fc binary.tar.gz")
|
require.Contains(t, string(bts), "61d034473102d7dac305902770471fd50f4c5b26f6831a56dd90b5184b3c30fc binary.tar.gz")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPipeSkipTrue(t *testing.T) {
|
func TestPipeSkipTrue(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = context.New(
|
var ctx = context.New(
|
||||||
config.Project{
|
config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
@ -71,12 +70,12 @@ func TestPipeSkipTrue(t *testing.T) {
|
|||||||
)
|
)
|
||||||
err = Pipe{}.Run(ctx)
|
err = Pipe{}.Run(ctx)
|
||||||
testlib.AssertSkipped(t, err)
|
testlib.AssertSkipped(t, err)
|
||||||
assert.EqualError(t, err, `checksum.disable is set`)
|
require.EqualError(t, err, `checksum.disable is set`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPipeFileNotExist(t *testing.T) {
|
func TestPipeFileNotExist(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = context.New(
|
var ctx = context.New(
|
||||||
config.Project{
|
config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
@ -92,15 +91,15 @@ func TestPipeFileNotExist(t *testing.T) {
|
|||||||
Type: artifact.UploadableBinary,
|
Type: artifact.UploadableBinary,
|
||||||
})
|
})
|
||||||
err = Pipe{}.Run(ctx)
|
err = Pipe{}.Run(ctx)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "/nope: no such file or directory")
|
require.Contains(t, err.Error(), "/nope: no such file or directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPipeInvalidNameTemplate(t *testing.T) {
|
func TestPipeInvalidNameTemplate(t *testing.T) {
|
||||||
binFile, err := ioutil.TempFile("", "goreleasertest-bin")
|
binFile, err := ioutil.TempFile("", "goreleasertest-bin")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = binFile.WriteString("fake artifact")
|
_, err = binFile.WriteString("fake artifact")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for template, eerr := range map[string]string{
|
for template, eerr := range map[string]string{
|
||||||
"{{ .Pro }_checksums.txt": `template: tmpl:1: unexpected "}" in operand`,
|
"{{ .Pro }_checksums.txt": `template: tmpl:1: unexpected "}" in operand`,
|
||||||
@ -108,7 +107,7 @@ func TestPipeInvalidNameTemplate(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
t.Run(template, func(tt *testing.T) {
|
t.Run(template, func(tt *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(tt, err)
|
require.NoError(tt, err)
|
||||||
var ctx = context.New(
|
var ctx = context.New(
|
||||||
config.Project{
|
config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
@ -126,22 +125,22 @@ func TestPipeInvalidNameTemplate(t *testing.T) {
|
|||||||
Path: binFile.Name(),
|
Path: binFile.Name(),
|
||||||
})
|
})
|
||||||
err = Pipe{}.Run(ctx)
|
err = Pipe{}.Run(ctx)
|
||||||
assert.Error(tt, err)
|
require.Error(tt, err)
|
||||||
assert.Equal(tt, eerr, err.Error())
|
require.Equal(tt, eerr, err.Error())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) {
|
func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) {
|
||||||
binFile, err := ioutil.TempFile("", "goreleasertest-bin")
|
binFile, err := ioutil.TempFile("", "goreleasertest-bin")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = binFile.WriteString("fake artifact")
|
_, err = binFile.WriteString("fake artifact")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var file = filepath.Join(folder, "checksums.txt")
|
var file = filepath.Join(folder, "checksums.txt")
|
||||||
assert.NoError(t, ioutil.WriteFile(file, []byte("some string"), 0000))
|
require.NoError(t, ioutil.WriteFile(file, []byte("some string"), 0000))
|
||||||
var ctx = context.New(
|
var ctx = context.New(
|
||||||
config.Project{
|
config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
@ -158,14 +157,14 @@ func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) {
|
|||||||
Path: binFile.Name(),
|
Path: binFile.Name(),
|
||||||
})
|
})
|
||||||
err = Pipe{}.Run(ctx)
|
err = Pipe{}.Run(ctx)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "/checksums.txt: permission denied")
|
require.Contains(t, err.Error(), "/checksums.txt: permission denied")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPipeWhenNoArtifacts(t *testing.T) {
|
func TestPipeWhenNoArtifacts(t *testing.T) {
|
||||||
var ctx = &context.Context{}
|
var ctx = &context.Context{}
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Len(t, ctx.Artifacts.List(), 0)
|
require.Len(t, ctx.Artifacts.List(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefault(t *testing.T) {
|
func TestDefault(t *testing.T) {
|
||||||
@ -174,13 +173,13 @@ func TestDefault(t *testing.T) {
|
|||||||
Checksum: config.Checksum{},
|
Checksum: config.Checksum{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(
|
require.Equal(
|
||||||
t,
|
t,
|
||||||
"{{ .ProjectName }}_{{ .Version }}_checksums.txt",
|
"{{ .ProjectName }}_{{ .Version }}_checksums.txt",
|
||||||
ctx.Config.Checksum.NameTemplate,
|
ctx.Config.Checksum.NameTemplate,
|
||||||
)
|
)
|
||||||
assert.Equal(t, "sha256", ctx.Config.Checksum.Algorithm)
|
require.Equal(t, "sha256", ctx.Config.Checksum.Algorithm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultSet(t *testing.T) {
|
func TestDefaultSet(t *testing.T) {
|
||||||
@ -191,8 +190,8 @@ func TestDefaultSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "checksums.txt", ctx.Config.Checksum.NameTemplate)
|
require.Equal(t, "checksums.txt", ctx.Config.Checksum.NameTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add tests for LinuxPackage and UploadableSourceArchive
|
// TODO: add tests for LinuxPackage and UploadableSourceArchive
|
||||||
|
@ -6,12 +6,11 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFillBasicData(t *testing.T) {
|
func TestFillBasicData(t *testing.T) {
|
||||||
@ -25,23 +24,23 @@ func TestFillBasicData(t *testing.T) {
|
|||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
||||||
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
||||||
assert.NotEmpty(t, ctx.Config.Builds)
|
require.NotEmpty(t, ctx.Config.Builds)
|
||||||
assert.Equal(t, "goreleaser", ctx.Config.Builds[0].Binary)
|
require.Equal(t, "goreleaser", ctx.Config.Builds[0].Binary)
|
||||||
assert.Equal(t, ".", ctx.Config.Builds[0].Main)
|
require.Equal(t, ".", ctx.Config.Builds[0].Main)
|
||||||
assert.Contains(t, ctx.Config.Builds[0].Goos, "darwin")
|
require.Contains(t, ctx.Config.Builds[0].Goos, "darwin")
|
||||||
assert.Contains(t, ctx.Config.Builds[0].Goos, "linux")
|
require.Contains(t, ctx.Config.Builds[0].Goos, "linux")
|
||||||
assert.Contains(t, ctx.Config.Builds[0].Goarch, "386")
|
require.Contains(t, ctx.Config.Builds[0].Goarch, "386")
|
||||||
assert.Contains(t, ctx.Config.Builds[0].Goarch, "amd64")
|
require.Contains(t, ctx.Config.Builds[0].Goarch, "amd64")
|
||||||
assert.Equal(t, "tar.gz", ctx.Config.Archives[0].Format)
|
require.Equal(t, "tar.gz", ctx.Config.Archives[0].Format)
|
||||||
assert.Empty(t, ctx.Config.Dockers)
|
require.Empty(t, ctx.Config.Dockers)
|
||||||
assert.Equal(t, "https://github.com", ctx.Config.GitHubURLs.Download)
|
require.Equal(t, "https://github.com", ctx.Config.GitHubURLs.Download)
|
||||||
assert.NotEmpty(t, ctx.Config.Archives[0].NameTemplate)
|
require.NotEmpty(t, ctx.Config.Archives[0].NameTemplate)
|
||||||
assert.NotEmpty(t, ctx.Config.Builds[0].Ldflags)
|
require.NotEmpty(t, ctx.Config.Builds[0].Ldflags)
|
||||||
assert.NotEmpty(t, ctx.Config.Archives[0].Files)
|
require.NotEmpty(t, ctx.Config.Archives[0].Files)
|
||||||
assert.NotEmpty(t, ctx.Config.Dist)
|
require.NotEmpty(t, ctx.Config.Dist)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFillPartial(t *testing.T) {
|
func TestFillPartial(t *testing.T) {
|
||||||
@ -95,14 +94,14 @@ func TestFillPartial(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Len(t, ctx.Config.Archives[0].Files, 1)
|
require.Len(t, ctx.Config.Archives[0].Files, 1)
|
||||||
assert.Equal(t, `bin.install "testreleaser"`, ctx.Config.Brews[0].Install)
|
require.Equal(t, `bin.install "testreleaser"`, ctx.Config.Brews[0].Install)
|
||||||
assert.NotEmpty(t, ctx.Config.Dockers[0].Binaries)
|
require.NotEmpty(t, ctx.Config.Dockers[0].Binaries)
|
||||||
assert.NotEmpty(t, ctx.Config.Dockers[0].Goos)
|
require.NotEmpty(t, ctx.Config.Dockers[0].Goos)
|
||||||
assert.NotEmpty(t, ctx.Config.Dockers[0].Goarch)
|
require.NotEmpty(t, ctx.Config.Dockers[0].Goarch)
|
||||||
assert.NotEmpty(t, ctx.Config.Dockers[0].Dockerfile)
|
require.NotEmpty(t, ctx.Config.Dockers[0].Dockerfile)
|
||||||
assert.Empty(t, ctx.Config.Dockers[0].Goarm)
|
require.Empty(t, ctx.Config.Dockers[0].Goarm)
|
||||||
assert.Equal(t, "disttt", ctx.Config.Dist)
|
require.Equal(t, "disttt", ctx.Config.Dist)
|
||||||
assert.NotEqual(t, "https://github.com", ctx.Config.GitHubURLs.Download)
|
require.NotEqual(t, "https://github.com", ctx.Config.GitHubURLs.Download)
|
||||||
}
|
}
|
||||||
|
28
internal/pipe/dist/dist_test.go
vendored
28
internal/pipe/dist/dist_test.go
vendored
@ -8,14 +8,14 @@ import (
|
|||||||
|
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDistDoesNotExist(t *testing.T) {
|
func TestDistDoesNotExist(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "disttest")
|
folder, err := ioutil.TempDir("", "disttest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(
|
require.NoError(
|
||||||
t,
|
t,
|
||||||
Pipe{}.Run(
|
Pipe{}.Run(
|
||||||
&context.Context{
|
&context.Context{
|
||||||
@ -29,38 +29,38 @@ func TestDistDoesNotExist(t *testing.T) {
|
|||||||
|
|
||||||
func TestPopulatedDistExists(t *testing.T) {
|
func TestPopulatedDistExists(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "disttest")
|
folder, err := ioutil.TempDir("", "disttest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
_, err = os.Create(filepath.Join(dist, "mybin"))
|
_, err = os.Create(filepath.Join(dist, "mybin"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
Dist: dist,
|
Dist: dist,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.Error(t, Pipe{}.Run(ctx))
|
require.Error(t, Pipe{}.Run(ctx))
|
||||||
ctx.RmDist = true
|
ctx.RmDist = true
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
_, err = os.Stat(dist)
|
_, err = os.Stat(dist)
|
||||||
assert.False(t, os.IsExist(err))
|
require.False(t, os.IsExist(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyDistExists(t *testing.T) {
|
func TestEmptyDistExists(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "disttest")
|
folder, err := ioutil.TempDir("", "disttest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
Dist: dist,
|
Dist: dist,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
_, err = os.Stat(dist)
|
_, err = os.Stat(dist)
|
||||||
assert.False(t, os.IsNotExist(err))
|
require.False(t, os.IsNotExist(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -662,21 +661,21 @@ func TestBuildCommand(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
command := buildCommand(images, tt.flags)
|
command := buildCommand(images, tt.flags)
|
||||||
assert.Equal(t, tt.expect, command)
|
require.Equal(t, tt.expect, command)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoDockers(t *testing.T) {
|
func TestNoDockers(t *testing.T) {
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{}))))
|
require.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{}))))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoDockerWithoutImageName(t *testing.T) {
|
func TestNoDockerWithoutImageName(t *testing.T) {
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{
|
require.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{
|
||||||
Dockers: []config.Docker{
|
Dockers: []config.Docker{
|
||||||
{
|
{
|
||||||
Goos: "linux",
|
Goos: "linux",
|
||||||
@ -688,9 +687,9 @@ func TestNoDockerWithoutImageName(t *testing.T) {
|
|||||||
func TestDockerNotInPath(t *testing.T) {
|
func TestDockerNotInPath(t *testing.T) {
|
||||||
var path = os.Getenv("PATH")
|
var path = os.Getenv("PATH")
|
||||||
defer func() {
|
defer func() {
|
||||||
assert.NoError(t, os.Setenv("PATH", path))
|
require.NoError(t, os.Setenv("PATH", path))
|
||||||
}()
|
}()
|
||||||
assert.NoError(t, os.Setenv("PATH", ""))
|
require.NoError(t, os.Setenv("PATH", ""))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Version: "1.0.0",
|
Version: "1.0.0",
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
@ -701,7 +700,7 @@ func TestDockerNotInPath(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), ErrNoDocker.Error())
|
require.EqualError(t, Pipe{}.Run(ctx), ErrNoDocker.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefault(t *testing.T) {
|
func TestDefault(t *testing.T) {
|
||||||
@ -717,13 +716,13 @@ func TestDefault(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Len(t, ctx.Config.Dockers, 1)
|
require.Len(t, ctx.Config.Dockers, 1)
|
||||||
var docker = ctx.Config.Dockers[0]
|
var docker = ctx.Config.Dockers[0]
|
||||||
assert.Equal(t, "linux", docker.Goos)
|
require.Equal(t, "linux", docker.Goos)
|
||||||
assert.Equal(t, "amd64", docker.Goarch)
|
require.Equal(t, "amd64", docker.Goarch)
|
||||||
assert.Equal(t, []string{ctx.Config.Builds[0].Binary}, docker.Binaries)
|
require.Equal(t, []string{ctx.Config.Builds[0].Binary}, docker.Binaries)
|
||||||
assert.Empty(t, docker.Builds)
|
require.Empty(t, docker.Builds)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultBinaries(t *testing.T) {
|
func TestDefaultBinaries(t *testing.T) {
|
||||||
@ -741,12 +740,12 @@ func TestDefaultBinaries(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
require.Len(t, ctx.Config.Dockers, 1)
|
require.Len(t, ctx.Config.Dockers, 1)
|
||||||
var docker = ctx.Config.Dockers[0]
|
var docker = ctx.Config.Dockers[0]
|
||||||
assert.Equal(t, "linux", docker.Goos)
|
require.Equal(t, "linux", docker.Goos)
|
||||||
assert.Equal(t, "amd64", docker.Goarch)
|
require.Equal(t, "amd64", docker.Goarch)
|
||||||
assert.Equal(t, []string{"foo"}, docker.Binaries)
|
require.Equal(t, []string{"foo"}, docker.Binaries)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultNoDockers(t *testing.T) {
|
func TestDefaultNoDockers(t *testing.T) {
|
||||||
@ -755,8 +754,8 @@ func TestDefaultNoDockers(t *testing.T) {
|
|||||||
Dockers: []config.Docker{},
|
Dockers: []config.Docker{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Empty(t, ctx.Config.Dockers)
|
require.Empty(t, ctx.Config.Dockers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultFilesDot(t *testing.T) {
|
func TestDefaultFilesDot(t *testing.T) {
|
||||||
@ -770,7 +769,7 @@ func TestDefaultFilesDot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.EqualError(t, Pipe{}.Default(ctx), `invalid docker.files: can't be . or inside dist folder: .`)
|
require.EqualError(t, Pipe{}.Default(ctx), `invalid docker.files: can't be . or inside dist folder: .`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultFilesDis(t *testing.T) {
|
func TestDefaultFilesDis(t *testing.T) {
|
||||||
@ -784,7 +783,7 @@ func TestDefaultFilesDis(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.EqualError(t, Pipe{}.Default(ctx), `invalid docker.files: can't be . or inside dist folder: /tmp/dist/asdasd/asd`)
|
require.EqualError(t, Pipe{}.Default(ctx), `invalid docker.files: can't be . or inside dist folder: /tmp/dist/asdasd/asd`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultSet(t *testing.T) {
|
func TestDefaultSet(t *testing.T) {
|
||||||
@ -801,14 +800,14 @@ func TestDefaultSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Len(t, ctx.Config.Dockers, 1)
|
require.Len(t, ctx.Config.Dockers, 1)
|
||||||
var docker = ctx.Config.Dockers[0]
|
var docker = ctx.Config.Dockers[0]
|
||||||
assert.Equal(t, "windows", docker.Goos)
|
require.Equal(t, "windows", docker.Goos)
|
||||||
assert.Equal(t, "i386", docker.Goarch)
|
require.Equal(t, "i386", docker.Goarch)
|
||||||
assert.Equal(t, "bar", docker.Binaries[0])
|
require.Equal(t, "bar", docker.Binaries[0])
|
||||||
assert.Equal(t, "foo", docker.Builds[0])
|
require.Equal(t, "foo", docker.Builds[0])
|
||||||
assert.Equal(t, "Dockerfile.foo", docker.Dockerfile)
|
require.Equal(t, "Dockerfile.foo", docker.Dockerfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_processImageTemplates(t *testing.T) {
|
func Test_processImageTemplates(t *testing.T) {
|
||||||
@ -848,15 +847,15 @@ func Test_processImageTemplates(t *testing.T) {
|
|||||||
Patch: 0,
|
Patch: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Len(t, ctx.Config.Dockers, 1)
|
require.Len(t, ctx.Config.Dockers, 1)
|
||||||
|
|
||||||
docker := ctx.Config.Dockers[0]
|
docker := ctx.Config.Dockers[0]
|
||||||
assert.Equal(t, "Dockerfile.foo", docker.Dockerfile)
|
require.Equal(t, "Dockerfile.foo", docker.Dockerfile)
|
||||||
|
|
||||||
images, err := processImageTemplates(ctx, docker)
|
images, err := processImageTemplates(ctx, docker)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []string{
|
require.Equal(t, []string{
|
||||||
"user/image:v1.0.0",
|
"user/image:v1.0.0",
|
||||||
"gcr.io/image:v1.0.0-123",
|
"gcr.io/image:v1.0.0-123",
|
||||||
"gcr.io/image:v1.0",
|
"gcr.io/image:v1.0",
|
||||||
|
@ -9,25 +9,25 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPipeDescription(t *testing.T) {
|
func TestPipeDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test(t *testing.T) {
|
func Test(t *testing.T) {
|
||||||
folder, back := testlib.Mktmp(t)
|
folder, back := testlib.Mktmp(t)
|
||||||
defer back()
|
defer back()
|
||||||
dist := filepath.Join(folder, "dist")
|
dist := filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
var ctx = context.New(
|
var ctx = context.New(
|
||||||
config.Project{
|
config.Project{
|
||||||
Dist: dist,
|
Dist: dist,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
bts, err := ioutil.ReadFile(filepath.Join(dist, "config.yaml"))
|
bts, err := ioutil.ReadFile(filepath.Join(dist, "config.yaml"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotEmpty(t, string(bts))
|
require.NotEmpty(t, string(bts))
|
||||||
}
|
}
|
||||||
|
142
internal/pipe/env/env_test.go
vendored
142
internal/pipe/env/env_test.go
vendored
@ -8,20 +8,20 @@ import (
|
|||||||
|
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetDefaultTokenFiles(t *testing.T) {
|
func TestSetDefaultTokenFiles(t *testing.T) {
|
||||||
t.Run("empty config", func(tt *testing.T) {
|
t.Run("empty config", func(tt *testing.T) {
|
||||||
ctx := context.New(config.Project{})
|
ctx := context.New(config.Project{})
|
||||||
setDefaultTokenFiles(ctx)
|
setDefaultTokenFiles(ctx)
|
||||||
assert.Equal(t, "~/.config/goreleaser/github_token", ctx.Config.EnvFiles.GitHubToken)
|
require.Equal(t, "~/.config/goreleaser/github_token", ctx.Config.EnvFiles.GitHubToken)
|
||||||
assert.Equal(t, "~/.config/goreleaser/gitlab_token", ctx.Config.EnvFiles.GitLabToken)
|
require.Equal(t, "~/.config/goreleaser/gitlab_token", ctx.Config.EnvFiles.GitLabToken)
|
||||||
assert.Equal(t, "~/.config/goreleaser/gitea_token", ctx.Config.EnvFiles.GiteaToken)
|
require.Equal(t, "~/.config/goreleaser/gitea_token", ctx.Config.EnvFiles.GiteaToken)
|
||||||
})
|
})
|
||||||
t.Run("custom config config", func(tt *testing.T) {
|
t.Run("custom config config", func(tt *testing.T) {
|
||||||
cfg := "what"
|
cfg := "what"
|
||||||
@ -31,100 +31,100 @@ func TestSetDefaultTokenFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
setDefaultTokenFiles(ctx)
|
setDefaultTokenFiles(ctx)
|
||||||
assert.Equal(t, cfg, ctx.Config.EnvFiles.GitHubToken)
|
require.Equal(t, cfg, ctx.Config.EnvFiles.GitHubToken)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidGithubEnv(t *testing.T) {
|
func TestValidGithubEnv(t *testing.T) {
|
||||||
assert.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf"))
|
require.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf"))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, "asdf", ctx.Token)
|
require.Equal(t, "asdf", ctx.Token)
|
||||||
assert.Equal(t, context.TokenTypeGitHub, ctx.TokenType)
|
require.Equal(t, context.TokenTypeGitHub, ctx.TokenType)
|
||||||
// so the tests do not depend on each other
|
// so the tests do not depend on each other
|
||||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidGitlabEnv(t *testing.T) {
|
func TestValidGitlabEnv(t *testing.T) {
|
||||||
assert.NoError(t, os.Setenv("GITLAB_TOKEN", "qwertz"))
|
require.NoError(t, os.Setenv("GITLAB_TOKEN", "qwertz"))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, "qwertz", ctx.Token)
|
require.Equal(t, "qwertz", ctx.Token)
|
||||||
assert.Equal(t, context.TokenTypeGitLab, ctx.TokenType)
|
require.Equal(t, context.TokenTypeGitLab, ctx.TokenType)
|
||||||
// so the tests do not depend on each other
|
// so the tests do not depend on each other
|
||||||
assert.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidGiteaEnv(t *testing.T) {
|
func TestValidGiteaEnv(t *testing.T) {
|
||||||
assert.NoError(t, os.Setenv("GITEA_TOKEN", "token"))
|
require.NoError(t, os.Setenv("GITEA_TOKEN", "token"))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, "token", ctx.Token)
|
require.Equal(t, "token", ctx.Token)
|
||||||
assert.Equal(t, context.TokenTypeGitea, ctx.TokenType)
|
require.Equal(t, context.TokenTypeGitea, ctx.TokenType)
|
||||||
// so the tests do not depend on each other
|
// so the tests do not depend on each other
|
||||||
assert.NoError(t, os.Unsetenv("GITEA_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITEA_TOKEN"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidEnv(t *testing.T) {
|
func TestInvalidEnv(t *testing.T) {
|
||||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||||
assert.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.Error(t, Pipe{}.Run(ctx))
|
require.Error(t, Pipe{}.Run(ctx))
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), ErrMissingToken.Error())
|
require.EqualError(t, Pipe{}.Run(ctx), ErrMissingToken.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultipleEnvTokens(t *testing.T) {
|
func TestMultipleEnvTokens(t *testing.T) {
|
||||||
assert.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf"))
|
require.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf"))
|
||||||
assert.NoError(t, os.Setenv("GITLAB_TOKEN", "qwertz"))
|
require.NoError(t, os.Setenv("GITLAB_TOKEN", "qwertz"))
|
||||||
assert.NoError(t, os.Setenv("GITEA_TOKEN", "token"))
|
require.NoError(t, os.Setenv("GITEA_TOKEN", "token"))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.Error(t, Pipe{}.Run(ctx))
|
require.Error(t, Pipe{}.Run(ctx))
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), ErrMultipleTokens.Error())
|
require.EqualError(t, Pipe{}.Run(ctx), ErrMultipleTokens.Error())
|
||||||
// so the tests do not depend on each other
|
// so the tests do not depend on each other
|
||||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||||
assert.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
|
||||||
assert.NoError(t, os.Unsetenv("GITEA_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITEA_TOKEN"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyGithubFileEnv(t *testing.T) {
|
func TestEmptyGithubFileEnv(t *testing.T) {
|
||||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.Error(t, Pipe{}.Run(ctx))
|
require.Error(t, Pipe{}.Run(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyGitlabFileEnv(t *testing.T) {
|
func TestEmptyGitlabFileEnv(t *testing.T) {
|
||||||
assert.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.Error(t, Pipe{}.Run(ctx))
|
require.Error(t, Pipe{}.Run(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyGiteaFileEnv(t *testing.T) {
|
func TestEmptyGiteaFileEnv(t *testing.T) {
|
||||||
assert.NoError(t, os.Unsetenv("GITEA_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITEA_TOKEN"))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.Error(t, Pipe{}.Run(ctx))
|
require.Error(t, Pipe{}.Run(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyGithubEnvFile(t *testing.T) {
|
func TestEmptyGithubEnvFile(t *testing.T) {
|
||||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||||
f, err := ioutil.TempFile("", "token")
|
f, err := ioutil.TempFile("", "token")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NoError(t, os.Chmod(f.Name(), 0377))
|
require.NoError(t, os.Chmod(f.Name(), 0377))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
EnvFiles: config.EnvFiles{
|
EnvFiles: config.EnvFiles{
|
||||||
@ -132,14 +132,14 @@ func TestEmptyGithubEnvFile(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), fmt.Sprintf("failed to load github token: open %s: permission denied", f.Name()))
|
require.EqualError(t, Pipe{}.Run(ctx), fmt.Sprintf("failed to load github token: open %s: permission denied", f.Name()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyGitlabEnvFile(t *testing.T) {
|
func TestEmptyGitlabEnvFile(t *testing.T) {
|
||||||
assert.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITLAB_TOKEN"))
|
||||||
f, err := ioutil.TempFile("", "token")
|
f, err := ioutil.TempFile("", "token")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NoError(t, os.Chmod(f.Name(), 0377))
|
require.NoError(t, os.Chmod(f.Name(), 0377))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
EnvFiles: config.EnvFiles{
|
EnvFiles: config.EnvFiles{
|
||||||
@ -147,14 +147,14 @@ func TestEmptyGitlabEnvFile(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), fmt.Sprintf("failed to load gitlab token: open %s: permission denied", f.Name()))
|
require.EqualError(t, Pipe{}.Run(ctx), fmt.Sprintf("failed to load gitlab token: open %s: permission denied", f.Name()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyGiteaEnvFile(t *testing.T) {
|
func TestEmptyGiteaEnvFile(t *testing.T) {
|
||||||
assert.NoError(t, os.Unsetenv("GITEA_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITEA_TOKEN"))
|
||||||
f, err := ioutil.TempFile("", "token")
|
f, err := ioutil.TempFile("", "token")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NoError(t, os.Chmod(f.Name(), 0377))
|
require.NoError(t, os.Chmod(f.Name(), 0377))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
EnvFiles: config.EnvFiles{
|
EnvFiles: config.EnvFiles{
|
||||||
@ -162,20 +162,20 @@ func TestEmptyGiteaEnvFile(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), fmt.Sprintf("failed to load gitea token: open %s: permission denied", f.Name()))
|
require.EqualError(t, Pipe{}.Run(ctx), fmt.Sprintf("failed to load gitea token: open %s: permission denied", f.Name()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidEnvChecksSkipped(t *testing.T) {
|
func TestInvalidEnvChecksSkipped(t *testing.T) {
|
||||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
SkipPublish: true,
|
SkipPublish: true,
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidEnvReleaseDisabled(t *testing.T) {
|
func TestInvalidEnvReleaseDisabled(t *testing.T) {
|
||||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
Release: config.Release{
|
Release: config.Release{
|
||||||
@ -183,47 +183,47 @@ func TestInvalidEnvReleaseDisabled(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadEnv(t *testing.T) {
|
func TestLoadEnv(t *testing.T) {
|
||||||
t.Run("env exists", func(tt *testing.T) {
|
t.Run("env exists", func(tt *testing.T) {
|
||||||
var env = "SUPER_SECRET_ENV"
|
var env = "SUPER_SECRET_ENV"
|
||||||
assert.NoError(tt, os.Setenv(env, "1"))
|
require.NoError(tt, os.Setenv(env, "1"))
|
||||||
v, err := loadEnv(env, "nope")
|
v, err := loadEnv(env, "nope")
|
||||||
assert.NoError(tt, err)
|
require.NoError(tt, err)
|
||||||
assert.Equal(tt, "1", v)
|
require.Equal(tt, "1", v)
|
||||||
})
|
})
|
||||||
t.Run("env file exists", func(tt *testing.T) {
|
t.Run("env file exists", func(tt *testing.T) {
|
||||||
var env = "SUPER_SECRET_ENV_NOPE"
|
var env = "SUPER_SECRET_ENV_NOPE"
|
||||||
assert.NoError(tt, os.Unsetenv(env))
|
require.NoError(tt, os.Unsetenv(env))
|
||||||
f, err := ioutil.TempFile("", "token")
|
f, err := ioutil.TempFile("", "token")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
fmt.Fprintf(f, "123")
|
fmt.Fprintf(f, "123")
|
||||||
v, err := loadEnv(env, f.Name())
|
v, err := loadEnv(env, f.Name())
|
||||||
assert.NoError(tt, err)
|
require.NoError(tt, err)
|
||||||
assert.Equal(tt, "123", v)
|
require.Equal(tt, "123", v)
|
||||||
})
|
})
|
||||||
t.Run("env file with an empty line at the end", func(tt *testing.T) {
|
t.Run("env file with an empty line at the end", func(tt *testing.T) {
|
||||||
var env = "SUPER_SECRET_ENV_NOPE"
|
var env = "SUPER_SECRET_ENV_NOPE"
|
||||||
assert.NoError(tt, os.Unsetenv(env))
|
require.NoError(tt, os.Unsetenv(env))
|
||||||
f, err := ioutil.TempFile("", "token")
|
f, err := ioutil.TempFile("", "token")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
fmt.Fprintf(f, "123\n")
|
fmt.Fprintf(f, "123\n")
|
||||||
v, err := loadEnv(env, f.Name())
|
v, err := loadEnv(env, f.Name())
|
||||||
assert.NoError(tt, err)
|
require.NoError(tt, err)
|
||||||
assert.Equal(tt, "123", v)
|
require.Equal(tt, "123", v)
|
||||||
})
|
})
|
||||||
t.Run("env file is not readable", func(tt *testing.T) {
|
t.Run("env file is not readable", func(tt *testing.T) {
|
||||||
var env = "SUPER_SECRET_ENV_NOPE"
|
var env = "SUPER_SECRET_ENV_NOPE"
|
||||||
assert.NoError(tt, os.Unsetenv(env))
|
require.NoError(tt, os.Unsetenv(env))
|
||||||
f, err := ioutil.TempFile("", "token")
|
f, err := ioutil.TempFile("", "token")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
fmt.Fprintf(f, "123")
|
fmt.Fprintf(f, "123")
|
||||||
err = os.Chmod(f.Name(), 0377)
|
err = os.Chmod(f.Name(), 0377)
|
||||||
assert.NoError(tt, err)
|
require.NoError(tt, err)
|
||||||
v, err := loadEnv(env, f.Name())
|
v, err := loadEnv(env, f.Name())
|
||||||
assert.EqualError(tt, err, fmt.Sprintf("open %s: permission denied", f.Name()))
|
require.EqualError(tt, err, fmt.Sprintf("open %s: permission denied", f.Name()))
|
||||||
assert.Equal(tt, "", v)
|
require.Equal(tt, "", v)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
@ -16,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotAGitFolder(t *testing.T) {
|
func TestNotAGitFolder(t *testing.T) {
|
||||||
@ -25,7 +24,7 @@ func TestNotAGitFolder(t *testing.T) {
|
|||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), ErrNotRepository.Error())
|
require.EqualError(t, Pipe{}.Run(ctx), ErrNotRepository.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSingleCommit(t *testing.T) {
|
func TestSingleCommit(t *testing.T) {
|
||||||
@ -38,8 +37,8 @@ func TestSingleCommit(t *testing.T) {
|
|||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
require.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoRemote(t *testing.T) {
|
func TestNoRemote(t *testing.T) {
|
||||||
@ -51,7 +50,7 @@ func TestNoRemote(t *testing.T) {
|
|||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), "couldn't get remote URL: fatal: No remote configured to list refs from.")
|
require.EqualError(t, Pipe{}.Run(ctx), "couldn't get remote URL: fatal: No remote configured to list refs from.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewRepository(t *testing.T) {
|
func TestNewRepository(t *testing.T) {
|
||||||
@ -62,7 +61,7 @@ func TestNewRepository(t *testing.T) {
|
|||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
// TODO: improve this error handling
|
// TODO: improve this error handling
|
||||||
assert.Contains(t, Pipe{}.Run(ctx).Error(), `fatal: ambiguous argument 'HEAD'`)
|
require.Contains(t, Pipe{}.Run(ctx).Error(), `fatal: ambiguous argument 'HEAD'`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestNoTagsNoSnapshot covers the situation where a repository
|
// TestNoTagsNoSnapshot covers the situation where a repository
|
||||||
@ -76,7 +75,7 @@ func TestNoTagsNoSnapshot(t *testing.T) {
|
|||||||
testlib.GitCommit(t, "first")
|
testlib.GitCommit(t, "first")
|
||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
ctx.Snapshot = false
|
ctx.Snapshot = false
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), `git doesn't contain any tags. Either add a tag or use --snapshot`)
|
require.EqualError(t, Pipe{}.Run(ctx), `git doesn't contain any tags. Either add a tag or use --snapshot`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDirty(t *testing.T) {
|
func TestDirty(t *testing.T) {
|
||||||
@ -85,15 +84,15 @@ func TestDirty(t *testing.T) {
|
|||||||
testlib.GitInit(t)
|
testlib.GitInit(t)
|
||||||
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
||||||
dummy, err := os.Create(filepath.Join(folder, "dummy"))
|
dummy, err := os.Create(filepath.Join(folder, "dummy"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
testlib.GitAdd(t)
|
testlib.GitAdd(t)
|
||||||
testlib.GitCommit(t, "commit2")
|
testlib.GitCommit(t, "commit2")
|
||||||
testlib.GitTag(t, "v0.0.1")
|
testlib.GitTag(t, "v0.0.1")
|
||||||
assert.NoError(t, ioutil.WriteFile(dummy.Name(), []byte("lorem ipsum"), 0644))
|
require.NoError(t, ioutil.WriteFile(dummy.Name(), []byte("lorem ipsum"), 0644))
|
||||||
t.Run("all checks up", func(t *testing.T) {
|
t.Run("all checks up", func(t *testing.T) {
|
||||||
err = Pipe{}.Run(context.New(config.Project{}))
|
err = Pipe{}.Run(context.New(config.Project{}))
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "git is currently in a dirty state")
|
require.Contains(t, err.Error(), "git is currently in a dirty state")
|
||||||
})
|
})
|
||||||
t.Run("skip validate is set", func(t *testing.T) {
|
t.Run("skip validate is set", func(t *testing.T) {
|
||||||
ctx := context.New(config.Project{})
|
ctx := context.New(config.Project{})
|
||||||
@ -118,8 +117,8 @@ func TestTagIsNotLastCommit(t *testing.T) {
|
|||||||
testlib.GitTag(t, "v0.0.1")
|
testlib.GitTag(t, "v0.0.1")
|
||||||
testlib.GitCommit(t, "commit4")
|
testlib.GitCommit(t, "commit4")
|
||||||
err := Pipe{}.Run(context.New(config.Project{}))
|
err := Pipe{}.Run(context.New(config.Project{}))
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "git tag v0.0.1 was not made against commit")
|
require.Contains(t, err.Error(), "git tag v0.0.1 was not made against commit")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidState(t *testing.T) {
|
func TestValidState(t *testing.T) {
|
||||||
@ -132,9 +131,9 @@ func TestValidState(t *testing.T) {
|
|||||||
testlib.GitCommit(t, "commit4")
|
testlib.GitCommit(t, "commit4")
|
||||||
testlib.GitTag(t, "v0.0.2")
|
testlib.GitTag(t, "v0.0.2")
|
||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, "v0.0.2", ctx.Git.CurrentTag)
|
require.Equal(t, "v0.0.2", ctx.Git.CurrentTag)
|
||||||
assert.Equal(t, "git@github.com:foo/bar.git", ctx.Git.URL)
|
require.Equal(t, "git@github.com:foo/bar.git", ctx.Git.URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSnapshotNoTags(t *testing.T) {
|
func TestSnapshotNoTags(t *testing.T) {
|
||||||
@ -147,7 +146,7 @@ func TestSnapshotNoTags(t *testing.T) {
|
|||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
ctx.Snapshot = true
|
ctx.Snapshot = true
|
||||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, fakeInfo.CurrentTag, ctx.Git.CurrentTag)
|
require.Equal(t, fakeInfo.CurrentTag, ctx.Git.CurrentTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSnapshotNoCommits(t *testing.T) {
|
func TestSnapshotNoCommits(t *testing.T) {
|
||||||
@ -158,7 +157,7 @@ func TestSnapshotNoCommits(t *testing.T) {
|
|||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
ctx.Snapshot = true
|
ctx.Snapshot = true
|
||||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, fakeInfo, ctx.Git)
|
require.Equal(t, fakeInfo, ctx.Git)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSnapshotWithoutRepo(t *testing.T) {
|
func TestSnapshotWithoutRepo(t *testing.T) {
|
||||||
@ -167,7 +166,7 @@ func TestSnapshotWithoutRepo(t *testing.T) {
|
|||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
ctx.Snapshot = true
|
ctx.Snapshot = true
|
||||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, fakeInfo, ctx.Git)
|
require.Equal(t, fakeInfo, ctx.Git)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSnapshotDirty(t *testing.T) {
|
func TestSnapshotDirty(t *testing.T) {
|
||||||
@ -178,7 +177,7 @@ func TestSnapshotDirty(t *testing.T) {
|
|||||||
testlib.GitAdd(t)
|
testlib.GitAdd(t)
|
||||||
testlib.GitCommit(t, "whatever")
|
testlib.GitCommit(t, "whatever")
|
||||||
testlib.GitTag(t, "v0.0.1")
|
testlib.GitTag(t, "v0.0.1")
|
||||||
assert.NoError(t, ioutil.WriteFile(filepath.Join(folder, "foo"), []byte("foobar"), 0644))
|
require.NoError(t, ioutil.WriteFile(filepath.Join(folder, "foo"), []byte("foobar"), 0644))
|
||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
ctx.Snapshot = true
|
ctx.Snapshot = true
|
||||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||||
@ -187,10 +186,10 @@ func TestSnapshotDirty(t *testing.T) {
|
|||||||
func TestGitNotInPath(t *testing.T) {
|
func TestGitNotInPath(t *testing.T) {
|
||||||
var path = os.Getenv("PATH")
|
var path = os.Getenv("PATH")
|
||||||
defer func() {
|
defer func() {
|
||||||
assert.NoError(t, os.Setenv("PATH", path))
|
require.NoError(t, os.Setenv("PATH", path))
|
||||||
}()
|
}()
|
||||||
assert.NoError(t, os.Setenv("PATH", ""))
|
require.NoError(t, os.Setenv("PATH", ""))
|
||||||
assert.EqualError(t, Pipe{}.Run(context.New(config.Project{})), ErrNoGit.Error())
|
require.EqualError(t, Pipe{}.Run(context.New(config.Project{})), ErrNoGit.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTagFromCI(t *testing.T) {
|
func TestTagFromCI(t *testing.T) {
|
||||||
@ -222,8 +221,8 @@ func TestTagFromCI(t *testing.T) {
|
|||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, tc.expected, ctx.Git.CurrentTag)
|
require.Equal(t, tc.expected, ctx.Git.CurrentTag)
|
||||||
|
|
||||||
for name := range tc.envs {
|
for name := range tc.envs {
|
||||||
require.NoError(t, os.Setenv(name, ""))
|
require.NoError(t, os.Setenv(name, ""))
|
||||||
@ -244,7 +243,7 @@ func TestCommitDate(t *testing.T) {
|
|||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
require.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
||||||
assert.True(t, commitDate.Equal(ctx.Git.CommitDate), "commit date does not match expected")
|
require.True(t, commitDate.Equal(ctx.Git.CommitDate), "commit date does not match expected")
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDefaultWithRepoConfig(t *testing.T) {
|
func TestDefaultWithRepoConfig(t *testing.T) {
|
||||||
@ -32,9 +32,9 @@ func TestDefaultWithRepoConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "configrepo", ctx.Config.Milestones[0].Repo.Name)
|
require.Equal(t, "configrepo", ctx.Config.Milestones[0].Repo.Name)
|
||||||
assert.Equal(t, "configowner", ctx.Config.Milestones[0].Repo.Owner)
|
require.Equal(t, "configowner", ctx.Config.Milestones[0].Repo.Owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultWithRepoRemote(t *testing.T) {
|
func TestDefaultWithRepoRemote(t *testing.T) {
|
||||||
@ -45,9 +45,9 @@ func TestDefaultWithRepoRemote(t *testing.T) {
|
|||||||
|
|
||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "githubrepo", ctx.Config.Milestones[0].Repo.Name)
|
require.Equal(t, "githubrepo", ctx.Config.Milestones[0].Repo.Name)
|
||||||
assert.Equal(t, "githubowner", ctx.Config.Milestones[0].Repo.Owner)
|
require.Equal(t, "githubowner", ctx.Config.Milestones[0].Repo.Owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultWithNameTemplate(t *testing.T) {
|
func TestDefaultWithNameTemplate(t *testing.T) {
|
||||||
@ -60,8 +60,8 @@ func TestDefaultWithNameTemplate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "confignametemplate", ctx.Config.Milestones[0].NameTemplate)
|
require.Equal(t, "confignametemplate", ctx.Config.Milestones[0].NameTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultWithoutGitRepo(t *testing.T) {
|
func TestDefaultWithoutGitRepo(t *testing.T) {
|
||||||
@ -71,8 +71,8 @@ func TestDefaultWithoutGitRepo(t *testing.T) {
|
|||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
assert.EqualError(t, Pipe{}.Default(ctx), "current folder is not a git repository")
|
require.EqualError(t, Pipe{}.Default(ctx), "current folder is not a git repository")
|
||||||
assert.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
|
func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
|
||||||
@ -83,8 +83,8 @@ func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
testlib.GitInit(t)
|
testlib.GitInit(t)
|
||||||
assert.EqualError(t, Pipe{}.Default(ctx), "repository doesn't have an `origin` remote")
|
require.EqualError(t, Pipe{}.Default(ctx), "repository doesn't have an `origin` remote")
|
||||||
assert.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultWithoutGitRepoSnapshot(t *testing.T) {
|
func TestDefaultWithoutGitRepoSnapshot(t *testing.T) {
|
||||||
@ -95,8 +95,8 @@ func TestDefaultWithoutGitRepoSnapshot(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
ctx.Snapshot = true
|
ctx.Snapshot = true
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultWithoutNameTemplate(t *testing.T) {
|
func TestDefaultWithoutNameTemplate(t *testing.T) {
|
||||||
@ -105,12 +105,12 @@ func TestDefaultWithoutNameTemplate(t *testing.T) {
|
|||||||
Milestones: []config.Milestone{},
|
Milestones: []config.Milestone{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "{{ .Tag }}", ctx.Config.Milestones[0].NameTemplate)
|
require.Equal(t, "{{ .Tag }}", ctx.Config.Milestones[0].NameTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestString(t *testing.T) {
|
func TestString(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPublishCloseDisabled(t *testing.T) {
|
func TestPublishCloseDisabled(t *testing.T) {
|
||||||
@ -123,7 +123,7 @@ func TestPublishCloseDisabled(t *testing.T) {
|
|||||||
})
|
})
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
testlib.AssertSkipped(t, doPublish(ctx, client))
|
testlib.AssertSkipped(t, doPublish(ctx, client))
|
||||||
assert.Equal(t, "", client.ClosedMilestone)
|
require.Equal(t, "", client.ClosedMilestone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPublishCloseEnabled(t *testing.T) {
|
func TestPublishCloseEnabled(t *testing.T) {
|
||||||
@ -141,8 +141,8 @@ func TestPublishCloseEnabled(t *testing.T) {
|
|||||||
})
|
})
|
||||||
ctx.Git.CurrentTag = "v1.0.0"
|
ctx.Git.CurrentTag = "v1.0.0"
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
assert.NoError(t, doPublish(ctx, client))
|
require.NoError(t, doPublish(ctx, client))
|
||||||
assert.Equal(t, "v1.0.0", client.ClosedMilestone)
|
require.Equal(t, "v1.0.0", client.ClosedMilestone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPublishCloseError(t *testing.T) {
|
func TestPublishCloseError(t *testing.T) {
|
||||||
@ -163,8 +163,8 @@ func TestPublishCloseError(t *testing.T) {
|
|||||||
client := &DummyClient{
|
client := &DummyClient{
|
||||||
FailToCloseMilestone: true,
|
FailToCloseMilestone: true,
|
||||||
}
|
}
|
||||||
assert.NoError(t, doPublish(ctx, client))
|
require.NoError(t, doPublish(ctx, client))
|
||||||
assert.Equal(t, "", client.ClosedMilestone)
|
require.Equal(t, "", client.ClosedMilestone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPublishCloseFailOnError(t *testing.T) {
|
func TestPublishCloseFailOnError(t *testing.T) {
|
||||||
@ -186,8 +186,8 @@ func TestPublishCloseFailOnError(t *testing.T) {
|
|||||||
client := &DummyClient{
|
client := &DummyClient{
|
||||||
FailToCloseMilestone: true,
|
FailToCloseMilestone: true,
|
||||||
}
|
}
|
||||||
assert.Error(t, doPublish(ctx, client))
|
require.Error(t, doPublish(ctx, client))
|
||||||
assert.Equal(t, "", client.ClosedMilestone)
|
require.Equal(t, "", client.ClosedMilestone)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DummyClient struct {
|
type DummyClient struct {
|
||||||
|
@ -4,19 +4,19 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSkipPipe(t *testing.T) {
|
func TestSkipPipe(t *testing.T) {
|
||||||
var reason = "this is a test"
|
var reason = "this is a test"
|
||||||
var err = Skip(reason)
|
var err = Skip(reason)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Equal(t, reason, err.Error())
|
require.Equal(t, reason, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsSkip(t *testing.T) {
|
func TestIsSkip(t *testing.T) {
|
||||||
assert.True(t, IsSkip(Skip("whatever")))
|
require.True(t, IsSkip(Skip("whatever")))
|
||||||
assert.False(t, IsSkip(errors.New("nope")))
|
require.False(t, IsSkip(errors.New("nope")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSkipMemento(t *testing.T) {
|
func TestSkipMemento(t *testing.T) {
|
||||||
@ -26,10 +26,10 @@ func TestSkipMemento(t *testing.T) {
|
|||||||
// test duplicated errors
|
// test duplicated errors
|
||||||
m.Remember(Skip("dupe"))
|
m.Remember(Skip("dupe"))
|
||||||
m.Remember(Skip("dupe"))
|
m.Remember(Skip("dupe"))
|
||||||
assert.EqualError(t, m.Evaluate(), `foo, bar, dupe`)
|
require.EqualError(t, m.Evaluate(), `foo, bar, dupe`)
|
||||||
assert.True(t, IsSkip(m.Evaluate()))
|
require.True(t, IsSkip(m.Evaluate()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSkipMementoNoErrors(t *testing.T) {
|
func TestSkipMementoNoErrors(t *testing.T) {
|
||||||
assert.NoError(t, (&SkipMemento{}).Evaluate())
|
require.NoError(t, (&SkipMemento{}).Evaluate())
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var update = flag.Bool("update", false, "update .golden files")
|
var update = flag.Bool("update", false, "update .golden files")
|
||||||
@ -28,15 +28,15 @@ func TestDescribeBody(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
out, err := describeBody(ctx)
|
out, err := describeBody(ctx)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var golden = "testdata/release1.golden"
|
var golden = "testdata/release1.golden"
|
||||||
if *update {
|
if *update {
|
||||||
_ = ioutil.WriteFile(golden, out.Bytes(), 0755)
|
_ = ioutil.WriteFile(golden, out.Bytes(), 0755)
|
||||||
}
|
}
|
||||||
bts, err := ioutil.ReadFile(golden)
|
bts, err := ioutil.ReadFile(golden)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, string(bts), out.String())
|
require.Equal(t, string(bts), out.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDescribeBodyNoDockerImagesNoBrews(t *testing.T) {
|
func TestDescribeBodyNoDockerImagesNoBrews(t *testing.T) {
|
||||||
@ -45,16 +45,16 @@ func TestDescribeBodyNoDockerImagesNoBrews(t *testing.T) {
|
|||||||
ReleaseNotes: changelog,
|
ReleaseNotes: changelog,
|
||||||
}
|
}
|
||||||
out, err := describeBody(ctx)
|
out, err := describeBody(ctx)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var golden = "testdata/release2.golden"
|
var golden = "testdata/release2.golden"
|
||||||
if *update {
|
if *update {
|
||||||
_ = ioutil.WriteFile(golden, out.Bytes(), 0655)
|
_ = ioutil.WriteFile(golden, out.Bytes(), 0655)
|
||||||
}
|
}
|
||||||
bts, err := ioutil.ReadFile(golden)
|
bts, err := ioutil.ReadFile(golden)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, string(bts), out.String())
|
require.Equal(t, string(bts), out.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDontEscapeHTML(t *testing.T) {
|
func TestDontEscapeHTML(t *testing.T) {
|
||||||
@ -63,6 +63,6 @@ func TestDontEscapeHTML(t *testing.T) {
|
|||||||
ctx.ReleaseNotes = changelog
|
ctx.ReleaseNotes = changelog
|
||||||
|
|
||||||
out, err := describeBody(ctx)
|
out, err := describeBody(ctx)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Contains(t, out.String(), changelog)
|
require.Contains(t, out.String(), changelog)
|
||||||
}
|
}
|
||||||
|
@ -15,26 +15,26 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPipeDescription(t *testing.T) {
|
func TestPipeDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
|
func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
srcfile, err := os.Create(filepath.Join(folder, "source.tar.gz"))
|
srcfile, err := os.Create(filepath.Join(folder, "source.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
filteredtarfile, err := os.Create(filepath.Join(folder, "filtered.tar.gz"))
|
filteredtarfile, err := os.Create(filepath.Join(folder, "filtered.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
filtereddebfile, err := os.Create(filepath.Join(folder, "filtered.deb"))
|
filtereddebfile, err := os.Create(filepath.Join(folder, "filtered.deb"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
@ -88,27 +88,27 @@ func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
assert.NoError(t, doPublish(ctx, client))
|
require.NoError(t, doPublish(ctx, client))
|
||||||
assert.True(t, client.CreatedRelease)
|
require.True(t, client.CreatedRelease)
|
||||||
assert.True(t, client.UploadedFile)
|
require.True(t, client.UploadedFile)
|
||||||
assert.Contains(t, client.UploadedFileNames, "source.tar.gz")
|
require.Contains(t, client.UploadedFileNames, "source.tar.gz")
|
||||||
assert.Contains(t, client.UploadedFileNames, "bin.deb")
|
require.Contains(t, client.UploadedFileNames, "bin.deb")
|
||||||
assert.Contains(t, client.UploadedFileNames, "bin.tar.gz")
|
require.Contains(t, client.UploadedFileNames, "bin.tar.gz")
|
||||||
assert.Contains(t, client.UploadedFileNames, "filtered.deb")
|
require.Contains(t, client.UploadedFileNames, "filtered.deb")
|
||||||
assert.Contains(t, client.UploadedFileNames, "filtered.tar.gz")
|
require.Contains(t, client.UploadedFileNames, "filtered.tar.gz")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeWithIDsThenFilters(t *testing.T) {
|
func TestRunPipeWithIDsThenFilters(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
filteredtarfile, err := os.Create(filepath.Join(folder, "filtered.tar.gz"))
|
filteredtarfile, err := os.Create(filepath.Join(folder, "filtered.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
filtereddebfile, err := os.Create(filepath.Join(folder, "filtered.deb"))
|
filtereddebfile, err := os.Create(filepath.Join(folder, "filtered.deb"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
@ -158,16 +158,16 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
assert.NoError(t, doPublish(ctx, client))
|
require.NoError(t, doPublish(ctx, client))
|
||||||
assert.True(t, client.CreatedRelease)
|
require.True(t, client.CreatedRelease)
|
||||||
assert.True(t, client.UploadedFile)
|
require.True(t, client.UploadedFile)
|
||||||
assert.Contains(t, client.UploadedFileNames, "bin.deb")
|
require.Contains(t, client.UploadedFileNames, "bin.deb")
|
||||||
assert.Contains(t, client.UploadedFileNames, "bin.tar.gz")
|
require.Contains(t, client.UploadedFileNames, "bin.tar.gz")
|
||||||
assert.Contains(t, client.UploadedFileNames, "release1.golden")
|
require.Contains(t, client.UploadedFileNames, "release1.golden")
|
||||||
assert.Contains(t, client.UploadedFileNames, "release2.golden")
|
require.Contains(t, client.UploadedFileNames, "release2.golden")
|
||||||
assert.Contains(t, client.UploadedFileNames, "f1")
|
require.Contains(t, client.UploadedFileNames, "f1")
|
||||||
assert.NotContains(t, client.UploadedFileNames, "filtered.deb")
|
require.NotContains(t, client.UploadedFileNames, "filtered.deb")
|
||||||
assert.NotContains(t, client.UploadedFileNames, "filtered.tar.gz")
|
require.NotContains(t, client.UploadedFileNames, "filtered.tar.gz")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeReleaseCreationFailed(t *testing.T) {
|
func TestRunPipeReleaseCreationFailed(t *testing.T) {
|
||||||
@ -184,9 +184,9 @@ func TestRunPipeReleaseCreationFailed(t *testing.T) {
|
|||||||
client := &DummyClient{
|
client := &DummyClient{
|
||||||
FailToCreateRelease: true,
|
FailToCreateRelease: true,
|
||||||
}
|
}
|
||||||
assert.Error(t, doPublish(ctx, client))
|
require.Error(t, doPublish(ctx, client))
|
||||||
assert.False(t, client.CreatedRelease)
|
require.False(t, client.CreatedRelease)
|
||||||
assert.False(t, client.UploadedFile)
|
require.False(t, client.UploadedFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeWithFileThatDontExist(t *testing.T) {
|
func TestRunPipeWithFileThatDontExist(t *testing.T) {
|
||||||
@ -206,16 +206,16 @@ func TestRunPipeWithFileThatDontExist(t *testing.T) {
|
|||||||
Path: "/nope/nope/nope",
|
Path: "/nope/nope/nope",
|
||||||
})
|
})
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
assert.Error(t, doPublish(ctx, client))
|
require.Error(t, doPublish(ctx, client))
|
||||||
assert.True(t, client.CreatedRelease)
|
require.True(t, client.CreatedRelease)
|
||||||
assert.False(t, client.UploadedFile)
|
require.False(t, client.UploadedFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeUploadFailure(t *testing.T) {
|
func TestRunPipeUploadFailure(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
Release: config.Release{
|
Release: config.Release{
|
||||||
GitHub: config.Repo{
|
GitHub: config.Repo{
|
||||||
@ -234,9 +234,9 @@ func TestRunPipeUploadFailure(t *testing.T) {
|
|||||||
client := &DummyClient{
|
client := &DummyClient{
|
||||||
FailToUpload: true,
|
FailToUpload: true,
|
||||||
}
|
}
|
||||||
assert.EqualError(t, doPublish(ctx, client), "failed to upload bin.tar.gz after 1 tries: upload failed")
|
require.EqualError(t, doPublish(ctx, client), "failed to upload bin.tar.gz after 1 tries: upload failed")
|
||||||
assert.True(t, client.CreatedRelease)
|
require.True(t, client.CreatedRelease)
|
||||||
assert.False(t, client.UploadedFile)
|
require.False(t, client.UploadedFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeExtraFileNotFound(t *testing.T) {
|
func TestRunPipeExtraFileNotFound(t *testing.T) {
|
||||||
@ -255,9 +255,9 @@ func TestRunPipeExtraFileNotFound(t *testing.T) {
|
|||||||
var ctx = context.New(config)
|
var ctx = context.New(config)
|
||||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
assert.EqualError(t, doPublish(ctx, client), "globbing failed for pattern ./nope: file does not exist")
|
require.EqualError(t, doPublish(ctx, client), "globbing failed for pattern ./nope: file does not exist")
|
||||||
assert.True(t, client.CreatedRelease)
|
require.True(t, client.CreatedRelease)
|
||||||
assert.False(t, client.UploadedFile)
|
require.False(t, client.UploadedFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeExtraOverride(t *testing.T) {
|
func TestRunPipeExtraOverride(t *testing.T) {
|
||||||
@ -276,18 +276,18 @@ func TestRunPipeExtraOverride(t *testing.T) {
|
|||||||
var ctx = context.New(config)
|
var ctx = context.New(config)
|
||||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
assert.NoError(t, doPublish(ctx, client))
|
require.NoError(t, doPublish(ctx, client))
|
||||||
assert.True(t, client.CreatedRelease)
|
require.True(t, client.CreatedRelease)
|
||||||
assert.True(t, client.UploadedFile)
|
require.True(t, client.UploadedFile)
|
||||||
assert.Contains(t, client.UploadedFileNames, "f1")
|
require.Contains(t, client.UploadedFileNames, "f1")
|
||||||
assert.True(t, strings.HasSuffix(client.UploadedFilePaths["f1"], "testdata/upload_same_name/f1"))
|
require.True(t, strings.HasSuffix(client.UploadedFilePaths["f1"], "testdata/upload_same_name/f1"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeUploadRetry(t *testing.T) {
|
func TestRunPipeUploadRetry(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
Release: config.Release{
|
Release: config.Release{
|
||||||
GitHub: config.Repo{
|
GitHub: config.Repo{
|
||||||
@ -306,9 +306,9 @@ func TestRunPipeUploadRetry(t *testing.T) {
|
|||||||
client := &DummyClient{
|
client := &DummyClient{
|
||||||
FailFirstUpload: true,
|
FailFirstUpload: true,
|
||||||
}
|
}
|
||||||
assert.NoError(t, doPublish(ctx, client))
|
require.NoError(t, doPublish(ctx, client))
|
||||||
assert.True(t, client.CreatedRelease)
|
require.True(t, client.CreatedRelease)
|
||||||
assert.True(t, client.UploadedFile)
|
require.True(t, client.UploadedFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPipeDisabled(t *testing.T) {
|
func TestPipeDisabled(t *testing.T) {
|
||||||
@ -319,8 +319,8 @@ func TestPipeDisabled(t *testing.T) {
|
|||||||
})
|
})
|
||||||
client := &DummyClient{}
|
client := &DummyClient{}
|
||||||
testlib.AssertSkipped(t, doPublish(ctx, client))
|
testlib.AssertSkipped(t, doPublish(ctx, client))
|
||||||
assert.False(t, client.CreatedRelease)
|
require.False(t, client.CreatedRelease)
|
||||||
assert.False(t, client.UploadedFile)
|
require.False(t, client.UploadedFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefault(t *testing.T) {
|
func TestDefault(t *testing.T) {
|
||||||
@ -331,9 +331,9 @@ func TestDefault(t *testing.T) {
|
|||||||
|
|
||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
||||||
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultWithGitlab(t *testing.T) {
|
func TestDefaultWithGitlab(t *testing.T) {
|
||||||
@ -344,9 +344,9 @@ func TestDefaultWithGitlab(t *testing.T) {
|
|||||||
|
|
||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
ctx.TokenType = context.TokenTypeGitLab
|
ctx.TokenType = context.TokenTypeGitLab
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "gitlabrepo", ctx.Config.Release.GitLab.Name)
|
require.Equal(t, "gitlabrepo", ctx.Config.Release.GitLab.Name)
|
||||||
assert.Equal(t, "gitlabowner", ctx.Config.Release.GitLab.Owner)
|
require.Equal(t, "gitlabowner", ctx.Config.Release.GitLab.Owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultWithGitea(t *testing.T) {
|
func TestDefaultWithGitea(t *testing.T) {
|
||||||
@ -357,9 +357,9 @@ func TestDefaultWithGitea(t *testing.T) {
|
|||||||
|
|
||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
ctx.TokenType = context.TokenTypeGitea
|
ctx.TokenType = context.TokenTypeGitea
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "gitearepo", ctx.Config.Release.Gitea.Name)
|
require.Equal(t, "gitearepo", ctx.Config.Release.Gitea.Name)
|
||||||
assert.Equal(t, "giteaowner", ctx.Config.Release.Gitea.Owner)
|
require.Equal(t, "giteaowner", ctx.Config.Release.Gitea.Owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultPreReleaseAuto(t *testing.T) {
|
func TestDefaultPreReleaseAuto(t *testing.T) {
|
||||||
@ -380,8 +380,8 @@ func TestDefaultPreReleaseAuto(t *testing.T) {
|
|||||||
Minor: 0,
|
Minor: 0,
|
||||||
Patch: 0,
|
Patch: 0,
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, false, ctx.PreRelease)
|
require.Equal(t, false, ctx.PreRelease)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("auto-rc", func(t *testing.T) {
|
t.Run("auto-rc", func(t *testing.T) {
|
||||||
@ -397,8 +397,8 @@ func TestDefaultPreReleaseAuto(t *testing.T) {
|
|||||||
Patch: 0,
|
Patch: 0,
|
||||||
Prerelease: "rc1",
|
Prerelease: "rc1",
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, true, ctx.PreRelease)
|
require.Equal(t, true, ctx.PreRelease)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("auto-rc-github-setup", func(t *testing.T) {
|
t.Run("auto-rc-github-setup", func(t *testing.T) {
|
||||||
@ -418,8 +418,8 @@ func TestDefaultPreReleaseAuto(t *testing.T) {
|
|||||||
Patch: 0,
|
Patch: 0,
|
||||||
Prerelease: "rc1",
|
Prerelease: "rc1",
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, true, ctx.PreRelease)
|
require.Equal(t, true, ctx.PreRelease)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,9 +435,9 @@ func TestDefaultPipeDisabled(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
||||||
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultFilled(t *testing.T) {
|
func TestDefaultFilled(t *testing.T) {
|
||||||
@ -457,9 +457,9 @@ func TestDefaultFilled(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "foo", ctx.Config.Release.GitHub.Name)
|
require.Equal(t, "foo", ctx.Config.Release.GitHub.Name)
|
||||||
assert.Equal(t, "bar", ctx.Config.Release.GitHub.Owner)
|
require.Equal(t, "bar", ctx.Config.Release.GitHub.Owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultNotAGitRepo(t *testing.T) {
|
func TestDefaultNotAGitRepo(t *testing.T) {
|
||||||
@ -469,8 +469,8 @@ func TestDefaultNotAGitRepo(t *testing.T) {
|
|||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
assert.EqualError(t, Pipe{}.Default(ctx), "current folder is not a git repository")
|
require.EqualError(t, Pipe{}.Default(ctx), "current folder is not a git repository")
|
||||||
assert.Empty(t, ctx.Config.Release.GitHub.String())
|
require.Empty(t, ctx.Config.Release.GitHub.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultGitRepoWithoutOrigin(t *testing.T) {
|
func TestDefaultGitRepoWithoutOrigin(t *testing.T) {
|
||||||
@ -481,8 +481,8 @@ func TestDefaultGitRepoWithoutOrigin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
testlib.GitInit(t)
|
testlib.GitInit(t)
|
||||||
assert.EqualError(t, Pipe{}.Default(ctx), "repository doesn't have an `origin` remote")
|
require.EqualError(t, Pipe{}.Default(ctx), "repository doesn't have an `origin` remote")
|
||||||
assert.Empty(t, ctx.Config.Release.GitHub.String())
|
require.Empty(t, ctx.Config.Release.GitHub.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultNotAGitRepoSnapshot(t *testing.T) {
|
func TestDefaultNotAGitRepoSnapshot(t *testing.T) {
|
||||||
@ -493,8 +493,8 @@ func TestDefaultNotAGitRepoSnapshot(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
ctx.Snapshot = true
|
ctx.Snapshot = true
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Empty(t, ctx.Config.Release.GitHub.String())
|
require.Empty(t, ctx.Config.Release.GitHub.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultGitRepoWithoutRemote(t *testing.T) {
|
func TestDefaultGitRepoWithoutRemote(t *testing.T) {
|
||||||
@ -504,8 +504,8 @@ func TestDefaultGitRepoWithoutRemote(t *testing.T) {
|
|||||||
Config: config.Project{},
|
Config: config.Project{},
|
||||||
}
|
}
|
||||||
ctx.TokenType = context.TokenTypeGitHub
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
assert.Error(t, Pipe{}.Default(ctx))
|
require.Error(t, Pipe{}.Default(ctx))
|
||||||
assert.Empty(t, ctx.Config.Release.GitHub.String())
|
require.Empty(t, ctx.Config.Release.GitHub.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultMultipleReleasesDefined(t *testing.T) {
|
func TestDefaultMultipleReleasesDefined(t *testing.T) {
|
||||||
@ -525,7 +525,7 @@ func TestDefaultMultipleReleasesDefined(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.EqualError(t, Pipe{}.Default(ctx), ErrMultipleReleases.Error())
|
require.EqualError(t, Pipe{}.Default(ctx), ErrMultipleReleases.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
type DummyClient struct {
|
type DummyClient struct {
|
||||||
|
@ -14,14 +14,13 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var update = flag.Bool("update", false, "update .golden files")
|
var update = flag.Bool("update", false, "update .golden files")
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefault(t *testing.T) {
|
func TestDefault(t *testing.T) {
|
||||||
@ -54,11 +53,11 @@ func TestDefault(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, ctx.Config.ProjectName, ctx.Config.Scoop.Name)
|
require.Equal(t, ctx.Config.ProjectName, ctx.Config.Scoop.Name)
|
||||||
assert.NotEmpty(t, ctx.Config.Scoop.CommitAuthor.Name)
|
require.NotEmpty(t, ctx.Config.Scoop.CommitAuthor.Name)
|
||||||
assert.NotEmpty(t, ctx.Config.Scoop.CommitAuthor.Email)
|
require.NotEmpty(t, ctx.Config.Scoop.CommitAuthor.Email)
|
||||||
assert.NotEmpty(t, ctx.Config.Scoop.CommitMessageTemplate)
|
require.NotEmpty(t, ctx.Config.Scoop.CommitMessageTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_doRun(t *testing.T) {
|
func Test_doRun(t *testing.T) {
|
||||||
@ -70,12 +69,12 @@ func Test_doRun(t *testing.T) {
|
|||||||
type errChecker func(*testing.T, error)
|
type errChecker func(*testing.T, error)
|
||||||
var shouldErr = func(msg string) errChecker {
|
var shouldErr = func(msg string) errChecker {
|
||||||
return func(t *testing.T, err error) {
|
return func(t *testing.T, err error) {
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.EqualError(t, err, msg)
|
require.EqualError(t, err, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var shouldNotErr = func(t *testing.T, err error) {
|
var shouldNotErr = func(t *testing.T, err error) {
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
type args struct {
|
type args struct {
|
||||||
ctx *context.Context
|
ctx *context.Context
|
||||||
|
@ -7,12 +7,11 @@ import (
|
|||||||
|
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidSemver(t *testing.T) {
|
func TestValidSemver(t *testing.T) {
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSignDefault(t *testing.T) {
|
func TestSignDefault(t *testing.T) {
|
||||||
@ -50,11 +49,11 @@ func TestSignDefault(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
err := Pipe{}.Default(ctx)
|
err := Pipe{}.Default(ctx)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, ctx.Config.Signs[0].Cmd, "gpg")
|
require.Equal(t, ctx.Config.Signs[0].Cmd, "gpg")
|
||||||
assert.Equal(t, ctx.Config.Signs[0].Signature, "${artifact}.sig")
|
require.Equal(t, ctx.Config.Signs[0].Signature, "${artifact}.sig")
|
||||||
assert.Equal(t, ctx.Config.Signs[0].Args, []string{"--output", "$signature", "--detach-sig", "$artifact"})
|
require.Equal(t, ctx.Config.Signs[0].Args, []string{"--output", "$signature", "--detach-sig", "$artifact"})
|
||||||
assert.Equal(t, ctx.Config.Signs[0].Artifacts, "none")
|
require.Equal(t, ctx.Config.Signs[0].Artifacts, "none")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSignDisabled(t *testing.T) {
|
func TestSignDisabled(t *testing.T) {
|
||||||
@ -63,14 +62,14 @@ func TestSignDisabled(t *testing.T) {
|
|||||||
{Artifacts: "none"},
|
{Artifacts: "none"},
|
||||||
}
|
}
|
||||||
err := Pipe{}.Run(ctx)
|
err := Pipe{}.Run(ctx)
|
||||||
assert.EqualError(t, err, "artifact signing is disabled")
|
require.EqualError(t, err, "artifact signing is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSignSkipped(t *testing.T) {
|
func TestSignSkipped(t *testing.T) {
|
||||||
ctx := context.New(config.Project{})
|
ctx := context.New(config.Project{})
|
||||||
ctx.SkipSign = true
|
ctx.SkipSign = true
|
||||||
err := Pipe{}.Run(ctx)
|
err := Pipe{}.Run(ctx)
|
||||||
assert.EqualError(t, err, "artifact signing is disabled")
|
require.EqualError(t, err, "artifact signing is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSignInvalidArtifacts(t *testing.T) {
|
func TestSignInvalidArtifacts(t *testing.T) {
|
||||||
@ -79,7 +78,7 @@ func TestSignInvalidArtifacts(t *testing.T) {
|
|||||||
{Artifacts: "foo"},
|
{Artifacts: "foo"},
|
||||||
}
|
}
|
||||||
err := Pipe{}.Run(ctx)
|
err := Pipe{}.Run(ctx)
|
||||||
assert.EqualError(t, err, "invalid list of artifacts to sign: foo")
|
require.EqualError(t, err, "invalid list of artifacts to sign: foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSignArtifacts(t *testing.T) {
|
func TestSignArtifacts(t *testing.T) {
|
||||||
@ -384,7 +383,7 @@ func TestSignArtifacts(t *testing.T) {
|
|||||||
func testSign(t *testing.T, ctx *context.Context, signaturePaths []string, signatureNames []string, user, expectedErrMsg string) {
|
func testSign(t *testing.T, ctx *context.Context, signaturePaths []string, signatureNames []string, user, expectedErrMsg string) {
|
||||||
// create temp dir for file and signature
|
// create temp dir for file and signature
|
||||||
tmpdir, err := ioutil.TempDir("", "goreleaser")
|
tmpdir, err := ioutil.TempDir("", "goreleaser")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
ctx.Config.Dist = tmpdir
|
ctx.Config.Dist = tmpdir
|
||||||
@ -392,14 +391,14 @@ func testSign(t *testing.T, ctx *context.Context, signaturePaths []string, signa
|
|||||||
// create some fake artifacts
|
// create some fake artifacts
|
||||||
var artifacts = []string{"artifact1", "artifact2", "artifact3", "checksum", "checksum2"}
|
var artifacts = []string{"artifact1", "artifact2", "artifact3", "checksum", "checksum2"}
|
||||||
err = os.Mkdir(filepath.Join(tmpdir, "linux_amd64"), os.ModePerm)
|
err = os.Mkdir(filepath.Join(tmpdir, "linux_amd64"), os.ModePerm)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
for _, f := range artifacts {
|
for _, f := range artifacts {
|
||||||
file := filepath.Join(tmpdir, f)
|
file := filepath.Join(tmpdir, f)
|
||||||
assert.NoError(t, ioutil.WriteFile(file, []byte("foo"), 0644))
|
require.NoError(t, ioutil.WriteFile(file, []byte("foo"), 0644))
|
||||||
}
|
}
|
||||||
assert.NoError(t, ioutil.WriteFile(filepath.Join(tmpdir, "linux_amd64", "artifact4"), []byte("foo"), 0644))
|
require.NoError(t, ioutil.WriteFile(filepath.Join(tmpdir, "linux_amd64", "artifact4"), []byte("foo"), 0644))
|
||||||
artifacts = append(artifacts, "linux_amd64/artifact4")
|
artifacts = append(artifacts, "linux_amd64/artifact4")
|
||||||
assert.NoError(t, ioutil.WriteFile(filepath.Join(tmpdir, "artifact5.tar.gz"), []byte("foo"), 0644))
|
require.NoError(t, ioutil.WriteFile(filepath.Join(tmpdir, "artifact5.tar.gz"), []byte("foo"), 0644))
|
||||||
artifacts = append(artifacts, "artifact5.tar.gz")
|
artifacts = append(artifacts, "artifact5.tar.gz")
|
||||||
ctx.Artifacts.Add(&artifact.Artifact{
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
Name: "artifact1",
|
Name: "artifact1",
|
||||||
@ -451,7 +450,7 @@ func testSign(t *testing.T, ctx *context.Context, signaturePaths []string, signa
|
|||||||
|
|
||||||
// configure the pipeline
|
// configure the pipeline
|
||||||
// make sure we are using the test keyring
|
// make sure we are using the test keyring
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
for i := range ctx.Config.Signs {
|
for i := range ctx.Config.Signs {
|
||||||
ctx.Config.Signs[i].Args = append(
|
ctx.Config.Signs[i].Args = append(
|
||||||
[]string{"--homedir", keyring},
|
[]string{"--homedir", keyring},
|
||||||
@ -461,15 +460,15 @@ func testSign(t *testing.T, ctx *context.Context, signaturePaths []string, signa
|
|||||||
|
|
||||||
// run the pipeline
|
// run the pipeline
|
||||||
if expectedErrMsg != "" {
|
if expectedErrMsg != "" {
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), expectedErrMsg)
|
require.EqualError(t, Pipe{}.Run(ctx), expectedErrMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
|
|
||||||
// ensure all artifacts have an ID
|
// ensure all artifacts have an ID
|
||||||
for _, arti := range ctx.Artifacts.Filter(artifact.ByType(artifact.Signature)).List() {
|
for _, arti := range ctx.Artifacts.Filter(artifact.ByType(artifact.Signature)).List() {
|
||||||
assert.NotEmptyf(t, arti.ExtraOr("ID", ""), ".Extra.ID on %s", arti.Path)
|
require.NotEmptyf(t, arti.ExtraOr("ID", ""), ".Extra.ID on %s", arti.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify that only the artifacts and the signatures are in the dist dir
|
// verify that only the artifacts and the signatures are in the dist dir
|
||||||
@ -490,11 +489,11 @@ func testSign(t *testing.T, ctx *context.Context, signaturePaths []string, signa
|
|||||||
gotFiles = append(gotFiles, relPath)
|
gotFiles = append(gotFiles, relPath)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
wantFiles := append(artifacts, signaturePaths...)
|
wantFiles := append(artifacts, signaturePaths...)
|
||||||
sort.Strings(wantFiles)
|
sort.Strings(wantFiles)
|
||||||
assert.ElementsMatch(t, wantFiles, gotFiles)
|
require.ElementsMatch(t, wantFiles, gotFiles)
|
||||||
|
|
||||||
// verify the signatures
|
// verify the signatures
|
||||||
for _, sig := range signaturePaths {
|
for _, sig := range signaturePaths {
|
||||||
@ -506,7 +505,7 @@ func testSign(t *testing.T, ctx *context.Context, signaturePaths []string, signa
|
|||||||
signArtifacts = append(signArtifacts, sig.Name)
|
signArtifacts = append(signArtifacts, sig.Name)
|
||||||
}
|
}
|
||||||
// check signature is an artifact
|
// check signature is an artifact
|
||||||
assert.ElementsMatch(t, signArtifacts, signatureNames)
|
require.ElementsMatch(t, signArtifacts, signatureNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifySignature(t *testing.T, ctx *context.Context, sig string, user string) {
|
func verifySignature(t *testing.T, ctx *context.Context, sig string, user string) {
|
||||||
@ -515,7 +514,7 @@ func verifySignature(t *testing.T, ctx *context.Context, sig string, user string
|
|||||||
// verify signature was made with key for usesr 'nopass'
|
// verify signature was made with key for usesr 'nopass'
|
||||||
cmd := exec.Command("gpg", "--homedir", keyring, "--verify", filepath.Join(ctx.Config.Dist, sig), filepath.Join(ctx.Config.Dist, artifact))
|
cmd := exec.Command("gpg", "--homedir", keyring, "--verify", filepath.Join(ctx.Config.Dist, sig), filepath.Join(ctx.Config.Dist, artifact))
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// check if the signature matches the user we expect to do this properly we
|
// check if the signature matches the user we expect to do this properly we
|
||||||
// might need to have either separate keyrings or export the key from the
|
// might need to have either separate keyrings or export the key from the
|
||||||
|
@ -6,11 +6,11 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStringer(t *testing.T) {
|
func TestStringer(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
func TestDefault(t *testing.T) {
|
func TestDefault(t *testing.T) {
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
@ -18,8 +18,8 @@ func TestDefault(t *testing.T) {
|
|||||||
Snapshot: config.Snapshot{},
|
Snapshot: config.Snapshot{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "{{ .Tag }}-SNAPSHOT-{{ .ShortCommit }}", ctx.Config.Snapshot.NameTemplate)
|
require.Equal(t, "{{ .Tag }}-SNAPSHOT-{{ .ShortCommit }}", ctx.Config.Snapshot.NameTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultSet(t *testing.T) {
|
func TestDefaultSet(t *testing.T) {
|
||||||
@ -30,8 +30,8 @@ func TestDefaultSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Equal(t, "snap", ctx.Config.Snapshot.NameTemplate)
|
require.Equal(t, "snap", ctx.Config.Snapshot.NameTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSnapshotInvalidNametemplate(t *testing.T) {
|
func TestSnapshotInvalidNametemplate(t *testing.T) {
|
||||||
@ -41,7 +41,7 @@ func TestSnapshotInvalidNametemplate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
ctx.Snapshot = true
|
ctx.Snapshot = true
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), `failed to generate snapshot name: template: tmpl:1: unexpected "}" in operand`)
|
require.EqualError(t, Pipe{}.Run(ctx), `failed to generate snapshot name: template: tmpl:1: unexpected "}" in operand`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSnapshotEmptyFinalName(t *testing.T) {
|
func TestSnapshotEmptyFinalName(t *testing.T) {
|
||||||
@ -52,7 +52,7 @@ func TestSnapshotEmptyFinalName(t *testing.T) {
|
|||||||
})
|
})
|
||||||
ctx.Snapshot = true
|
ctx.Snapshot = true
|
||||||
ctx.Git.CurrentTag = "v1.2.3"
|
ctx.Git.CurrentTag = "v1.2.3"
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), "empty snapshot name")
|
require.EqualError(t, Pipe{}.Run(ctx), "empty snapshot name")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotASnapshot(t *testing.T) {
|
func TestNotASnapshot(t *testing.T) {
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -57,14 +57,14 @@ func TestRunPipe_ModeBinary(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||||
d1 := []byte("hello\ngo\n")
|
d1 := []byte("hello\ngo\n")
|
||||||
err = ioutil.WriteFile(binPath, d1, 0666)
|
err = ioutil.WriteFile(binPath, d1, 0666)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Dummy http server
|
// Dummy http server
|
||||||
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -141,7 +141,7 @@ func TestRunPipe_ModeBinary(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Publish(ctx))
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_ModeArchive(t *testing.T) {
|
func TestRunPipe_ModeArchive(t *testing.T) {
|
||||||
@ -149,11 +149,11 @@ func TestRunPipe_ModeArchive(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
ProjectName: "goreleaser",
|
ProjectName: "goreleaser",
|
||||||
@ -208,11 +208,11 @@ func TestRunPipe_ModeArchive(t *testing.T) {
|
|||||||
uploads.Store("deb", true)
|
uploads.Store("deb", true)
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Publish(ctx))
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
_, ok := uploads.Load("targz")
|
_, ok := uploads.Load("targz")
|
||||||
assert.True(t, ok, "tar.gz file was not uploaded")
|
require.True(t, ok, "tar.gz file was not uploaded")
|
||||||
_, ok = uploads.Load("deb")
|
_, ok = uploads.Load("deb")
|
||||||
assert.True(t, ok, "deb file was not uploaded")
|
require.True(t, ok, "deb file was not uploaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_ModeBinary_CustomArtifactName(t *testing.T) {
|
func TestRunPipe_ModeBinary_CustomArtifactName(t *testing.T) {
|
||||||
@ -220,14 +220,14 @@ func TestRunPipe_ModeBinary_CustomArtifactName(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||||
d1 := []byte("hello\ngo\n")
|
d1 := []byte("hello\ngo\n")
|
||||||
err = ioutil.WriteFile(binPath, d1, 0666)
|
err = ioutil.WriteFile(binPath, d1, 0666)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Dummy http server
|
// Dummy http server
|
||||||
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin;deb.distribution=xenial", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin;deb.distribution=xenial", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -279,7 +279,7 @@ func TestRunPipe_ModeBinary_CustomArtifactName(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Publish(ctx))
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_ModeArchive_CustomArtifactName(t *testing.T) {
|
func TestRunPipe_ModeArchive_CustomArtifactName(t *testing.T) {
|
||||||
@ -287,11 +287,11 @@ func TestRunPipe_ModeArchive_CustomArtifactName(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
ProjectName: "goreleaser",
|
ProjectName: "goreleaser",
|
||||||
@ -347,18 +347,18 @@ func TestRunPipe_ModeArchive_CustomArtifactName(t *testing.T) {
|
|||||||
uploads.Store("deb", true)
|
uploads.Store("deb", true)
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, Pipe{}.Publish(ctx))
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
_, ok := uploads.Load("targz")
|
_, ok := uploads.Load("targz")
|
||||||
assert.True(t, ok, "tar.gz file was not uploaded")
|
require.True(t, ok, "tar.gz file was not uploaded")
|
||||||
_, ok = uploads.Load("deb")
|
_, ok = uploads.Load("deb")
|
||||||
assert.True(t, ok, "deb file was not uploaded")
|
require.True(t, ok, "deb file was not uploaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_ArtifactoryDown(t *testing.T) {
|
func TestRunPipe_ArtifactoryDown(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
ProjectName: "goreleaser",
|
ProjectName: "goreleaser",
|
||||||
@ -383,13 +383,13 @@ func TestRunPipe_ArtifactoryDown(t *testing.T) {
|
|||||||
Path: tarfile.Name(),
|
Path: tarfile.Name(),
|
||||||
})
|
})
|
||||||
err = Pipe{}.Publish(ctx)
|
err = Pipe{}.Publish(ctx)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "connection refused")
|
require.Contains(t, err.Error(), "connection refused")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_TargetTemplateError(t *testing.T) {
|
func TestRunPipe_TargetTemplateError(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||||
|
|
||||||
@ -421,8 +421,8 @@ func TestRunPipe_TargetTemplateError(t *testing.T) {
|
|||||||
Type: artifact.UploadableBinary,
|
Type: artifact.UploadableBinary,
|
||||||
})
|
})
|
||||||
err = Pipe{}.Publish(ctx)
|
err = Pipe{}.Publish(ctx)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), `upload: error while building the target url: template: tmpl:1: unexpected "/" in operand`)
|
require.Contains(t, err.Error(), `upload: error while building the target url: template: tmpl:1: unexpected "/" in operand`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_BadCredentials(t *testing.T) {
|
func TestRunPipe_BadCredentials(t *testing.T) {
|
||||||
@ -430,14 +430,14 @@ func TestRunPipe_BadCredentials(t *testing.T) {
|
|||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||||
d1 := []byte("hello\ngo\n")
|
d1 := []byte("hello\ngo\n")
|
||||||
err = ioutil.WriteFile(binPath, d1, 0666)
|
err = ioutil.WriteFile(binPath, d1, 0666)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Dummy http server
|
// Dummy http server
|
||||||
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -477,8 +477,8 @@ func TestRunPipe_BadCredentials(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
err = Pipe{}.Publish(ctx)
|
err = Pipe{}.Publish(ctx)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "Unauthorized")
|
require.Contains(t, err.Error(), "Unauthorized")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_FileNotFound(t *testing.T) {
|
func TestRunPipe_FileNotFound(t *testing.T) {
|
||||||
@ -509,19 +509,19 @@ func TestRunPipe_FileNotFound(t *testing.T) {
|
|||||||
Type: artifact.UploadableBinary,
|
Type: artifact.UploadableBinary,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.EqualError(t, Pipe{}.Publish(ctx), `open archivetest/dist/mybin/mybin: no such file or directory`)
|
require.EqualError(t, Pipe{}.Publish(ctx), `open archivetest/dist/mybin/mybin: no such file or directory`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_UnparsableTarget(t *testing.T) {
|
func TestRunPipe_UnparsableTarget(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||||
d1 := []byte("hello\ngo\n")
|
d1 := []byte("hello\ngo\n")
|
||||||
err = ioutil.WriteFile(binPath, d1, 0666)
|
err = ioutil.WriteFile(binPath, d1, 0666)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
ProjectName: "mybin",
|
ProjectName: "mybin",
|
||||||
@ -550,7 +550,7 @@ func TestRunPipe_UnparsableTarget(t *testing.T) {
|
|||||||
Type: artifact.UploadableBinary,
|
Type: artifact.UploadableBinary,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.EqualError(t, Pipe{}.Publish(ctx), `upload: upload failed: parse "://artifacts.company.com/example-repo-local/mybin/darwin/amd64/mybin": missing protocol scheme`)
|
require.EqualError(t, Pipe{}.Publish(ctx), `upload: upload failed: parse "://artifacts.company.com/example-repo-local/mybin/darwin/amd64/mybin": missing protocol scheme`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
|
func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
|
||||||
@ -573,16 +573,16 @@ func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
|
|||||||
ctx.SkipPublish = true
|
ctx.SkipPublish = true
|
||||||
|
|
||||||
err := Pipe{}.Publish(ctx)
|
err := Pipe{}.Publish(ctx)
|
||||||
assert.True(t, pipe.IsSkip(err))
|
require.True(t, pipe.IsSkip(err))
|
||||||
assert.EqualError(t, err, pipe.ErrSkipPublishEnabled.Error())
|
require.EqualError(t, err, pipe.ErrSkipPublishEnabled.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe_DirUpload(t *testing.T) {
|
func TestRunPipe_DirUpload(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
require.NoError(t, os.Mkdir(dist, 0755))
|
||||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||||
var binPath = filepath.Join(dist, "mybin")
|
var binPath = filepath.Join(dist, "mybin")
|
||||||
|
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
@ -612,15 +612,15 @@ func TestRunPipe_DirUpload(t *testing.T) {
|
|||||||
Type: artifact.UploadableBinary,
|
Type: artifact.UploadableBinary,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.EqualError(t, Pipe{}.Publish(ctx), `upload: upload failed: the asset to upload can't be a directory`)
|
require.EqualError(t, Pipe{}.Publish(ctx), `upload: upload failed: the asset to upload can't be a directory`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestDescription(t *testing.T) {
|
||||||
assert.NotEmpty(t, Pipe{}.String())
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoPuts(t *testing.T) {
|
func TestNoPuts(t *testing.T) {
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Publish(context.New(config.Project{}))))
|
require.True(t, pipe.IsSkip(Pipe{}.Publish(context.New(config.Project{}))))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPutsWithoutTarget(t *testing.T) {
|
func TestPutsWithoutTarget(t *testing.T) {
|
||||||
@ -639,7 +639,7 @@ func TestPutsWithoutTarget(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
require.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPutsWithoutUsername(t *testing.T) {
|
func TestPutsWithoutUsername(t *testing.T) {
|
||||||
@ -658,11 +658,11 @@ func TestPutsWithoutUsername(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
require.True(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPutsWithoutName(t *testing.T) {
|
func TestPutsWithoutName(t *testing.T) {
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Publish(context.New(config.Project{
|
require.True(t, pipe.IsSkip(Pipe{}.Publish(context.New(config.Project{
|
||||||
Uploads: []config.Upload{
|
Uploads: []config.Upload{
|
||||||
{
|
{
|
||||||
Method: h.MethodPut,
|
Method: h.MethodPut,
|
||||||
@ -674,7 +674,7 @@ func TestPutsWithoutName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPutsWithoutSecret(t *testing.T) {
|
func TestPutsWithoutSecret(t *testing.T) {
|
||||||
assert.True(t, pipe.IsSkip(Pipe{}.Publish(context.New(config.Project{
|
require.True(t, pipe.IsSkip(Pipe{}.Publish(context.New(config.Project{
|
||||||
Uploads: []config.Upload{
|
Uploads: []config.Upload{
|
||||||
{
|
{
|
||||||
Method: h.MethodPut,
|
Method: h.MethodPut,
|
||||||
@ -703,7 +703,7 @@ func TestPutsWithInvalidMode(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.Error(t, Pipe{}.Publish(ctx))
|
require.Error(t, Pipe{}.Publish(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefault(t *testing.T) {
|
func TestDefault(t *testing.T) {
|
||||||
@ -718,11 +718,11 @@ func TestDefault(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Len(t, ctx.Config.Uploads, 1)
|
require.Len(t, ctx.Config.Uploads, 1)
|
||||||
var upload = ctx.Config.Uploads[0]
|
var upload = ctx.Config.Uploads[0]
|
||||||
assert.Equal(t, "archive", upload.Mode)
|
require.Equal(t, "archive", upload.Mode)
|
||||||
assert.Equal(t, h.MethodPut, upload.Method)
|
require.Equal(t, h.MethodPut, upload.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultNoPuts(t *testing.T) {
|
func TestDefaultNoPuts(t *testing.T) {
|
||||||
@ -731,8 +731,8 @@ func TestDefaultNoPuts(t *testing.T) {
|
|||||||
Uploads: []config.Upload{},
|
Uploads: []config.Upload{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Empty(t, ctx.Config.Uploads)
|
require.Empty(t, ctx.Config.Uploads)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultSet(t *testing.T) {
|
func TestDefaultSet(t *testing.T) {
|
||||||
@ -746,9 +746,9 @@ func TestDefaultSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
assert.Len(t, ctx.Config.Uploads, 1)
|
require.Len(t, ctx.Config.Uploads, 1)
|
||||||
var upload = ctx.Config.Uploads[0]
|
var upload = ctx.Config.Uploads[0]
|
||||||
assert.Equal(t, "custom", upload.Mode)
|
require.Equal(t, "custom", upload.Mode)
|
||||||
assert.Equal(t, h.MethodPost, upload.Method)
|
require.Equal(t, h.MethodPost, upload.Method)
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExampleConfig(t *testing.T) {
|
func TestExampleConfig(t *testing.T) {
|
||||||
_, err := config.LoadReader(strings.NewReader(ExampleConfig))
|
_, err := config.LoadReader(strings.NewReader(ExampleConfig))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
@ -5,22 +5,22 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/internal/git"
|
"github.com/goreleaser/goreleaser/internal/git"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GitInit inits a new git project.
|
// GitInit inits a new git project.
|
||||||
func GitInit(t *testing.T) {
|
func GitInit(t *testing.T) {
|
||||||
out, err := fakeGit("init")
|
out, err := fakeGit("init")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Contains(t, out, "Initialized empty Git repository")
|
require.Contains(t, out, "Initialized empty Git repository")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GitRemoteAdd adds the given url as remote.
|
// GitRemoteAdd adds the given url as remote.
|
||||||
func GitRemoteAdd(t *testing.T, url string) {
|
func GitRemoteAdd(t *testing.T, url string) {
|
||||||
out, err := fakeGit("remote", "add", "origin", url)
|
out, err := fakeGit("remote", "add", "origin", url)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Empty(t, out)
|
require.Empty(t, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GitCommit creates a git commits.
|
// GitCommit creates a git commits.
|
||||||
@ -37,29 +37,29 @@ func GitCommitWithDate(t *testing.T, msg string, commitDate time.Time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
out, err := fakeGitEnv(env, "commit", "--allow-empty", "-m", msg)
|
out, err := fakeGitEnv(env, "commit", "--allow-empty", "-m", msg)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Contains(t, out, "master", msg)
|
require.Contains(t, out, "master", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GitTag creates a git tag.
|
// GitTag creates a git tag.
|
||||||
func GitTag(t *testing.T, tag string) {
|
func GitTag(t *testing.T, tag string) {
|
||||||
out, err := fakeGit("tag", tag)
|
out, err := fakeGit("tag", tag)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Empty(t, out)
|
require.Empty(t, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GitBranch creates a git branch.
|
// GitBranch creates a git branch.
|
||||||
func GitBranch(t *testing.T, branch string) {
|
func GitBranch(t *testing.T, branch string) {
|
||||||
out, err := fakeGit("branch", branch)
|
out, err := fakeGit("branch", branch)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Empty(t, out)
|
require.Empty(t, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GitAdd adds all files to stage.
|
// GitAdd adds all files to stage.
|
||||||
func GitAdd(t *testing.T) {
|
func GitAdd(t *testing.T) {
|
||||||
out, err := fakeGit("add", "-A")
|
out, err := fakeGit("add", "-A")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Empty(t, out)
|
require.Empty(t, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fakeGitEnv(env map[string]string, args ...string) (string, error) {
|
func fakeGitEnv(env map[string]string, args ...string) (string, error) {
|
||||||
@ -80,6 +80,6 @@ func fakeGit(args ...string) (string, error) {
|
|||||||
// GitCheckoutBranch allows us to change the active branch that we're using.
|
// GitCheckoutBranch allows us to change the active branch that we're using.
|
||||||
func GitCheckoutBranch(t *testing.T, name string) {
|
func GitCheckoutBranch(t *testing.T, name string) {
|
||||||
out, err := fakeGit("checkout", "-b", name)
|
out, err := fakeGit("checkout", "-b", name)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Empty(t, out)
|
require.Empty(t, out)
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,18 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mktmp creates a new tempdir, cd into it and provides a back function that
|
// Mktmp creates a new tempdir, cd into it and provides a back function that
|
||||||
// cd into the previous directory.
|
// cd into the previous directory.
|
||||||
func Mktmp(t *testing.T) (folder string, back func()) {
|
func Mktmp(t *testing.T) (folder string, back func()) {
|
||||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
current, err := os.Getwd()
|
current, err := os.Getwd()
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NoError(t, os.Chdir(folder))
|
require.NoError(t, os.Chdir(folder))
|
||||||
return folder, func() {
|
return folder, func() {
|
||||||
assert.NoError(t, os.Chdir(current))
|
require.NoError(t, os.Chdir(current))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,16 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMkTemp(t *testing.T) {
|
func TestMkTemp(t *testing.T) {
|
||||||
current, err := os.Getwd()
|
current, err := os.Getwd()
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
folder, back := Mktmp(t)
|
folder, back := Mktmp(t)
|
||||||
assert.NotEmpty(t, folder)
|
require.NotEmpty(t, folder)
|
||||||
back()
|
back()
|
||||||
newCurrent, err := os.Getwd()
|
newCurrent, err := os.Getwd()
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, current, newCurrent)
|
require.Equal(t, current, newCurrent)
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AssertSkipped asserts that a pipe was skipped.
|
// AssertSkipped asserts that a pipe was skipped.
|
||||||
func AssertSkipped(t *testing.T, err error) {
|
func AssertSkipped(t *testing.T, err error) {
|
||||||
_, ok := err.(pipe.ErrSkip)
|
_, ok := err.(pipe.ErrSkip)
|
||||||
assert.True(t, ok, "expected a pipe.ErrSkip but got %v", err)
|
require.True(t, ok, "expected a pipe.ErrSkip but got %v", err)
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,8 +62,8 @@ func TestWithArtifact(t *testing.T) {
|
|||||||
},
|
},
|
||||||
map[string]string{"linux": "Linux"},
|
map[string]string{"linux": "Linux"},
|
||||||
).Apply(tmpl)
|
).Apply(tmpl)
|
||||||
assert.NoError(tt, err)
|
require.NoError(tt, err)
|
||||||
assert.Equal(tt, expect, result)
|
require.Equal(tt, expect, result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,8 +81,8 @@ func TestWithArtifact(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}, map[string]string{},
|
}, map[string]string{},
|
||||||
).Apply("{{ .ArtifactUploadHash }}")
|
).Apply("{{ .ArtifactUploadHash }}")
|
||||||
assert.NoError(tt, err)
|
require.NoError(tt, err)
|
||||||
assert.Equal(tt, uploadHash, result)
|
require.Equal(tt, uploadHash, result)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("artifact without binary name", func(tt *testing.T) {
|
t.Run("artifact without binary name", func(tt *testing.T) {
|
||||||
@ -96,15 +95,15 @@ func TestWithArtifact(t *testing.T) {
|
|||||||
Goarm: "6",
|
Goarm: "6",
|
||||||
}, map[string]string{},
|
}, map[string]string{},
|
||||||
).Apply("{{ .Binary }}")
|
).Apply("{{ .Binary }}")
|
||||||
assert.NoError(tt, err)
|
require.NoError(tt, err)
|
||||||
assert.Equal(tt, ctx.Config.ProjectName, result)
|
require.Equal(tt, ctx.Config.ProjectName, result)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("template using artifact Fields with no artifact", func(tt *testing.T) {
|
t.Run("template using artifact Fields with no artifact", func(tt *testing.T) {
|
||||||
tt.Parallel()
|
tt.Parallel()
|
||||||
result, err := New(ctx).Apply("{{ .Os }}")
|
result, err := New(ctx).Apply("{{ .Os }}")
|
||||||
assert.EqualError(tt, err, `template: tmpl:1:3: executing "tmpl" at <.Os>: map has no entry for key "Os"`)
|
require.EqualError(tt, err, `template: tmpl:1:3: executing "tmpl" at <.Os>: map has no entry for key "Os"`)
|
||||||
assert.Empty(tt, result)
|
require.Empty(tt, result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +132,7 @@ func TestEnv(t *testing.T) {
|
|||||||
for _, tC := range testCases {
|
for _, tC := range testCases {
|
||||||
t.Run(tC.desc, func(t *testing.T) {
|
t.Run(tC.desc, func(t *testing.T) {
|
||||||
out, _ := New(ctx).Apply(tC.in)
|
out, _ := New(ctx).Apply(tC.in)
|
||||||
assert.Equal(t, tC.out, out)
|
require.Equal(t, tC.out, out)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,8 +147,8 @@ func TestWithEnv(t *testing.T) {
|
|||||||
"FOO=foo",
|
"FOO=foo",
|
||||||
"BAR=bar",
|
"BAR=bar",
|
||||||
}).Apply("{{ .Env.FOO }}-{{ .Env.BAR }}")
|
}).Apply("{{ .Env.FOO }}-{{ .Env.BAR }}")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "foo-bar", out)
|
require.Equal(t, "foo-bar", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFuncMap(t *testing.T) {
|
func TestFuncMap(t *testing.T) {
|
||||||
@ -204,11 +203,11 @@ func TestFuncMap(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
out, err := New(ctx).Apply(tc.Template)
|
out, err := New(ctx).Apply(tc.Template)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if tc.Expected != "" {
|
if tc.Expected != "" {
|
||||||
assert.Equal(t, tc.Expected, out)
|
require.Equal(t, tc.Expected, out)
|
||||||
} else {
|
} else {
|
||||||
assert.NotEmpty(t, out)
|
require.NotEmpty(t, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,9 +270,9 @@ func TestApplySingleEnvOnly(t *testing.T) {
|
|||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
_, err := New(ctx).ApplySingleEnvOnly(tc.tpl)
|
_, err := New(ctx).ApplySingleEnvOnly(tc.tpl)
|
||||||
if tc.expectedErr != nil {
|
if tc.expectedErr != nil {
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
} else {
|
} else {
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -283,15 +282,15 @@ func TestInvalidTemplate(t *testing.T) {
|
|||||||
ctx := context.New(config.Project{})
|
ctx := context.New(config.Project{})
|
||||||
ctx.Git.CurrentTag = "v1.1.1"
|
ctx.Git.CurrentTag = "v1.1.1"
|
||||||
_, err := New(ctx).Apply("{{{.Foo}")
|
_, err := New(ctx).Apply("{{{.Foo}")
|
||||||
assert.EqualError(t, err, "template: tmpl:1: unexpected \"{\" in command")
|
require.EqualError(t, err, "template: tmpl:1: unexpected \"{\" in command")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnvNotFound(t *testing.T) {
|
func TestEnvNotFound(t *testing.T) {
|
||||||
var ctx = context.New(config.Project{})
|
var ctx = context.New(config.Project{})
|
||||||
ctx.Git.CurrentTag = "v1.2.4"
|
ctx.Git.CurrentTag = "v1.2.4"
|
||||||
result, err := New(ctx).Apply("{{.Env.FOO}}")
|
result, err := New(ctx).Apply("{{.Env.FOO}}")
|
||||||
assert.Empty(t, result)
|
require.Empty(t, result)
|
||||||
assert.EqualError(t, err, `template: tmpl:1:6: executing "tmpl" at <.Env.FOO>: map has no entry for key "FOO"`)
|
require.EqualError(t, err, `template: tmpl:1:6: executing "tmpl" at <.Env.FOO>: map has no entry for key "FOO"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithExtraFields(t *testing.T) {
|
func TestWithExtraFields(t *testing.T) {
|
||||||
@ -299,6 +298,6 @@ func TestWithExtraFields(t *testing.T) {
|
|||||||
out, _ := New(ctx).WithExtraFields(Fields{
|
out, _ := New(ctx).WithExtraFields(Fields{
|
||||||
"MyCustomField": "foo",
|
"MyCustomField": "foo",
|
||||||
}).Apply("{{ .MyCustomField }}")
|
}).Apply("{{ .MyCustomField }}")
|
||||||
assert.Equal(t, "foo", out)
|
require.Equal(t, "foo", out)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,30 +5,29 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestArchive(t *testing.T) {
|
func TestArchive(t *testing.T) {
|
||||||
var assert = assert.New(t)
|
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
empty, err := os.Create(folder + "/empty.txt")
|
empty, err := os.Create(folder + "/empty.txt")
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
assert.NoError(os.Mkdir(folder+"/folder-inside", 0755))
|
require.NoError(t, os.Mkdir(folder+"/folder-inside", 0755))
|
||||||
|
|
||||||
for _, format := range []string{"tar.gz", "zip", "gz", "tar.xz", "willbeatargzanyway"} {
|
for _, format := range []string{"tar.gz", "zip", "gz", "tar.xz", "willbeatargzanyway"} {
|
||||||
format := format
|
format := format
|
||||||
t.Run(format, func(t *testing.T) {
|
t.Run(format, func(t *testing.T) {
|
||||||
var archive = newArchive(folder, format, t)
|
var archive = newArchive(folder, format, t)
|
||||||
assert.NoError(archive.Add("empty.txt", empty.Name()))
|
require.NoError(t, archive.Add("empty.txt", empty.Name()))
|
||||||
assert.Error(archive.Add("dont.txt", empty.Name()+"_nope"))
|
require.Error(t, archive.Add("dont.txt", empty.Name()+"_nope"))
|
||||||
assert.NoError(archive.Close())
|
require.NoError(t, archive.Close())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newArchive(folder, format string, t *testing.T) Archive {
|
func newArchive(folder, format string, t *testing.T) Archive {
|
||||||
file, err := os.Create(folder + "/folder." + format)
|
file, err := os.Create(folder + "/folder." + format)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return New(file)
|
return New(file)
|
||||||
}
|
}
|
||||||
|
@ -7,40 +7,39 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGzFile(t *testing.T) {
|
func TestGzFile(t *testing.T) {
|
||||||
var assert = assert.New(t)
|
|
||||||
tmp, err := ioutil.TempDir("", "")
|
tmp, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
f, err := os.Create(filepath.Join(tmp, "test.gz"))
|
f, err := os.Create(filepath.Join(tmp, "test.gz"))
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
defer f.Close() // nolint: errcheck
|
defer f.Close() // nolint: errcheck
|
||||||
archive := New(f)
|
archive := New(f)
|
||||||
|
|
||||||
assert.NoError(archive.Add("sub1/sub2/subfoo.txt", "../testdata/sub1/sub2/subfoo.txt"))
|
require.NoError(t, archive.Add("sub1/sub2/subfoo.txt", "../testdata/sub1/sub2/subfoo.txt"))
|
||||||
assert.EqualError(archive.Add("foo.txt", "../testdata/foo.txt"), "gzip: failed to add foo.txt, only one file can be archived in gz format")
|
require.EqualError(t, archive.Add("foo.txt", "../testdata/foo.txt"), "gzip: failed to add foo.txt, only one file can be archived in gz format")
|
||||||
assert.NoError(archive.Close())
|
require.NoError(t, archive.Close())
|
||||||
|
|
||||||
assert.NoError(f.Close())
|
require.NoError(t, f.Close())
|
||||||
|
|
||||||
t.Log(f.Name())
|
t.Log(f.Name())
|
||||||
f, err = os.Open(f.Name())
|
f, err = os.Open(f.Name())
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
defer f.Close() // nolint: errcheck
|
defer f.Close() // nolint: errcheck
|
||||||
|
|
||||||
info, err := f.Stat()
|
info, err := f.Stat()
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
assert.Truef(info.Size() < 500, "archived file should be smaller than %d", info.Size())
|
require.Truef(t, info.Size() < 500, "archived file should be smaller than %d", info.Size())
|
||||||
|
|
||||||
gzf, err := gzip.NewReader(f)
|
gzf, err := gzip.NewReader(f)
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
defer gzf.Close() // nolint: errcheck
|
defer gzf.Close() // nolint: errcheck
|
||||||
|
|
||||||
assert.Equal("sub1/sub2/subfoo.txt", gzf.Name)
|
require.Equal(t, "sub1/sub2/subfoo.txt", gzf.Name)
|
||||||
|
|
||||||
bts, err := ioutil.ReadAll(gzf)
|
bts, err := ioutil.ReadAll(gzf)
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
assert.Equal("sub\n", string(bts))
|
require.Equal(t, "sub\n", string(bts))
|
||||||
}
|
}
|
||||||
|
@ -9,41 +9,40 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTarGzFile(t *testing.T) {
|
func TestTarGzFile(t *testing.T) {
|
||||||
var assert = assert.New(t)
|
|
||||||
tmp, err := ioutil.TempDir("", "")
|
tmp, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
f, err := os.Create(filepath.Join(tmp, "test.tar.gz"))
|
f, err := os.Create(filepath.Join(tmp, "test.tar.gz"))
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
defer f.Close() // nolint: errcheck
|
defer f.Close() // nolint: errcheck
|
||||||
archive := New(f)
|
archive := New(f)
|
||||||
|
|
||||||
assert.Error(archive.Add("nope.txt", "../testdata/nope.txt"))
|
require.Error(t, archive.Add("nope.txt", "../testdata/nope.txt"))
|
||||||
assert.NoError(archive.Add("foo.txt", "../testdata/foo.txt"))
|
require.NoError(t, archive.Add("foo.txt", "../testdata/foo.txt"))
|
||||||
assert.NoError(archive.Add("sub1", "../testdata/sub1"))
|
require.NoError(t, archive.Add("sub1", "../testdata/sub1"))
|
||||||
assert.NoError(archive.Add("sub1/bar.txt", "../testdata/sub1/bar.txt"))
|
require.NoError(t, archive.Add("sub1/bar.txt", "../testdata/sub1/bar.txt"))
|
||||||
assert.NoError(archive.Add("sub1/executable", "../testdata/sub1/executable"))
|
require.NoError(t, archive.Add("sub1/executable", "../testdata/sub1/executable"))
|
||||||
assert.NoError(archive.Add("sub1/sub2", "../testdata/sub1/sub2"))
|
require.NoError(t, archive.Add("sub1/sub2", "../testdata/sub1/sub2"))
|
||||||
assert.NoError(archive.Add("sub1/sub2/subfoo.txt", "../testdata/sub1/sub2/subfoo.txt"))
|
require.NoError(t, archive.Add("sub1/sub2/subfoo.txt", "../testdata/sub1/sub2/subfoo.txt"))
|
||||||
|
|
||||||
assert.NoError(archive.Close())
|
require.NoError(t, archive.Close())
|
||||||
assert.Error(archive.Add("tar.go", "tar.go"))
|
require.Error(t, archive.Add("tar.go", "tar.go"))
|
||||||
assert.NoError(f.Close())
|
require.NoError(t, f.Close())
|
||||||
|
|
||||||
t.Log(f.Name())
|
t.Log(f.Name())
|
||||||
f, err = os.Open(f.Name())
|
f, err = os.Open(f.Name())
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
defer f.Close() // nolint: errcheck
|
defer f.Close() // nolint: errcheck
|
||||||
|
|
||||||
info, err := f.Stat()
|
info, err := f.Stat()
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
assert.Truef(info.Size() < 500, "archived file should be smaller than %d", info.Size())
|
require.Truef(t, info.Size() < 500, "archived file should be smaller than %d", info.Size())
|
||||||
|
|
||||||
gzf, err := gzip.NewReader(f)
|
gzf, err := gzip.NewReader(f)
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
defer gzf.Close() // nolint: errcheck
|
defer gzf.Close() // nolint: errcheck
|
||||||
|
|
||||||
var paths []string
|
var paths []string
|
||||||
@ -53,15 +52,15 @@ func TestTarGzFile(t *testing.T) {
|
|||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
paths = append(paths, next.Name)
|
paths = append(paths, next.Name)
|
||||||
t.Logf("%s: %v", next.Name, next.FileInfo().Mode())
|
t.Logf("%s: %v", next.Name, next.FileInfo().Mode())
|
||||||
if next.Name == "sub1/executable" {
|
if next.Name == "sub1/executable" {
|
||||||
var ex = next.FileInfo().Mode() | 0111
|
var ex = next.FileInfo().Mode() | 0111
|
||||||
assert.Equal(next.FileInfo().Mode().String(), ex.String())
|
require.Equal(t, next.FileInfo().Mode().String(), ex.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.Equal([]string{
|
require.Equal(t, []string{
|
||||||
"foo.txt",
|
"foo.txt",
|
||||||
"sub1",
|
"sub1",
|
||||||
"sub1/bar.txt",
|
"sub1/bar.txt",
|
||||||
|
@ -8,42 +8,41 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/ulikunitz/xz"
|
"github.com/ulikunitz/xz"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTarXzFile(t *testing.T) {
|
func TestTarXzFile(t *testing.T) {
|
||||||
var assert = assert.New(t)
|
|
||||||
tmp, err := ioutil.TempDir("", "")
|
tmp, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
f, err := os.Create(filepath.Join(tmp, "test.tar.xz"))
|
f, err := os.Create(filepath.Join(tmp, "test.tar.xz"))
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
defer f.Close() // nolint: errcheck
|
defer f.Close() // nolint: errcheck
|
||||||
archive := New(f)
|
archive := New(f)
|
||||||
|
|
||||||
assert.Error(archive.Add("nope.txt", "../testdata/nope.txt"))
|
require.Error(t, archive.Add("nope.txt", "../testdata/nope.txt"))
|
||||||
assert.NoError(archive.Add("foo.txt", "../testdata/foo.txt"))
|
require.NoError(t, archive.Add("foo.txt", "../testdata/foo.txt"))
|
||||||
assert.NoError(archive.Add("sub1", "../testdata/sub1"))
|
require.NoError(t, archive.Add("sub1", "../testdata/sub1"))
|
||||||
assert.NoError(archive.Add("sub1/bar.txt", "../testdata/sub1/bar.txt"))
|
require.NoError(t, archive.Add("sub1/bar.txt", "../testdata/sub1/bar.txt"))
|
||||||
assert.NoError(archive.Add("sub1/executable", "../testdata/sub1/executable"))
|
require.NoError(t, archive.Add("sub1/executable", "../testdata/sub1/executable"))
|
||||||
assert.NoError(archive.Add("sub1/sub2", "../testdata/sub1/sub2"))
|
require.NoError(t, archive.Add("sub1/sub2", "../testdata/sub1/sub2"))
|
||||||
assert.NoError(archive.Add("sub1/sub2/subfoo.txt", "../testdata/sub1/sub2/subfoo.txt"))
|
require.NoError(t, archive.Add("sub1/sub2/subfoo.txt", "../testdata/sub1/sub2/subfoo.txt"))
|
||||||
|
|
||||||
assert.NoError(archive.Close())
|
require.NoError(t, archive.Close())
|
||||||
assert.Error(archive.Add("tar.go", "tar.go"))
|
require.Error(t, archive.Add("tar.go", "tar.go"))
|
||||||
assert.NoError(f.Close())
|
require.NoError(t, f.Close())
|
||||||
|
|
||||||
t.Log(f.Name())
|
t.Log(f.Name())
|
||||||
f, err = os.Open(f.Name())
|
f, err = os.Open(f.Name())
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
defer f.Close() // nolint: errcheck
|
defer f.Close() // nolint: errcheck
|
||||||
|
|
||||||
info, err := f.Stat()
|
info, err := f.Stat()
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
assert.Truef(info.Size() < 500, "archived file should be smaller than %d", info.Size())
|
require.Truef(t, info.Size() < 500, "archived file should be smaller than %d", info.Size())
|
||||||
|
|
||||||
xzf, err := xz.NewReader(f)
|
xzf, err := xz.NewReader(f)
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
//defer xzf.Close() // nolint: errcheck
|
//defer xzf.Close() // nolint: errcheck
|
||||||
|
|
||||||
var paths []string
|
var paths []string
|
||||||
@ -53,15 +52,15 @@ func TestTarXzFile(t *testing.T) {
|
|||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
paths = append(paths, next.Name)
|
paths = append(paths, next.Name)
|
||||||
t.Logf("%s: %v", next.Name, next.FileInfo().Mode())
|
t.Logf("%s: %v", next.Name, next.FileInfo().Mode())
|
||||||
if next.Name == "sub1/executable" {
|
if next.Name == "sub1/executable" {
|
||||||
var ex = next.FileInfo().Mode() | 0111
|
var ex = next.FileInfo().Mode() | 0111
|
||||||
assert.Equal(next.FileInfo().Mode().String(), ex.String())
|
require.Equal(t, next.FileInfo().Mode().String(), ex.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.Equal([]string{
|
require.Equal(t, []string{
|
||||||
"foo.txt",
|
"foo.txt",
|
||||||
"sub1",
|
"sub1",
|
||||||
"sub1/bar.txt",
|
"sub1/bar.txt",
|
||||||
|
@ -8,42 +8,41 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestZipFile(t *testing.T) {
|
func TestZipFile(t *testing.T) {
|
||||||
var assert = assert.New(t)
|
|
||||||
tmp, err := ioutil.TempDir("", "")
|
tmp, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
f, err := os.Create(filepath.Join(tmp, "test.zip"))
|
f, err := os.Create(filepath.Join(tmp, "test.zip"))
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
fmt.Println(f.Name())
|
fmt.Println(f.Name())
|
||||||
defer f.Close() // nolint: errcheck
|
defer f.Close() // nolint: errcheck
|
||||||
archive := New(f)
|
archive := New(f)
|
||||||
|
|
||||||
assert.Error(archive.Add("nope.txt", "../testdata/nope.txt"))
|
require.Error(t, archive.Add("nope.txt", "../testdata/nope.txt"))
|
||||||
assert.NoError(archive.Add("foo.txt", "../testdata/foo.txt"))
|
require.NoError(t, archive.Add("foo.txt", "../testdata/foo.txt"))
|
||||||
assert.NoError(archive.Add("sub1", "../testdata/sub1"))
|
require.NoError(t, archive.Add("sub1", "../testdata/sub1"))
|
||||||
assert.NoError(archive.Add("sub1/bar.txt", "../testdata/sub1/bar.txt"))
|
require.NoError(t, archive.Add("sub1/bar.txt", "../testdata/sub1/bar.txt"))
|
||||||
assert.NoError(archive.Add("sub1/executable", "../testdata/sub1/executable"))
|
require.NoError(t, archive.Add("sub1/executable", "../testdata/sub1/executable"))
|
||||||
assert.NoError(archive.Add("sub1/sub2", "../testdata/sub1/sub2"))
|
require.NoError(t, archive.Add("sub1/sub2", "../testdata/sub1/sub2"))
|
||||||
assert.NoError(archive.Add("sub1/sub2/subfoo.txt", "../testdata/sub1/sub2/subfoo.txt"))
|
require.NoError(t, archive.Add("sub1/sub2/subfoo.txt", "../testdata/sub1/sub2/subfoo.txt"))
|
||||||
|
|
||||||
assert.NoError(archive.Close())
|
require.NoError(t, archive.Close())
|
||||||
assert.Error(archive.Add("tar.go", "tar.go"))
|
require.Error(t, archive.Add("tar.go", "tar.go"))
|
||||||
assert.NoError(f.Close())
|
require.NoError(t, f.Close())
|
||||||
|
|
||||||
t.Log(f.Name())
|
t.Log(f.Name())
|
||||||
f, err = os.Open(f.Name())
|
f, err = os.Open(f.Name())
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
defer f.Close() // nolint: errcheck
|
defer f.Close() // nolint: errcheck
|
||||||
|
|
||||||
info, err := f.Stat()
|
info, err := f.Stat()
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
assert.Truef(info.Size() < 900, "archived file should be smaller than %d", info.Size())
|
require.Truef(t, info.Size() < 900, "archived file should be smaller than %d", info.Size())
|
||||||
|
|
||||||
r, err := zip.NewReader(f, info.Size())
|
r, err := zip.NewReader(f, info.Size())
|
||||||
assert.NoError(err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var paths = make([]string, len(r.File))
|
var paths = make([]string, len(r.File))
|
||||||
for i, zf := range r.File {
|
for i, zf := range r.File {
|
||||||
@ -51,10 +50,10 @@ func TestZipFile(t *testing.T) {
|
|||||||
t.Logf("%s: %v", zf.Name, zf.Mode())
|
t.Logf("%s: %v", zf.Name, zf.Mode())
|
||||||
if zf.Name == "sub1/executable" {
|
if zf.Name == "sub1/executable" {
|
||||||
var ex = zf.Mode() | 0111
|
var ex = zf.Mode() | 0111
|
||||||
assert.Equal(zf.Mode().String(), ex.String())
|
require.Equal(t, zf.Mode().String(), ex.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.Equal([]string{
|
require.Equal(t, []string{
|
||||||
"foo.txt",
|
"foo.txt",
|
||||||
"sub1/bar.txt",
|
"sub1/bar.txt",
|
||||||
"sub1/executable",
|
"sub1/executable",
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
type dummy struct{}
|
type dummy struct{}
|
||||||
@ -20,5 +20,5 @@ func (*dummy) Build(ctx *context.Context, build config.Build, options Options) e
|
|||||||
func TestRegisterAndGet(t *testing.T) {
|
func TestRegisterAndGet(t *testing.T) {
|
||||||
var builder = &dummy{}
|
var builder = &dummy{}
|
||||||
Register("dummy", builder)
|
Register("dummy", builder)
|
||||||
assert.Equal(t, builder, For("dummy"))
|
require.Equal(t, builder, For("dummy"))
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -92,10 +92,10 @@ func TestStringArray(t *testing.T) {
|
|||||||
|
|
||||||
err := yaml.UnmarshalStrict([]byte(testCase.yaml), &actual)
|
err := yaml.UnmarshalStrict([]byte(testCase.yaml), &actual)
|
||||||
if testCase.err == "" {
|
if testCase.err == "" {
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, testCase.expected, actual)
|
require.Equal(t, testCase.expected, actual)
|
||||||
} else {
|
} else {
|
||||||
assert.EqualError(t, err, testCase.err)
|
require.EqualError(t, err, testCase.err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,10 +106,10 @@ func TestFlagArray(t *testing.T) {
|
|||||||
|
|
||||||
err := yaml.UnmarshalStrict([]byte(testCase.yaml), &actual)
|
err := yaml.UnmarshalStrict([]byte(testCase.yaml), &actual)
|
||||||
if testCase.err == "" {
|
if testCase.err == "" {
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
} else {
|
} else {
|
||||||
assert.EqualError(t, err, testCase.err)
|
require.EqualError(t, err, testCase.err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, testCase.expected, actual)
|
require.Equal(t, testCase.expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,8 +11,8 @@ func TestBuildHook_justString(t *testing.T) {
|
|||||||
var actual HookConfig
|
var actual HookConfig
|
||||||
|
|
||||||
err := yaml.UnmarshalStrict([]byte(`pre: ./script.sh`), &actual)
|
err := yaml.UnmarshalStrict([]byte(`pre: ./script.sh`), &actual)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, BuildHook{
|
require.Equal(t, BuildHook{
|
||||||
Cmd: "./script.sh",
|
Cmd: "./script.sh",
|
||||||
Env: nil,
|
Env: nil,
|
||||||
}, actual.Pre[0])
|
}, actual.Pre[0])
|
||||||
@ -25,9 +25,9 @@ func TestBuildHook_stringCmds(t *testing.T) {
|
|||||||
- ./script.sh
|
- ./script.sh
|
||||||
- second-script.sh
|
- second-script.sh
|
||||||
`), &actual)
|
`), &actual)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, BuildHooks{
|
require.Equal(t, BuildHooks{
|
||||||
{
|
{
|
||||||
Cmd: "./script.sh",
|
Cmd: "./script.sh",
|
||||||
Env: nil,
|
Env: nil,
|
||||||
@ -47,8 +47,8 @@ func TestBuildHook_complex(t *testing.T) {
|
|||||||
env:
|
env:
|
||||||
- TEST=value
|
- TEST=value
|
||||||
`), &actual)
|
`), &actual)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, BuildHook{
|
require.Equal(t, BuildHook{
|
||||||
Cmd: "./script.sh",
|
Cmd: "./script.sh",
|
||||||
Env: []string{"TEST=value"},
|
Env: []string{"TEST=value"},
|
||||||
}, actual.Pre[0])
|
}, actual.Pre[0])
|
||||||
|
@ -8,11 +8,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRepo(t *testing.T) {
|
func TestRepo(t *testing.T) {
|
||||||
assert.Equal(
|
require.Equal(
|
||||||
t,
|
t,
|
||||||
"goreleaser/godownloader",
|
"goreleaser/godownloader",
|
||||||
Repo{Owner: "goreleaser", Name: "godownloader"}.String(),
|
Repo{Owner: "goreleaser", Name: "godownloader"}.String(),
|
||||||
@ -20,7 +20,7 @@ func TestRepo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyRepoNameAndOwner(t *testing.T) {
|
func TestEmptyRepoNameAndOwner(t *testing.T) {
|
||||||
assert.Empty(t, Repo{}.String())
|
require.Empty(t, Repo{}.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadReader(t *testing.T) {
|
func TestLoadReader(t *testing.T) {
|
||||||
@ -31,8 +31,8 @@ nfpms:
|
|||||||
buf := strings.NewReader(conf)
|
buf := strings.NewReader(conf)
|
||||||
prop, err := LoadReader(buf)
|
prop, err := LoadReader(buf)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "http://goreleaser.github.io", prop.NFPMs[0].Homepage, "yaml did not load correctly")
|
require.Equal(t, "http://goreleaser.github.io", prop.NFPMs[0].Homepage, "yaml did not load correctly")
|
||||||
}
|
}
|
||||||
|
|
||||||
type errorReader struct{}
|
type errorReader struct{}
|
||||||
@ -42,32 +42,32 @@ func (errorReader) Read(p []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
func TestLoadBadReader(t *testing.T) {
|
func TestLoadBadReader(t *testing.T) {
|
||||||
_, err := LoadReader(errorReader{})
|
_, err := LoadReader(errorReader{})
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFile(t *testing.T) {
|
func TestFile(t *testing.T) {
|
||||||
f, err := ioutil.TempFile(os.TempDir(), "config")
|
f, err := ioutil.TempFile(os.TempDir(), "config")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = Load(filepath.Join(f.Name()))
|
_, err = Load(filepath.Join(f.Name()))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFileNotFound(t *testing.T) {
|
func TestFileNotFound(t *testing.T) {
|
||||||
_, err := Load("/nope/no-way.yml")
|
_, err := Load("/nope/no-way.yml")
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidFields(t *testing.T) {
|
func TestInvalidFields(t *testing.T) {
|
||||||
_, err := Load("testdata/invalid_config.yml")
|
_, err := Load("testdata/invalid_config.yml")
|
||||||
assert.EqualError(t, err, "yaml: unmarshal errors:\n line 2: field invalid_yaml not found in type config.Build")
|
require.EqualError(t, err, "yaml: unmarshal errors:\n line 2: field invalid_yaml not found in type config.Build")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidYaml(t *testing.T) {
|
func TestInvalidYaml(t *testing.T) {
|
||||||
_, err := Load("testdata/invalid.yml")
|
_, err := Load("testdata/invalid.yml")
|
||||||
assert.EqualError(t, err, "yaml: line 1: did not find expected node content")
|
require.EqualError(t, err, "yaml: line 1: did not find expected node content")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfigWithAnchors(t *testing.T) {
|
func TestConfigWithAnchors(t *testing.T) {
|
||||||
_, err := Load("testdata/anchor.yaml")
|
_, err := Load("testdata/anchor.yaml")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
@ -6,27 +6,27 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
assert.NoError(t, os.Setenv("FOO", "NOT BAR"))
|
require.NoError(t, os.Setenv("FOO", "NOT BAR"))
|
||||||
assert.NoError(t, os.Setenv("BAR", "1"))
|
require.NoError(t, os.Setenv("BAR", "1"))
|
||||||
var ctx = New(config.Project{
|
var ctx = New(config.Project{
|
||||||
Env: []string{
|
Env: []string{
|
||||||
"FOO=BAR",
|
"FOO=BAR",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.Equal(t, "BAR", ctx.Env["FOO"])
|
require.Equal(t, "BAR", ctx.Env["FOO"])
|
||||||
assert.Equal(t, "1", ctx.Env["BAR"])
|
require.Equal(t, "1", ctx.Env["BAR"])
|
||||||
assert.Equal(t, 4, ctx.Parallelism)
|
require.Equal(t, 4, ctx.Parallelism)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewWithTimeout(t *testing.T) {
|
func TestNewWithTimeout(t *testing.T) {
|
||||||
ctx, cancel := NewWithTimeout(config.Project{}, time.Second)
|
ctx, cancel := NewWithTimeout(config.Project{}, time.Second)
|
||||||
assert.NotEmpty(t, ctx.Env)
|
require.NotEmpty(t, ctx.Env)
|
||||||
assert.Equal(t, 4, ctx.Parallelism)
|
require.Equal(t, 4, ctx.Parallelism)
|
||||||
cancel()
|
cancel()
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
assert.EqualError(t, ctx.Err(), `context canceled`)
|
require.EqualError(t, ctx.Err(), `context canceled`)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user