1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-26 04:22:05 +02:00

Merge pull request #371 from goreleaser/lint

Lint on build
This commit is contained in:
Carlos Alexandro Becker 2017-10-01 09:55:23 -03:00 committed by GitHub
commit ef68fce2a8
30 changed files with 361 additions and 483 deletions

View File

@ -13,7 +13,7 @@ install:
- export PATH=/snap/bin:$PATH - export PATH=/snap/bin:$PATH
- sudo snap install snapcraft --candidate --classic - sudo snap install snapcraft --candidate --classic
script: script:
- make test - make ci
- test -n "$TRAVIS_TAG" || go run main.go --skip-validate --skip-publish - test -n "$TRAVIS_TAG" || go run main.go --skip-validate --skip-publish
after_success: after_success:
- bash <(curl -s https://codecov.io/bash) - bash <(curl -s https://codecov.io/bash)

View File

@ -11,31 +11,28 @@ import (
) )
func TestChecksums(t *testing.T) { func TestChecksums(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
var file = filepath.Join(folder, "subject") var file = filepath.Join(folder, "subject")
assert.NoError(ioutil.WriteFile(file, []byte("lorem ipsum"), 0644)) assert.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
sum, err := SHA256(file) sum, err := SHA256(file)
assert.NoError(err) assert.NoError(t, err)
assert.Equal("5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269", sum) assert.Equal(t, "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269", sum)
} }
func TestOpenFailure(t *testing.T) { func TestOpenFailure(t *testing.T) {
var assert = assert.New(t)
sum, err := SHA256("/tmp/this-file-wont-exist-I-hope") sum, err := SHA256("/tmp/this-file-wont-exist-I-hope")
assert.Empty(sum) assert.Empty(t, sum)
assert.Error(err) assert.Error(t, err)
} }
func TestFileDoesntExist(t *testing.T) { func TestFileDoesntExist(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
var path = filepath.Join(folder, "subject") var path = filepath.Join(folder, "subject")
file, err := os.Create(path) file, err := os.Create(path)
assert.NoError(err) assert.NoError(t, err)
assert.NoError(file.Close()) assert.NoError(t, file.Close())
_, err = doCalculate(sha256.New(), file) _, err = doCalculate(sha256.New(), file)
assert.Error(err) assert.Error(t, err)
} }

View File

@ -12,9 +12,8 @@ import (
) )
func TestRepo(t *testing.T) { func TestRepo(t *testing.T) {
var assert = assert.New(t)
r := Repo{Owner: "goreleaser", Name: "godownloader"} r := Repo{Owner: "goreleaser", Name: "godownloader"}
assert.Equal("goreleaser/godownloader", r.String(), "not equal") assert.Equal(t, "goreleaser/godownloader", r.String(), "not equal")
} }
func TestLoadReader(t *testing.T) { func TestLoadReader(t *testing.T) {
@ -22,12 +21,11 @@ func TestLoadReader(t *testing.T) {
fpm: fpm:
homepage: http://goreleaser.github.io homepage: http://goreleaser.github.io
` `
var assert = assert.New(t)
buf := strings.NewReader(conf) buf := strings.NewReader(conf)
prop, err := LoadReader(buf) prop, err := LoadReader(buf)
assert.Nil(err) assert.NoError(t, err)
assert.Equal("http://goreleaser.github.io", prop.FPM.Homepage, "yaml did not load correctly") assert.Equal(t, "http://goreleaser.github.io", prop.FPM.Homepage, "yaml did not load correctly")
} }
type errorReader struct{} type errorReader struct{}
@ -36,33 +34,28 @@ func (errorReader) Read(p []byte) (n int, err error) {
return 1, fmt.Errorf("error") return 1, fmt.Errorf("error")
} }
func TestLoadBadReader(t *testing.T) { func TestLoadBadReader(t *testing.T) {
var assert = assert.New(t)
_, err := LoadReader(errorReader{}) _, err := LoadReader(errorReader{})
assert.Error(err) assert.Error(t, err)
} }
func TestFile(t *testing.T) { func TestFile(t *testing.T) {
var assert = assert.New(t)
f, err := ioutil.TempFile(os.TempDir(), "config") f, err := ioutil.TempFile(os.TempDir(), "config")
assert.NoError(err) assert.NoError(t, err)
_, err = Load(filepath.Join(f.Name())) _, err = Load(filepath.Join(f.Name()))
assert.NoError(err) assert.NoError(t, err)
} }
func TestFileNotFound(t *testing.T) { func TestFileNotFound(t *testing.T) {
var assert = assert.New(t)
_, err := Load("/nope/no-way.yml") _, err := Load("/nope/no-way.yml")
assert.Error(err) assert.Error(t, err)
} }
func TestInvalidFields(t *testing.T) { func TestInvalidFields(t *testing.T) {
var assert = assert.New(t)
_, err := Load("testdata/invalid_config.yml") _, err := Load("testdata/invalid_config.yml")
assert.EqualError(err, "unknown fields in the config file: invalid_root, archive.invalid_archive, archive.format_overrides[0].invalid_archive_fmtoverrides, brew.invalid_brew, brew.github.invalid_brew_github, builds[0].invalid_builds, builds[0].hooks.invalid_builds_hooks, builds[0].ignored_builds[0].invalid_builds_ignore, fpm.invalid_fpm, release.invalid_release, release.github.invalid_release_github, build.invalid_build, builds.hooks.invalid_build_hook, builds.ignored_builds[0].invalid_build_ignore, snapshot.invalid_snapshot, docker[0].invalid_docker") assert.EqualError(t, err, "unknown fields in the config file: invalid_root, archive.invalid_archive, archive.format_overrides[0].invalid_archive_fmtoverrides, brew.invalid_brew, brew.github.invalid_brew_github, builds[0].invalid_builds, builds[0].hooks.invalid_builds_hooks, builds[0].ignored_builds[0].invalid_builds_ignore, fpm.invalid_fpm, release.invalid_release, release.github.invalid_release_github, build.invalid_build, builds.hooks.invalid_build_hook, builds.ignored_builds[0].invalid_build_ignore, snapshot.invalid_snapshot, docker[0].invalid_docker")
} }
func TestInvalidYaml(t *testing.T) { func TestInvalidYaml(t *testing.T) {
var assert = assert.New(t)
_, err := Load("testdata/invalid.yml") _, err := Load("testdata/invalid.yml")
assert.EqualError(err, "yaml: line 1: did not find expected node content") assert.EqualError(t, err, "yaml: line 1: did not find expected node content")
} }

View File

@ -9,7 +9,6 @@ import (
) )
func TestMultipleAdds(t *testing.T) { func TestMultipleAdds(t *testing.T) {
var assert = assert.New(t)
var artifacts = []string{ var artifacts = []string{
"dist/a", "dist/a",
"dist/b", "dist/b",
@ -32,7 +31,7 @@ func TestMultipleAdds(t *testing.T) {
return nil return nil
}) })
} }
assert.NoError(g.Wait()) assert.NoError(t, g.Wait())
for _, d := range dockerfiles { for _, d := range dockerfiles {
d := d d := d
g.Go(func() error { g.Go(func() error {
@ -40,15 +39,14 @@ func TestMultipleAdds(t *testing.T) {
return nil return nil
}) })
} }
assert.NoError(g.Wait()) assert.NoError(t, g.Wait())
assert.Len(ctx.Artifacts, len(artifacts)) assert.Len(t, ctx.Artifacts, len(artifacts))
assert.Contains(ctx.Artifacts, "a", "b", "c", "d") assert.Contains(t, ctx.Artifacts, "a", "b", "c", "d")
assert.Len(ctx.Dockers, len(dockerfiles)) assert.Len(t, ctx.Dockers, len(dockerfiles))
assert.Contains(ctx.Dockers, "a/b:1.0.0", "c/d:2.0.0", "e/f:3.0.0") assert.Contains(t, ctx.Dockers, "a/b:1.0.0", "c/d:2.0.0", "e/f:3.0.0")
} }
func TestMultipleBinaryAdds(t *testing.T) { func TestMultipleBinaryAdds(t *testing.T) {
var assert = assert.New(t)
var list = map[string]string{ var list = map[string]string{
"a": "folder/a", "a": "folder/a",
"b": "folder/b", "b": "folder/b",
@ -67,7 +65,7 @@ func TestMultipleBinaryAdds(t *testing.T) {
return nil return nil
}) })
} }
assert.NoError(g.Wait()) assert.NoError(t, g.Wait())
assert.Len(ctx.Binaries["linuxamd64"], len(list)) assert.Len(t, ctx.Binaries["linuxamd64"], len(list))
assert.Len(ctx.Binaries, 1) assert.Len(t, ctx.Binaries, 1)
} }

View File

@ -18,7 +18,6 @@ func init() {
} }
func TestRelease(t *testing.T) { func TestRelease(t *testing.T) {
var assert = assert.New(t)
_, back := setup(t) _, back := setup(t)
defer back() defer back()
var flags = fakeFlags{ var flags = fakeFlags{
@ -29,11 +28,10 @@ func TestRelease(t *testing.T) {
"parallelism": "4", "parallelism": "4",
}, },
} }
assert.NoError(Release(flags)) assert.NoError(t, Release(flags))
} }
func TestSnapshotRelease(t *testing.T) { func TestSnapshotRelease(t *testing.T) {
var assert = assert.New(t)
_, back := setup(t) _, back := setup(t)
defer back() defer back()
var flags = fakeFlags{ var flags = fakeFlags{
@ -42,17 +40,16 @@ func TestSnapshotRelease(t *testing.T) {
"parallelism": "4", "parallelism": "4",
}, },
} }
assert.NoError(Release(flags)) assert.NoError(t, Release(flags))
} }
func TestConfigFileIsSetAndDontExist(t *testing.T) { func TestConfigFileIsSetAndDontExist(t *testing.T) {
var assert = assert.New(t)
var flags = fakeFlags{ var flags = fakeFlags{
flags: map[string]string{ flags: map[string]string{
"config": "/this/wont/exist", "config": "/this/wont/exist",
}, },
} }
assert.Error(Release(flags)) assert.Error(t, Release(flags))
} }
func TestConfigFlagNotSetButExists(t *testing.T) { func TestConfigFlagNotSetButExists(t *testing.T) {
@ -81,17 +78,15 @@ func TestConfigFlagNotSetButExists(t *testing.T) {
} }
func TestReleaseNotesFileDontExist(t *testing.T) { func TestReleaseNotesFileDontExist(t *testing.T) {
var assert = assert.New(t)
var flags = fakeFlags{ var flags = fakeFlags{
flags: map[string]string{ flags: map[string]string{
"release-notes": "/this/also/wont/exist", "release-notes": "/this/also/wont/exist",
}, },
} }
assert.Error(Release(flags)) assert.Error(t, Release(flags))
} }
func TestCustomReleaseNotesFile(t *testing.T) { func TestCustomReleaseNotesFile(t *testing.T) {
var assert = assert.New(t)
folder, back := setup(t) folder, back := setup(t)
defer back() defer back()
var releaseNotes = filepath.Join(folder, "notes.md") var releaseNotes = filepath.Join(folder, "notes.md")
@ -104,11 +99,10 @@ func TestCustomReleaseNotesFile(t *testing.T) {
"parallelism": "4", "parallelism": "4",
}, },
} }
assert.NoError(Release(flags)) assert.NoError(t, Release(flags))
} }
func TestBrokenPipe(t *testing.T) { func TestBrokenPipe(t *testing.T) {
var assert = assert.New(t)
_, back := setup(t) _, back := setup(t)
defer back() defer back()
createFile(t, "main.go", "not a valid go file") createFile(t, "main.go", "not a valid go file")
@ -119,41 +113,38 @@ func TestBrokenPipe(t *testing.T) {
"parallelism": "4", "parallelism": "4",
}, },
} }
assert.Error(Release(flags)) assert.Error(t, Release(flags))
} }
func TestInitProject(t *testing.T) { func TestInitProject(t *testing.T) {
var assert = assert.New(t)
_, back := setup(t) _, back := setup(t)
defer back() defer back()
var filename = "test_goreleaser.yml" var filename = "test_goreleaser.yml"
assert.NoError(InitProject(filename)) assert.NoError(t, InitProject(filename))
file, err := os.Open(filename) file, err := os.Open(filename)
assert.NoError(err) assert.NoError(t, err)
out, err := ioutil.ReadAll(file) out, err := ioutil.ReadAll(file)
assert.NoError(err) assert.NoError(t, err)
var config = config.Project{} var config = config.Project{}
assert.NoError(yaml.Unmarshal(out, &config)) assert.NoError(t, yaml.Unmarshal(out, &config))
} }
func TestInitProjectFileExist(t *testing.T) { func TestInitProjectFileExist(t *testing.T) {
var assert = assert.New(t)
_, back := setup(t) _, back := setup(t)
defer back() defer back()
var filename = "test_goreleaser.yml" var filename = "test_goreleaser.yml"
createFile(t, filename, "") createFile(t, filename, "")
assert.Error(InitProject(filename)) assert.Error(t, InitProject(filename))
} }
func TestInitProjectDefaultPipeFails(t *testing.T) { func TestInitProjectDefaultPipeFails(t *testing.T) {
var assert = assert.New(t)
_, back := setup(t) _, back := setup(t)
defer back() defer back()
var filename = "test_goreleaser.yml" var filename = "test_goreleaser.yml"
assert.NoError(os.RemoveAll(".git")) assert.NoError(t, os.RemoveAll(".git"))
assert.Error(InitProject(filename)) assert.Error(t, InitProject(filename))
} }
// fakeFlags is a mock of the cli flags // fakeFlags is a mock of the cli flags
@ -179,12 +170,11 @@ func (f fakeFlags) Bool(s string) bool {
} }
func setup(t *testing.T) (current string, back func()) { func setup(t *testing.T) (current string, back func()) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleaser") folder, err := ioutil.TempDir("", "goreleaser")
assert.NoError(err) assert.NoError(t, err)
previous, err := os.Getwd() previous, err := os.Getwd()
assert.NoError(err) assert.NoError(t, err)
assert.NoError(os.Chdir(folder)) assert.NoError(t, os.Chdir(folder))
createGoreleaserYaml(t) createGoreleaserYaml(t)
createMainGo(t) createMainGo(t)
testlib.GitInit(t) testlib.GitInit(t)
@ -197,13 +187,12 @@ func setup(t *testing.T) (current string, back func()) {
testlib.GitTag(t, "v0.0.2") testlib.GitTag(t, "v0.0.2")
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/fake.git") testlib.GitRemoteAdd(t, "git@github.com:goreleaser/fake.git")
return folder, func() { return folder, func() {
assert.NoError(os.Chdir(previous)) assert.NoError(t, os.Chdir(previous))
} }
} }
func createFile(t *testing.T, filename, contents string) { func createFile(t *testing.T, filename, contents string) {
var assert = assert.New(t) assert.NoError(t, ioutil.WriteFile(filename, []byte(contents), 0644))
assert.NoError(ioutil.WriteFile(filename, []byte(contents), 0644))
} }
func createMainGo(t *testing.T) { func createMainGo(t *testing.T) {

View File

@ -9,7 +9,6 @@ import (
) )
func TestFormatFor(t *testing.T) { func TestFormatFor(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Archive: config.Archive{ Archive: config.Archive{
@ -23,6 +22,6 @@ func TestFormatFor(t *testing.T) {
}, },
}, },
} }
assert.Equal("zip", For(ctx, "windowsamd64")) assert.Equal(t, "zip", For(ctx, "windowsamd64"))
assert.Equal("tar.gz", For(ctx, "linux386")) assert.Equal(t, "tar.gz", For(ctx, "linux386"))
} }

View File

@ -7,24 +7,24 @@ import (
) )
func TestEnv(t *testing.T) { func TestEnv(t *testing.T) {
var assert = assert.New(t)
assert.Equal( assert.Equal(
t,
[]string{"GOOS=linux", "GOARCH=arm64", "GOARM=6"}, []string{"GOOS=linux", "GOARCH=arm64", "GOARM=6"},
New("linux", "arm64", "6").Env(), New("linux", "arm64", "6").Env(),
) )
} }
func TestString(t *testing.T) { func TestString(t *testing.T) {
var assert = assert.New(t)
assert.Equal( assert.Equal(
t,
"linuxarm7", "linuxarm7",
New("linux", "arm", "7").String(), New("linux", "arm", "7").String(),
) )
} }
func TestPrettyString(t *testing.T) { func TestPrettyString(t *testing.T) {
var assert = assert.New(t)
assert.Equal( assert.Equal(
t,
"linux/arm646", "linux/arm646",
New("linux", "arm64", "6").PrettyString(), New("linux", "arm64", "6").PrettyString(),
) )

View File

@ -9,7 +9,6 @@ import (
) )
func TestAllBuildTargets(t *testing.T) { func TestAllBuildTargets(t *testing.T) {
var assert = assert.New(t)
var build = config.Build{ var build = config.Build{
Goos: []string{ Goos: []string{
"linux", "linux",
@ -41,7 +40,7 @@ func TestAllBuildTargets(t *testing.T) {
}, },
}, },
} }
assert.Equal([]Target{ assert.Equal(t, []Target{
New("linux", "386", ""), New("linux", "386", ""),
New("linux", "amd64", ""), New("linux", "amd64", ""),
New("linux", "arm", "6"), New("linux", "arm", "6"),

View File

@ -1,25 +1,21 @@
package git_test package git
import ( import (
"testing" "testing"
"github.com/goreleaser/goreleaser/internal/git"
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestGit(t *testing.T) { func TestGit(t *testing.T) {
var assert = assert.New(t) out, err := Run("status")
_, back := testlib.Mktmp(t) assert.NoError(t, err)
defer back() assert.NotEmpty(t, out)
out, err := git.Run("init")
assert.NoError(err)
assert.Contains(out, "Initialized empty Git repository")
out, err = git.Run("command-that-dont-exist") out, err = Run("command-that-dont-exist")
assert.Error(err) assert.Error(t, err)
assert.Empty(out) assert.Empty(t, out)
assert.Equal( assert.Equal(
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(),
) )

View File

@ -11,8 +11,6 @@ import (
) )
func TestChecksums(t *testing.T) { func TestChecksums(t *testing.T) {
var assert = assert.New(t)
var config = config.Project{ var config = config.Project{
Checksum: config.Checksum{ Checksum: config.Checksum{
NameTemplate: "{{.ProjectName }}_{{.Tag}}_{{.Version}}_checksums.txt", NameTemplate: "{{.ProjectName }}_{{.Tag}}_{{.Version}}_checksums.txt",
@ -28,13 +26,11 @@ func TestChecksums(t *testing.T) {
} }
name, err := ForChecksums(ctx) name, err := ForChecksums(ctx)
assert.NoError(err) assert.NoError(t, err)
assert.Equal("testcheck_v1.0.0_1.0.0_checksums.txt", name) assert.Equal(t, "testcheck_v1.0.0_1.0.0_checksums.txt", name)
} }
func TestNameFor(t *testing.T) { func TestNameFor(t *testing.T) {
var assert = assert.New(t)
var config = config.Project{ var config = config.Project{
Archive: config.Archive{ Archive: config.Archive{
NameTemplate: "{{.Binary}}_{{.Os}}_{{.Arch}}_{{.Tag}}_{{.Version}}", NameTemplate: "{{.Binary}}_{{.Os}}_{{.Arch}}_{{.Tag}}_{{.Version}}",
@ -54,13 +50,11 @@ func TestNameFor(t *testing.T) {
} }
name, err := For(ctx, buildtarget.New("darwin", "amd64", "")) name, err := For(ctx, buildtarget.New("darwin", "amd64", ""))
assert.NoError(err) assert.NoError(t, err)
assert.Equal("test_Darwin_x86_64_v1.2.3_1.2.3", name) assert.Equal(t, "test_Darwin_x86_64_v1.2.3_1.2.3", name)
} }
func TestNameForBuild(t *testing.T) { func TestNameForBuild(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Archive: config.Archive{ Archive: config.Archive{
@ -83,12 +77,11 @@ func TestNameForBuild(t *testing.T) {
config.Build{Binary: "foo"}, config.Build{Binary: "foo"},
buildtarget.New("darwin", "amd64", ""), buildtarget.New("darwin", "amd64", ""),
) )
assert.NoError(err) assert.NoError(t, err)
assert.Equal("foo_Darwin_x86_64_v1.2.3_1.2.3", name) assert.Equal(t, "foo_Darwin_x86_64_v1.2.3_1.2.3", name)
} }
func TestInvalidNameTemplate(t *testing.T) { func TestInvalidNameTemplate(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Archive: config.Archive{ Archive: config.Archive{
@ -102,11 +95,10 @@ func TestInvalidNameTemplate(t *testing.T) {
} }
_, err := For(ctx, buildtarget.New("darwin", "amd64", "")) _, err := For(ctx, buildtarget.New("darwin", "amd64", ""))
assert.Error(err) assert.Error(t, err)
} }
func TestNameDefaultTemplate(t *testing.T) { func TestNameDefaultTemplate(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Archive: config.Archive{ Archive: config.Archive{
@ -123,8 +115,8 @@ func TestNameDefaultTemplate(t *testing.T) {
} { } {
t.Run(key, func(t *testing.T) { t.Run(key, func(t *testing.T) {
name, err := For(ctx, target) name, err := For(ctx, target)
assert.NoError(err) assert.NoError(t, err)
assert.Equal(key, name) assert.Equal(t, key, name)
}) })
} }
} }

View File

@ -9,43 +9,38 @@ import (
// GitInit inits a new git project // GitInit inits a new git project
func GitInit(t *testing.T) { func GitInit(t *testing.T) {
var assert = assert.New(t)
out, err := fakeGit("init") out, err := fakeGit("init")
assert.NoError(err) assert.NoError(t, err)
assert.Contains(out, "Initialized empty Git repository") assert.Contains(t, out, "Initialized empty Git repository")
assert.NoError(err) assert.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) {
var assert = assert.New(t)
out, err := fakeGit("remote", "add", "origin", url) out, err := fakeGit("remote", "add", "origin", url)
assert.NoError(err) assert.NoError(t, err)
assert.Empty(out) assert.Empty(t, out)
} }
// GitCommit creates a git commits // GitCommit creates a git commits
func GitCommit(t *testing.T, msg string) { func GitCommit(t *testing.T, msg string) {
var assert = assert.New(t)
out, err := fakeGit("commit", "--allow-empty", "-m", msg) out, err := fakeGit("commit", "--allow-empty", "-m", msg)
assert.NoError(err) assert.NoError(t, err)
assert.Contains(out, "master", msg) assert.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) {
var assert = assert.New(t)
out, err := fakeGit("tag", tag) out, err := fakeGit("tag", tag)
assert.NoError(err) assert.NoError(t, err)
assert.Empty(out) assert.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) {
var assert = assert.New(t)
out, err := fakeGit("add", "-A") out, err := fakeGit("add", "-A")
assert.NoError(err) assert.NoError(t, err)
assert.Empty(out) assert.Empty(t, out)
} }
func fakeGit(args ...string) (string, error) { func fakeGit(args ...string) (string, error) {

View File

@ -12,13 +12,12 @@ import (
// 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()) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
current, err := os.Getwd() current, err := os.Getwd()
assert.NoError(err) assert.NoError(t, err)
assert.NoError(os.Chdir(folder)) assert.NoError(t, os.Chdir(folder))
return folder, func() { return folder, func() {
assert.NoError(os.Chdir(current)) assert.NoError(t, os.Chdir(current))
} }
} }

View File

@ -8,13 +8,12 @@ import (
) )
func TestMkTemp(t *testing.T) { func TestMkTemp(t *testing.T) {
var assert = assert.New(t)
current, err := os.Getwd() current, err := os.Getwd()
assert.NoError(err) assert.NoError(t, err)
folder, back := Mktmp(t) folder, back := Mktmp(t)
assert.NotEmpty(folder) assert.NotEmpty(t, folder)
back() back()
newCurrent, err := os.Getwd() newCurrent, err := os.Getwd()
assert.NoError(err) assert.NoError(t, err)
assert.Equal(current, newCurrent) assert.Equal(t, current, newCurrent)
} }

View File

@ -16,19 +16,18 @@ func TestDescription(t *testing.T) {
} }
func TestRunPipe(t *testing.T) { func TestRunPipe(t *testing.T) {
var assert = assert.New(t)
folder, back := testlib.Mktmp(t) folder, back := testlib.Mktmp(t)
defer back() defer back()
var dist = filepath.Join(folder, "dist") var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755)) assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin_darwin_amd64"), 0755)) assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin_darwin_amd64"), 0755))
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin_windows_amd64"), 0755)) assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin_windows_amd64"), 0755))
_, err := os.Create(filepath.Join(dist, "mybin_darwin_amd64", "mybin")) _, err := os.Create(filepath.Join(dist, "mybin_darwin_amd64", "mybin"))
assert.NoError(err) assert.NoError(t, err)
_, err = os.Create(filepath.Join(dist, "mybin_windows_amd64", "mybin.exe")) _, err = os.Create(filepath.Join(dist, "mybin_windows_amd64", "mybin.exe"))
assert.NoError(err) assert.NoError(t, err)
_, err = os.Create(filepath.Join(folder, "README.md")) _, err = os.Create(filepath.Join(folder, "README.md"))
assert.NoError(err) assert.NoError(t, err)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Dist: dist, Dist: dist,
@ -50,25 +49,24 @@ func TestRunPipe(t *testing.T) {
for _, format := range []string{"tar.gz", "zip"} { for _, format := range []string{"tar.gz", "zip"} {
t.Run("Archive format "+format, func(t *testing.T) { t.Run("Archive format "+format, func(t *testing.T) {
ctx.Config.Archive.Format = format ctx.Config.Archive.Format = format
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
}) })
} }
} }
func TestRunPipeBinary(t *testing.T) { func TestRunPipeBinary(t *testing.T) {
var assert = assert.New(t)
folder, back := testlib.Mktmp(t) folder, back := testlib.Mktmp(t)
defer back() defer back()
var dist = filepath.Join(folder, "dist") var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755)) assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin_darwin"), 0755)) assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin_darwin"), 0755))
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin_win"), 0755)) assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin_win"), 0755))
_, err := os.Create(filepath.Join(dist, "mybin_darwin", "mybin")) _, err := os.Create(filepath.Join(dist, "mybin_darwin", "mybin"))
assert.NoError(err) assert.NoError(t, err)
_, err = os.Create(filepath.Join(dist, "mybin_win", "mybin.exe")) _, err = os.Create(filepath.Join(dist, "mybin_win", "mybin.exe"))
assert.NoError(err) assert.NoError(t, err)
_, err = os.Create(filepath.Join(folder, "README.md")) _, err = os.Create(filepath.Join(folder, "README.md"))
assert.NoError(err) assert.NoError(t, err)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Dist: dist, Dist: dist,
@ -82,14 +80,13 @@ func TestRunPipeBinary(t *testing.T) {
} }
ctx.AddBinary("darwinamd64", "mybin_darwin", "mybin", filepath.Join(dist, "mybin_darwin", "mybin")) ctx.AddBinary("darwinamd64", "mybin_darwin", "mybin", filepath.Join(dist, "mybin_darwin", "mybin"))
ctx.AddBinary("windowsamd64", "mybin_win", "mybin.exe", filepath.Join(dist, "mybin_win", "mybin.exe")) ctx.AddBinary("windowsamd64", "mybin_win", "mybin.exe", filepath.Join(dist, "mybin_win", "mybin.exe"))
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
assert.Contains(ctx.Artifacts, "mybin_darwin/mybin") assert.Contains(t, ctx.Artifacts, "mybin_darwin/mybin")
assert.Contains(ctx.Artifacts, "mybin_win/mybin.exe") assert.Contains(t, ctx.Artifacts, "mybin_win/mybin.exe")
assert.Len(ctx.Artifacts, 2) assert.Len(t, ctx.Artifacts, 2)
} }
func TestRunPipeDistRemoved(t *testing.T) { func TestRunPipeDistRemoved(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Dist: "/path/nope", Dist: "/path/nope",
@ -99,11 +96,10 @@ func TestRunPipeDistRemoved(t *testing.T) {
}, },
} }
ctx.AddBinary("windowsamd64", "nope", "no", "blah") ctx.AddBinary("windowsamd64", "nope", "no", "blah")
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
} }
func TestRunPipeInvalidGlob(t *testing.T) { func TestRunPipeInvalidGlob(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Dist: "/tmp", Dist: "/tmp",
@ -115,14 +111,13 @@ func TestRunPipeInvalidGlob(t *testing.T) {
}, },
} }
ctx.AddBinary("windowsamd64", "whatever", "foo", "bar") ctx.AddBinary("windowsamd64", "whatever", "foo", "bar")
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
} }
func TestRunPipeGlobFailsToAdd(t *testing.T) { func TestRunPipeGlobFailsToAdd(t *testing.T) {
var assert = assert.New(t)
folder, back := testlib.Mktmp(t) folder, back := testlib.Mktmp(t)
defer back() defer back()
assert.NoError(os.MkdirAll(filepath.Join(folder, "folder", "another"), 0755)) assert.NoError(t, os.MkdirAll(filepath.Join(folder, "folder", "another"), 0755))
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
@ -135,5 +130,5 @@ func TestRunPipeGlobFailsToAdd(t *testing.T) {
}, },
} }
ctx.AddBinary("windows386", "mybin", "mybin", "dist/mybin") ctx.AddBinary("windows386", "mybin", "mybin", "dist/mybin")
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
} }

View File

@ -45,16 +45,14 @@ var defaultTemplateData = templateData{
} }
func assertDefaultTemplateData(t *testing.T, formulae string) { func assertDefaultTemplateData(t *testing.T, formulae string) {
assert := assert.New(t) assert.Contains(t, formulae, "class Test < Formula")
assert.Contains(formulae, "class Test < Formula") assert.Contains(t, formulae, `homepage "https://google.com"`)
assert.Contains(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"`)
assert.Contains(formulae, `url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`) assert.Contains(t, formulae, `sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`)
assert.Contains(formulae, `sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`) assert.Contains(t, formulae, `version "0.1.3"`)
assert.Contains(formulae, `version "0.1.3"`)
} }
func TestFullFormulae(t *testing.T) { func TestFullFormulae(t *testing.T) {
assert := assert.New(t)
data := defaultTemplateData data := defaultTemplateData
data.Caveats = "Here are some caveats" data.Caveats = "Here are some caveats"
data.Dependencies = []string{"gtk+"} data.Dependencies = []string{"gtk+"}
@ -63,37 +61,34 @@ func TestFullFormulae(t *testing.T) {
data.Install = []string{"custom install script", "another install script"} data.Install = []string{"custom install script", "another install script"}
data.Tests = []string{`system "#{bin}/foo -version"`} data.Tests = []string{`system "#{bin}/foo -version"`}
out, err := doBuildFormula(data) out, err := doBuildFormula(data)
assert.NoError(err) assert.NoError(t, err)
formulae := out.String() formulae := out.String()
bts, err := ioutil.ReadFile("testdata/test.rb") bts, err := ioutil.ReadFile("testdata/test.rb")
assert.NoError(err) assert.NoError(t, err)
// ioutil.WriteFile("testdata/test.rb", []byte(formulae), 0644) // ioutil.WriteFile("testdata/test.rb", []byte(formulae), 0644)
assert.Equal(string(bts), formulae) assert.Equal(t, string(bts), formulae)
} }
func TestFormulaeSimple(t *testing.T) { func TestFormulaeSimple(t *testing.T) {
assert := assert.New(t)
out, err := doBuildFormula(defaultTemplateData) out, err := doBuildFormula(defaultTemplateData)
assert.NoError(err) assert.NoError(t, err)
formulae := out.String() formulae := out.String()
assertDefaultTemplateData(t, formulae) assertDefaultTemplateData(t, formulae)
assert.NotContains(formulae, "def caveats") assert.NotContains(t, formulae, "def caveats")
assert.NotContains(formulae, "depends_on") assert.NotContains(t, formulae, "depends_on")
assert.NotContains(formulae, "def plist;") assert.NotContains(t, formulae, "def plist;")
} }
func TestSplit(t *testing.T) { func TestSplit(t *testing.T) {
var assert = assert.New(t)
var parts = split("system \"true\"\nsystem \"#{bin}/foo -h\"") var parts = split("system \"true\"\nsystem \"#{bin}/foo -h\"")
assert.Equal([]string{"system \"true\"", "system \"#{bin}/foo -h\""}, parts) assert.Equal(t, []string{"system \"true\"", "system \"#{bin}/foo -h\""}, parts)
} }
func TestRunPipe(t *testing.T) { func TestRunPipe(t *testing.T) {
assert := assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.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",
@ -131,27 +126,27 @@ func TestRunPipe(t *testing.T) {
var path = filepath.Join(folder, "bin.tar.gz") var path = filepath.Join(folder, "bin.tar.gz")
ctx.AddBinary("darwinamd64", "bin", "bin", path) ctx.AddBinary("darwinamd64", "bin", "bin", path)
client := &DummyClient{} client := &DummyClient{}
assert.Error(doRun(ctx, client)) assert.Error(t, doRun(ctx, client))
assert.False(client.CreatedFile) assert.False(t, client.CreatedFile)
_, err = os.Create(path) _, err = os.Create(path)
assert.NoError(err) assert.NoError(t, err)
assert.NoError(doRun(ctx, client)) assert.NoError(t, doRun(ctx, client))
assert.True(client.CreatedFile) assert.True(t, client.CreatedFile)
bts, err := ioutil.ReadFile("testdata/run_pipe.rb") bts, err := ioutil.ReadFile("testdata/run_pipe.rb")
assert.NoError(err) assert.NoError(t, err)
// assert.NoError(ioutil.WriteFile("testdata/run_pipe.rb", []byte(client.Content), 0644)) // assert.NoError(ioutil.WriteFile("testdata/run_pipe.rb", []byte(client.Content), 0644))
assert.Equal(string(bts), client.Content)
assert.Equal(t, string(bts), client.Content)
} }
func TestRunPipeFormatOverride(t *testing.T) { func TestRunPipeFormatOverride(t *testing.T) {
assert := assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
var path = filepath.Join(folder, "bin.zip") var path = filepath.Join(folder, "bin.zip")
_, err = os.Create(path) _, err = os.Create(path)
assert.NoError(err) assert.NoError(t, err)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Dist: folder, Dist: folder,
@ -175,13 +170,12 @@ func TestRunPipeFormatOverride(t *testing.T) {
} }
ctx.AddBinary("darwinamd64", "bin", "bin", path) ctx.AddBinary("darwinamd64", "bin", "bin", path)
client := &DummyClient{} client := &DummyClient{}
assert.NoError(doRun(ctx, client)) assert.NoError(t, doRun(ctx, client))
assert.True(client.CreatedFile) assert.True(t, client.CreatedFile)
assert.Contains(client.Content, "bin.zip") assert.Contains(t, client.Content, "bin.zip")
} }
func TestRunPipeNoDarwin64Build(t *testing.T) { func TestRunPipeNoDarwin64Build(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Archive: config.Archive{ Archive: config.Archive{
@ -197,23 +191,21 @@ func TestRunPipeNoDarwin64Build(t *testing.T) {
Publish: true, Publish: true,
} }
client := &DummyClient{} client := &DummyClient{}
assert.Equal(ErrNoDarwin64Build, doRun(ctx, client)) assert.Equal(t, ErrNoDarwin64Build, doRun(ctx, client))
assert.False(client.CreatedFile) assert.False(t, client.CreatedFile)
} }
func TestRunPipeBrewNotSetup(t *testing.T) { func TestRunPipeBrewNotSetup(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{}, Config: config.Project{},
Publish: true, Publish: true,
} }
client := &DummyClient{} client := &DummyClient{}
testlib.AssertSkipped(t, doRun(ctx, client)) testlib.AssertSkipped(t, doRun(ctx, client))
assert.False(client.CreatedFile) assert.False(t, client.CreatedFile)
} }
func TestRunPipeBinaryRelease(t *testing.T) { func TestRunPipeBinaryRelease(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Publish: true, Publish: true,
Config: config.Project{ Config: config.Project{
@ -231,21 +223,19 @@ func TestRunPipeBinaryRelease(t *testing.T) {
ctx.AddBinary("darwinamd64", "foo", "bar", "baz") ctx.AddBinary("darwinamd64", "foo", "bar", "baz")
client := &DummyClient{} client := &DummyClient{}
testlib.AssertSkipped(t, doRun(ctx, client)) testlib.AssertSkipped(t, doRun(ctx, client))
assert.False(client.CreatedFile) assert.False(t, client.CreatedFile)
} }
func TestRunPipeNoPublish(t *testing.T) { func TestRunPipeNoPublish(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Publish: false, Publish: false,
} }
client := &DummyClient{} client := &DummyClient{}
testlib.AssertSkipped(t, doRun(ctx, client)) testlib.AssertSkipped(t, doRun(ctx, client))
assert.False(client.CreatedFile) assert.False(t, client.CreatedFile)
} }
func TestRunPipeDraftRelease(t *testing.T) { func TestRunPipeDraftRelease(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Publish: true, Publish: true,
Config: config.Project{ Config: config.Project{
@ -262,11 +252,10 @@ func TestRunPipeDraftRelease(t *testing.T) {
} }
client := &DummyClient{} client := &DummyClient{}
testlib.AssertSkipped(t, doRun(ctx, client)) testlib.AssertSkipped(t, doRun(ctx, client))
assert.False(client.CreatedFile) assert.False(t, client.CreatedFile)
} }
func TestRunPipeFormatBinary(t *testing.T) { func TestRunPipeFormatBinary(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Archive: config.Archive{ Archive: config.Archive{
@ -276,7 +265,7 @@ func TestRunPipeFormatBinary(t *testing.T) {
} }
client := &DummyClient{} client := &DummyClient{}
testlib.AssertSkipped(t, doRun(ctx, client)) testlib.AssertSkipped(t, doRun(ctx, client))
assert.False(client.CreatedFile) assert.False(t, client.CreatedFile)
} }
type DummyClient struct { type DummyClient struct {

View File

@ -28,7 +28,6 @@ func TestRunInvalidCommand(t *testing.T) {
} }
func TestBuild(t *testing.T) { func TestBuild(t *testing.T) {
assert := assert.New(t)
var config = config.Project{ var config = config.Project{
Builds: []config.Build{ Builds: []config.Build{
{ {
@ -39,13 +38,12 @@ func TestBuild(t *testing.T) {
}, },
} }
var ctx = context.New(config) var ctx = context.New(config)
assert.NoError(doBuild(ctx, ctx.Config.Builds[0], buildtarget.Runtime)) assert.NoError(t, doBuild(ctx, ctx.Config.Builds[0], buildtarget.Runtime))
} }
func TestRunFullPipe(t *testing.T) { func TestRunFullPipe(t *testing.T) {
assert := assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
var binary = filepath.Join(folder, "testing") var binary = filepath.Join(folder, "testing")
var pre = filepath.Join(folder, "pre") var pre = filepath.Join(folder, "pre")
var post = filepath.Join(folder, "post") var post = filepath.Join(folder, "post")
@ -69,16 +67,15 @@ func TestRunFullPipe(t *testing.T) {
}, },
}, },
} }
assert.NoError(Pipe{}.Run(context.New(config))) assert.NoError(t, Pipe{}.Run(context.New(config)))
assert.True(exists(binary), binary) assert.True(t, exists(binary), binary)
assert.True(exists(pre), pre) assert.True(t, exists(pre), pre)
assert.True(exists(post), post) assert.True(t, exists(post), post)
} }
func TestRunPipeFormatBinary(t *testing.T) { func TestRunPipeFormatBinary(t *testing.T) {
assert := assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
var binary = filepath.Join(folder, "binary-testing") var binary = filepath.Join(folder, "binary-testing")
var config = config.Project{ var config = config.Project{
ProjectName: "testing", ProjectName: "testing",
@ -99,14 +96,13 @@ func TestRunPipeFormatBinary(t *testing.T) {
NameTemplate: "binary-{{.Binary}}", NameTemplate: "binary-{{.Binary}}",
}, },
} }
assert.NoError(Pipe{}.Run(context.New(config))) assert.NoError(t, Pipe{}.Run(context.New(config)))
assert.True(exists(binary)) assert.True(t, exists(binary))
} }
func TestRunPipeArmBuilds(t *testing.T) { func TestRunPipeArmBuilds(t *testing.T) {
assert := assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
var binary = filepath.Join(folder, "armtesting") var binary = filepath.Join(folder, "armtesting")
var config = config.Project{ var config = config.Project{
Dist: folder, Dist: folder,
@ -128,12 +124,11 @@ func TestRunPipeArmBuilds(t *testing.T) {
}, },
}, },
} }
assert.NoError(Pipe{}.Run(context.New(config))) assert.NoError(t, Pipe{}.Run(context.New(config)))
assert.True(exists(binary), binary) assert.True(t, exists(binary), binary)
} }
func TestBuildFailed(t *testing.T) { func TestBuildFailed(t *testing.T) {
assert := assert.New(t)
var config = config.Project{ var config = config.Project{
Builds: []config.Build{ Builds: []config.Build{
{ {
@ -147,11 +142,10 @@ func TestBuildFailed(t *testing.T) {
}, },
}, },
} }
assert.Error(Pipe{}.Run(context.New(config))) assert.Error(t, Pipe{}.Run(context.New(config)))
} }
func TestRunPipeWithInvalidOS(t *testing.T) { func TestRunPipeWithInvalidOS(t *testing.T) {
assert := assert.New(t)
var config = config.Project{ var config = config.Project{
Builds: []config.Build{ Builds: []config.Build{
{ {
@ -165,11 +159,10 @@ func TestRunPipeWithInvalidOS(t *testing.T) {
}, },
}, },
} }
assert.NoError(Pipe{}.Run(context.New(config))) assert.NoError(t, Pipe{}.Run(context.New(config)))
} }
func TestRunInvalidNametemplate(t *testing.T) { func TestRunInvalidNametemplate(t *testing.T) {
var assert = assert.New(t)
for _, format := range []string{"tar.gz", "zip", "binary"} { for _, format := range []string{"tar.gz", "zip", "binary"} {
var config = config.Project{ var config = config.Project{
ProjectName: "nameeeee", ProjectName: "nameeeee",
@ -190,12 +183,11 @@ func TestRunInvalidNametemplate(t *testing.T) {
NameTemplate: "{{.Binary}", NameTemplate: "{{.Binary}",
}, },
} }
assert.Error(Pipe{}.Run(context.New(config))) assert.Error(t, Pipe{}.Run(context.New(config)))
} }
} }
func TestRunInvalidLdflags(t *testing.T) { func TestRunInvalidLdflags(t *testing.T) {
var assert = assert.New(t)
var config = config.Project{ var config = config.Project{
Builds: []config.Build{ Builds: []config.Build{
{ {
@ -211,11 +203,10 @@ func TestRunInvalidLdflags(t *testing.T) {
}, },
}, },
} }
assert.Error(Pipe{}.Run(context.New(config))) assert.Error(t, Pipe{}.Run(context.New(config)))
} }
func TestRunPipeFailingHooks(t *testing.T) { func TestRunPipeFailingHooks(t *testing.T) {
assert := assert.New(t)
var config = config.Project{ var config = config.Project{
Builds: []config.Build{ Builds: []config.Build{
{ {
@ -232,11 +223,11 @@ func TestRunPipeFailingHooks(t *testing.T) {
var ctx = context.New(config) var ctx = context.New(config)
t.Run("pre-hook", func(t *testing.T) { t.Run("pre-hook", func(t *testing.T) {
ctx.Config.Builds[0].Hooks.Pre = "exit 1" ctx.Config.Builds[0].Hooks.Pre = "exit 1"
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
}) })
t.Run("post-hook", func(t *testing.T) { t.Run("post-hook", func(t *testing.T) {
ctx.Config.Builds[0].Hooks.Post = "exit 1" ctx.Config.Builds[0].Hooks.Post = "exit 1"
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
}) })
} }

View File

@ -9,7 +9,6 @@ import (
) )
func TestLdFlagsFullTemplate(t *testing.T) { func TestLdFlagsFullTemplate(t *testing.T) {
assert := assert.New(t)
var config = config.Project{ var config = config.Project{
Builds: []config.Build{ Builds: []config.Build{
{ {
@ -26,16 +25,15 @@ func TestLdFlagsFullTemplate(t *testing.T) {
Config: config, Config: config,
} }
flags, err := ldflags(ctx, ctx.Config.Builds[0]) flags, err := ldflags(ctx, ctx.Config.Builds[0])
assert.NoError(err) assert.NoError(t, err)
assert.Contains(flags, "-s -w") assert.Contains(t, flags, "-s -w")
assert.Contains(flags, "-X main.version=1.2.3") assert.Contains(t, flags, "-X main.version=1.2.3")
assert.Contains(flags, "-X main.tag=v1.2.3") assert.Contains(t, flags, "-X main.tag=v1.2.3")
assert.Contains(flags, "-X main.commit=123") assert.Contains(t, flags, "-X main.commit=123")
assert.Contains(flags, "-X main.date=") assert.Contains(t, flags, "-X main.date=")
} }
func TestInvalidTemplate(t *testing.T) { func TestInvalidTemplate(t *testing.T) {
assert := assert.New(t)
var config = config.Project{ var config = config.Project{
Builds: []config.Build{ Builds: []config.Build{
{Ldflags: "{invalid{.Template}}}{{}}}"}, {Ldflags: "{invalid{.Template}}}{{}}}"},
@ -45,6 +43,6 @@ func TestInvalidTemplate(t *testing.T) {
Config: config, Config: config,
} }
flags, err := ldflags(ctx, ctx.Config.Builds[0]) flags, err := ldflags(ctx, ctx.Config.Builds[0])
assert.Error(err) assert.Error(t, err)
assert.Equal(flags, "") assert.Equal(t, flags, "")
} }

View File

@ -15,13 +15,12 @@ func TestDescription(t *testing.T) {
} }
func TestPipe(t *testing.T) { func TestPipe(t *testing.T) {
var assert = assert.New(t)
var binary = "binary" var binary = "binary"
var checksums = binary + "_checksums.txt" var checksums = binary + "_checksums.txt"
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
var file = filepath.Join(folder, binary) var file = filepath.Join(folder, binary)
assert.NoError(ioutil.WriteFile(file, []byte("some string"), 0644)) assert.NoError(t, ioutil.WriteFile(file, []byte("some string"), 0644))
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Dist: folder, Dist: folder,
@ -32,17 +31,16 @@ func TestPipe(t *testing.T) {
}, },
} }
ctx.AddArtifact(file) ctx.AddArtifact(file)
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
assert.Contains(ctx.Artifacts, checksums, binary) assert.Contains(t, ctx.Artifacts, checksums, binary)
bts, err := ioutil.ReadFile(filepath.Join(folder, checksums)) bts, err := ioutil.ReadFile(filepath.Join(folder, checksums))
assert.NoError(err) assert.NoError(t, err)
assert.Equal(string(bts), "61d034473102d7dac305902770471fd50f4c5b26f6831a56dd90b5184b3c30fc binary\n") assert.Equal(t, string(bts), "61d034473102d7dac305902770471fd50f4c5b26f6831a56dd90b5184b3c30fc binary\n")
} }
func TestPipeFileNotExist(t *testing.T) { func TestPipeFileNotExist(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Dist: folder, Dist: folder,
@ -53,14 +51,13 @@ func TestPipeFileNotExist(t *testing.T) {
} }
ctx.AddArtifact("nope") ctx.AddArtifact("nope")
err = Pipe{}.Run(ctx) err = Pipe{}.Run(ctx)
assert.Error(err) assert.Error(t, err)
assert.Contains(err.Error(), "/nope: no such file or directory") assert.Contains(t, err.Error(), "/nope: no such file or directory")
} }
func TestPipeInvalidNameTemplate(t *testing.T) { func TestPipeInvalidNameTemplate(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Dist: folder, Dist: folder,
@ -72,16 +69,15 @@ func TestPipeInvalidNameTemplate(t *testing.T) {
} }
ctx.AddArtifact("whatever") ctx.AddArtifact("whatever")
err = Pipe{}.Run(ctx) err = Pipe{}.Run(ctx)
assert.Error(err) assert.Error(t, err)
assert.Equal(`template: name:1: unexpected "}" in operand`, err.Error()) assert.Equal(t, `template: name:1: unexpected "}" in operand`, err.Error())
} }
func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) { func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
var file = filepath.Join(folder, "checksums.txt") var file = filepath.Join(folder, "checksums.txt")
assert.NoError(ioutil.WriteFile(file, []byte("some string"), 0000)) assert.NoError(t, ioutil.WriteFile(file, []byte("some string"), 0000))
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Dist: folder, Dist: folder,
@ -92,6 +88,6 @@ func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) {
} }
ctx.AddArtifact("nope") ctx.AddArtifact("nope")
err = Pipe{}.Run(ctx) err = Pipe{}.Run(ctx)
assert.Error(err) assert.Error(t, err)
assert.Contains(err.Error(), "/checksums.txt: permission denied") assert.Contains(t, err.Error(), "/checksums.txt: permission denied")
} }

View File

@ -12,8 +12,8 @@ import (
) )
func TestDistDoesNotExist(t *testing.T) { func TestDistDoesNotExist(t *testing.T) {
var assert = assert.New(t)
assert.NoError( assert.NoError(
t,
Pipe{}.Run( Pipe{}.Run(
&context.Context{ &context.Context{
Config: config.Project{ Config: config.Project{
@ -25,42 +25,39 @@ func TestDistDoesNotExist(t *testing.T) {
} }
func TestPopulatedDistExists(t *testing.T) { func TestPopulatedDistExists(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "disttest") folder, err := ioutil.TempDir("", "disttest")
assert.NoError(err) assert.NoError(t, err)
var dist = filepath.Join(folder, "dist") var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755)) assert.NoError(t, os.Mkdir(dist, 0755))
_, err = os.Create(filepath.Join(dist, "mybin")) _, err = os.Create(filepath.Join(dist, "mybin"))
assert.NoError(err) assert.NoError(t, err)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Dist: dist, Dist: dist,
}, },
} }
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
ctx.RmDist = true ctx.RmDist = true
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
_, err = os.Stat(dist) _, err = os.Stat(dist)
assert.False(os.IsExist(err)) assert.False(t, os.IsExist(err))
} }
func TestEmptyDistExists(t *testing.T) { func TestEmptyDistExists(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "disttest") folder, err := ioutil.TempDir("", "disttest")
assert.NoError(err) assert.NoError(t, err)
var dist = filepath.Join(folder, "dist") var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755)) assert.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(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
_, err = os.Stat(dist) _, err = os.Stat(dist)
assert.False(os.IsExist(err)) assert.False(t, os.IsExist(err))
} }
func TestDescription(t *testing.T) { func TestDescription(t *testing.T) {
var assert = assert.New(t) assert.NotEmpty(t, Pipe{}.Description())
assert.NotEmpty(Pipe{}.Description())
} }

View File

@ -15,27 +15,27 @@ func TestDescription(t *testing.T) {
} }
func TestFillBasicData(t *testing.T) { func TestFillBasicData(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{}, Config: config.Project{},
} }
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
assert.Equal("goreleaser", ctx.Config.Release.GitHub.Owner) assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
assert.Equal("goreleaser", ctx.Config.Release.GitHub.Name) assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
assert.NotEmpty(ctx.Config.Builds) assert.NotEmpty(t, ctx.Config.Builds)
assert.Equal("goreleaser", ctx.Config.Builds[0].Binary) assert.Equal(t, "goreleaser", ctx.Config.Builds[0].Binary)
assert.Equal(".", ctx.Config.Builds[0].Main) assert.Equal(t, ".", ctx.Config.Builds[0].Main)
assert.Contains(ctx.Config.Builds[0].Goos, "darwin") assert.Contains(t, ctx.Config.Builds[0].Goos, "darwin")
assert.Contains(ctx.Config.Builds[0].Goos, "linux") assert.Contains(t, ctx.Config.Builds[0].Goos, "linux")
assert.Contains(ctx.Config.Builds[0].Goarch, "386") assert.Contains(t, ctx.Config.Builds[0].Goarch, "386")
assert.Contains(ctx.Config.Builds[0].Goarch, "amd64") assert.Contains(t, ctx.Config.Builds[0].Goarch, "amd64")
assert.Equal("tar.gz", ctx.Config.Archive.Format) assert.Equal(t, "tar.gz", ctx.Config.Archive.Format)
assert.Contains(ctx.Config.Brew.Install, "bin.install \"goreleaser\"") assert.Contains(t, ctx.Config.Brew.Install, "bin.install \"goreleaser\"")
assert.Contains(ctx.Config.Brew.CommitAuthor.Name, "goreleaserbot") assert.Empty(t, ctx.Config.Dockers)
assert.Contains(ctx.Config.Brew.CommitAuthor.Email, "goreleaser@carlosbecker.com") assert.Equal(t, ctx.Config.Brew.CommitAuthor.Name, "goreleaserbot")
assert.Empty(ctx.Config.Dockers) assert.Equal(t, ctx.Config.Brew.CommitAuthor.Email, "goreleaser@carlosbecker.com")
assert.NotEmpty( assert.NotEmpty(
t,
ctx.Config.Archive.NameTemplate, ctx.Config.Archive.NameTemplate,
ctx.Config.Builds[0].Ldflags, ctx.Config.Builds[0].Ldflags,
ctx.Config.Archive.Files, ctx.Config.Archive.Files,
@ -43,7 +43,6 @@ func TestFillBasicData(t *testing.T) {
} }
func TestFillPartial(t *testing.T) { func TestFillPartial(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
@ -73,18 +72,17 @@ func TestFillPartial(t *testing.T) {
}, },
}, },
} }
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
assert.Len(ctx.Config.Archive.Files, 1) assert.Len(t, ctx.Config.Archive.Files, 1)
assert.Equal(`bin.install "testreleaser"`, ctx.Config.Brew.Install) assert.Equal(t, `bin.install "testreleaser"`, ctx.Config.Brew.Install)
assert.NotEmpty(ctx.Config.Dockers[0].Binary) assert.NotEmpty(t, ctx.Config.Dockers[0].Binary)
assert.NotEmpty(ctx.Config.Dockers[0].Goos) assert.NotEmpty(t, ctx.Config.Dockers[0].Goos)
assert.NotEmpty(ctx.Config.Dockers[0].Goarch) assert.NotEmpty(t, ctx.Config.Dockers[0].Goarch)
assert.NotEmpty(ctx.Config.Dockers[0].Dockerfile) assert.NotEmpty(t, ctx.Config.Dockers[0].Dockerfile)
assert.Empty(ctx.Config.Dockers[0].Goarm) assert.Empty(t, ctx.Config.Dockers[0].Goarm)
} }
func TestFillSingleBuild(t *testing.T) { func TestFillSingleBuild(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
@ -93,23 +91,22 @@ func TestFillSingleBuild(t *testing.T) {
}, },
}, },
} }
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
assert.Len(ctx.Config.Builds, 1) assert.Len(t, ctx.Config.Builds, 1)
assert.Equal(ctx.Config.Builds[0].Binary, "goreleaser") assert.Equal(t, ctx.Config.Builds[0].Binary, "goreleaser")
} }
func TestNotAGitRepo(t *testing.T) { func TestNotAGitRepo(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.NoError(t, err)
previous, err := os.Getwd() previous, err := os.Getwd()
assert.NoError(err) assert.NoError(t, err)
assert.NoError(os.Chdir(folder)) assert.NoError(t, os.Chdir(folder))
defer func() { defer func() {
assert.NoError(os.Chdir(previous)) assert.NoError(t, os.Chdir(previous))
}() }()
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{}, Config: config.Project{},
} }
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
} }

View File

@ -7,20 +7,17 @@ import (
) )
func TestRepoName(t *testing.T) { func TestRepoName(t *testing.T) {
var assert = assert.New(t)
repo, err := remoteRepo() repo, err := remoteRepo()
assert.NoError(err) assert.NoError(t, err)
assert.Equal("goreleaser/goreleaser", repo.String()) assert.Equal(t, "goreleaser/goreleaser", repo.String())
} }
func TestExtractReporFromGitURL(t *testing.T) { func TestExtractReporFromGitURL(t *testing.T) {
var assert = assert.New(t)
repo := extractRepoFromURL("git@github.com:goreleaser/goreleaser.git") repo := extractRepoFromURL("git@github.com:goreleaser/goreleaser.git")
assert.Equal("goreleaser/goreleaser", repo.String()) assert.Equal(t, "goreleaser/goreleaser", repo.String())
} }
func TestExtractReporFromHttpsURL(t *testing.T) { func TestExtractReporFromHttpsURL(t *testing.T) {
var assert = assert.New(t)
repo := extractRepoFromURL("https://github.com/goreleaser/goreleaser.git") repo := extractRepoFromURL("https://github.com/goreleaser/goreleaser.git")
assert.Equal("goreleaser/goreleaser", repo.String()) assert.Equal(t, "goreleaser/goreleaser", repo.String())
} }

View File

@ -85,6 +85,10 @@ func process(ctx *context.Context, folder string, docker config.Docker, binary c
} }
} }
return publish(ctx, docker, image, latest)
}
func publish(ctx *context.Context, docker config.Docker, image, latest string) error {
// TODO: improve this so it can log it to stdout // TODO: improve this so it can log it to stdout
if !ctx.Publish { if !ctx.Publish {
return pipeline.Skip("--skip-publish is set") return pipeline.Skip("--skip-publish is set")

View File

@ -15,15 +15,14 @@ import (
) )
func TestRunPipe(t *testing.T) { func TestRunPipe(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "archivetest") folder, err := ioutil.TempDir("", "archivetest")
assert.NoError(err) assert.NoError(t, err)
var dist = filepath.Join(folder, "dist") var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755)) assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755)) assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var binPath = filepath.Join(dist, "mybin", "mybin") var binPath = filepath.Join(dist, "mybin", "mybin")
_, err = os.Create(binPath) _, err = os.Create(binPath)
assert.NoError(err) assert.NoError(t, err)
var images = []string{ var images = []string{
"goreleaser/test_run_pipe:1.0.0", "goreleaser/test_run_pipe:1.0.0",
"goreleaser/test_run_pipe:latest", "goreleaser/test_run_pipe:latest",
@ -60,34 +59,31 @@ func TestRunPipe(t *testing.T) {
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} { for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} {
ctx.AddBinary(plat, "mybin", "mybin", binPath) ctx.AddBinary(plat, "mybin", "mybin", binPath)
} }
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
// this might should not fail as the image should have been created when // this might should not fail as the image should have been created when
// the step ran // the step ran
for _, img := range images { for _, img := range images {
assert.NoError(exec.Command("docker", "rmi", img).Run()) assert.NoError(t, exec.Command("docker", "rmi", img).Run())
} }
// the test_run_pipe_nope image should not have been created, so deleting // the test_run_pipe_nope image should not have been created, so deleting
// it should fail // it should fail
assert.Error( assert.Error(t,
exec.Command("docker", "rmi", "goreleaser/test_run_pipe_nope:1.0.0").Run(), exec.Command("docker", "rmi", "goreleaser/test_run_pipe_nope:1.0.0").Run(),
) )
} }
func TestDescription(t *testing.T) { func TestDescription(t *testing.T) {
var assert = assert.New(t) assert.NotEmpty(t, Pipe{}.Description())
assert.NotEmpty(Pipe{}.Description())
} }
func TestNoDockers(t *testing.T) { func TestNoDockers(t *testing.T) {
var assert = assert.New(t) assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{}))))
assert.True(pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{}))))
} }
func TestNoDockerWithoutImageName(t *testing.T) { func TestNoDockerWithoutImageName(t *testing.T) {
var assert = assert.New(t) assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{
assert.True(pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{
Dockers: []config.Docker{ Dockers: []config.Docker{
{ {
Goos: "linux", Goos: "linux",
@ -97,12 +93,11 @@ func TestNoDockerWithoutImageName(t *testing.T) {
} }
func TestDockerNotInPath(t *testing.T) { func TestDockerNotInPath(t *testing.T) {
var assert = assert.New(t)
var path = os.Getenv("PATH") var path = os.Getenv("PATH")
defer func() { defer func() {
assert.NoError(os.Setenv("PATH", path)) assert.NoError(t, os.Setenv("PATH", path))
}() }()
assert.NoError(os.Setenv("PATH", "")) assert.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{
@ -113,5 +108,5 @@ func TestDockerNotInPath(t *testing.T) {
}, },
}, },
} }
assert.EqualError(Pipe{}.Run(ctx), ErrNoDocker.Error()) assert.EqualError(t, Pipe{}.Run(ctx), ErrNoDocker.Error())
} }

View File

@ -16,25 +16,23 @@ func TestDescription(t *testing.T) {
} }
func TestValidEnv(t *testing.T) { func TestValidEnv(t *testing.T) {
assert := assert.New(t) assert.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf"))
assert.NoError(os.Setenv("GITHUB_TOKEN", "asdf"))
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{}, Config: config.Project{},
Validate: true, Validate: true,
Publish: true, Publish: true,
} }
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
} }
func TestInvalidEnv(t *testing.T) { func TestInvalidEnv(t *testing.T) {
assert := assert.New(t) assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
assert.NoError(os.Unsetenv("GITHUB_TOKEN"))
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{}, Config: config.Project{},
Validate: true, Validate: true,
Publish: true, Publish: true,
} }
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
} }
type flags struct { type flags struct {
@ -54,8 +52,7 @@ func TestInvalidEnvChecksSkipped(t *testing.T) {
}, },
} { } {
t.Run(fmt.Sprintf("%v", flag), func(t *testing.T) { t.Run(fmt.Sprintf("%v", flag), func(t *testing.T) {
var assert = assert.New(t) assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
assert.NoError(os.Unsetenv("GITHUB_TOKEN"))
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{}, Config: config.Project{},
Validate: flag.Validate, Validate: flag.Validate,

View File

@ -25,15 +25,14 @@ func TestRunPipeNoFormats(t *testing.T) {
} }
func TestRunPipe(t *testing.T) { func TestRunPipe(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "archivetest") folder, err := ioutil.TempDir("", "archivetest")
assert.NoError(err) assert.NoError(t, err)
var dist = filepath.Join(folder, "dist") var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755)) assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755)) assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var binPath = filepath.Join(dist, "mybin", "mybin") var binPath = filepath.Join(dist, "mybin", "mybin")
_, err = os.Create(binPath) _, err = os.Create(binPath)
assert.NoError(err) assert.NoError(t, err)
var ctx = &context.Context{ var ctx = &context.Context{
Version: "1.0.0", Version: "1.0.0",
Config: config.Project{ Config: config.Project{
@ -54,16 +53,15 @@ func TestRunPipe(t *testing.T) {
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} { for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} {
ctx.AddBinary(plat, "mybin", "mybin", binPath) ctx.AddBinary(plat, "mybin", "mybin", binPath)
} }
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
} }
func TestNoFPMInPath(t *testing.T) { func TestNoFPMInPath(t *testing.T) {
var assert = assert.New(t)
var path = os.Getenv("PATH") var path = os.Getenv("PATH")
defer func() { defer func() {
assert.NoError(os.Setenv("PATH", path)) assert.NoError(t, os.Setenv("PATH", path))
}() }()
assert.NoError(os.Setenv("PATH", "")) assert.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{
@ -72,16 +70,15 @@ func TestNoFPMInPath(t *testing.T) {
}, },
}, },
} }
assert.EqualError(Pipe{}.Run(ctx), ErrNoFPM.Error()) assert.EqualError(t, Pipe{}.Run(ctx), ErrNoFPM.Error())
} }
func TestCreateFileDoesntExist(t *testing.T) { func TestCreateFileDoesntExist(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "archivetest") folder, err := ioutil.TempDir("", "archivetest")
assert.NoError(err) assert.NoError(t, err)
var dist = filepath.Join(folder, "dist") var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755)) assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755)) assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var ctx = &context.Context{ var ctx = &context.Context{
Version: "1.0.0", Version: "1.0.0",
Config: config.Project{ Config: config.Project{
@ -95,11 +92,10 @@ func TestCreateFileDoesntExist(t *testing.T) {
}, },
} }
ctx.AddBinary("linuxamd64", "mybin", "mybin", filepath.Join(dist, "mybin", "mybin")) ctx.AddBinary("linuxamd64", "mybin", "mybin", filepath.Join(dist, "mybin", "mybin"))
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
} }
func TestRunPipeWithExtraFiles(t *testing.T) { func TestRunPipeWithExtraFiles(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Version: "1.0.0", Version: "1.0.0",
Config: config.Project{ Config: config.Project{
@ -108,5 +104,5 @@ func TestRunPipeWithExtraFiles(t *testing.T) {
}, },
}, },
} }
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
} }

View File

@ -18,17 +18,15 @@ func TestDescription(t *testing.T) {
} }
func TestNotAGitFolder(t *testing.T) { func TestNotAGitFolder(t *testing.T) {
var assert = assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{}, Config: config.Project{},
} }
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
} }
func TestSingleCommit(t *testing.T) { func TestSingleCommit(t *testing.T) {
var assert = assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
@ -38,22 +36,20 @@ func TestSingleCommit(t *testing.T) {
Config: config.Project{}, Config: config.Project{},
} }
testlib.AssertSkipped(t, Pipe{}.Run(ctx)) testlib.AssertSkipped(t, Pipe{}.Run(ctx))
assert.Equal("v0.0.1", ctx.Git.CurrentTag) assert.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
} }
func TestNewRepository(t *testing.T) { func TestNewRepository(t *testing.T) {
var assert = assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{}, Config: config.Project{},
} }
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
} }
func TestNoTagsSnapshot(t *testing.T) { func TestNoTagsSnapshot(t *testing.T) {
assert := assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
@ -68,11 +64,10 @@ func TestNoTagsSnapshot(t *testing.T) {
Publish: false, Publish: false,
} }
testlib.AssertSkipped(t, Pipe{}.Run(ctx)) testlib.AssertSkipped(t, Pipe{}.Run(ctx))
assert.Contains(ctx.Version, "SNAPSHOT-") assert.Contains(t, ctx.Version, "SNAPSHOT-")
} }
func TestNoTagsSnapshotInvalidTemplate(t *testing.T) { func TestNoTagsSnapshotInvalidTemplate(t *testing.T) {
assert := assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
@ -86,14 +81,13 @@ func TestNoTagsSnapshotInvalidTemplate(t *testing.T) {
Snapshot: true, Snapshot: true,
Publish: false, Publish: false,
} }
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
} }
// TestNoTagsNoSnapshot covers the situation where a repository // TestNoTagsNoSnapshot covers the situation where a repository
// only contains simple commits and no tags. In this case you have // only contains simple commits and no tags. In this case you have
// to set the --snapshot flag otherwise an error is returned. // to set the --snapshot flag otherwise an error is returned.
func TestNoTagsNoSnapshot(t *testing.T) { func TestNoTagsNoSnapshot(t *testing.T) {
assert := assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
@ -107,11 +101,10 @@ func TestNoTagsNoSnapshot(t *testing.T) {
Snapshot: false, Snapshot: false,
Publish: false, Publish: false,
} }
assert.Error(Pipe{}.Run(ctx)) assert.Error(t, Pipe{}.Run(ctx))
} }
func TestInvalidTagFormat(t *testing.T) { func TestInvalidTagFormat(t *testing.T) {
var assert = assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
@ -121,32 +114,30 @@ func TestInvalidTagFormat(t *testing.T) {
Config: config.Project{}, Config: config.Project{},
Validate: true, Validate: true,
} }
assert.EqualError(Pipe{}.Run(ctx), "sadasd is not in a valid version format") assert.EqualError(t, Pipe{}.Run(ctx), "sadasd is not in a valid version format")
assert.Equal("sadasd", ctx.Git.CurrentTag) assert.Equal(t, "sadasd", ctx.Git.CurrentTag)
} }
func TestDirty(t *testing.T) { func TestDirty(t *testing.T) {
var assert = assert.New(t)
folder, back := testlib.Mktmp(t) folder, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
dummy, err := os.Create(filepath.Join(folder, "dummy")) dummy, err := os.Create(filepath.Join(folder, "dummy"))
assert.NoError(err) assert.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(ioutil.WriteFile(dummy.Name(), []byte("lorem ipsum"), 0644)) assert.NoError(t, ioutil.WriteFile(dummy.Name(), []byte("lorem ipsum"), 0644))
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{}, Config: config.Project{},
Validate: true, Validate: true,
} }
err = Pipe{}.Run(ctx) err = Pipe{}.Run(ctx)
assert.Error(err) assert.Error(t, err)
assert.Contains(err.Error(), "git is currently in a dirty state:") assert.Contains(t, err.Error(), "git is currently in a dirty state:")
} }
func TestTagIsNotLastCommit(t *testing.T) { func TestTagIsNotLastCommit(t *testing.T) {
var assert = assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
@ -158,12 +149,11 @@ func TestTagIsNotLastCommit(t *testing.T) {
Validate: true, Validate: true,
} }
err := Pipe{}.Run(ctx) err := Pipe{}.Run(ctx)
assert.Error(err) assert.Error(t, err)
assert.Contains(err.Error(), "git tag v0.0.1 was not made against commit") assert.Contains(t, err.Error(), "git tag v0.0.1 was not made against commit")
} }
func TestValidState(t *testing.T) { func TestValidState(t *testing.T) {
var assert = assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
@ -175,10 +165,10 @@ func TestValidState(t *testing.T) {
Config: config.Project{}, Config: config.Project{},
Validate: true, Validate: true,
} }
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
assert.Equal("v0.0.2", ctx.Git.CurrentTag) assert.Equal(t, "v0.0.2", ctx.Git.CurrentTag)
assert.NotContains("commit4", ctx.ReleaseNotes) assert.NotContains(t, "commit4", ctx.ReleaseNotes)
assert.NotContains("commit3", ctx.ReleaseNotes) assert.NotContains(t, "commit3", ctx.ReleaseNotes)
} }
func TestNoValidate(t *testing.T) { func TestNoValidate(t *testing.T) {
@ -197,7 +187,6 @@ func TestNoValidate(t *testing.T) {
} }
func TestChangelog(t *testing.T) { func TestChangelog(t *testing.T) {
var assert = assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
@ -210,15 +199,14 @@ func TestChangelog(t *testing.T) {
Config: config.Project{}, Config: config.Project{},
} }
testlib.AssertSkipped(t, Pipe{}.Run(ctx)) testlib.AssertSkipped(t, Pipe{}.Run(ctx))
assert.Equal("v0.0.2", ctx.Git.CurrentTag) assert.Equal(t, "v0.0.2", ctx.Git.CurrentTag)
assert.Contains(ctx.ReleaseNotes, "## Changelog") assert.Contains(t, ctx.ReleaseNotes, "## Changelog")
assert.NotContains(ctx.ReleaseNotes, "first") assert.NotContains(t, ctx.ReleaseNotes, "first")
assert.Contains(ctx.ReleaseNotes, "added feature 1") assert.Contains(t, ctx.ReleaseNotes, "added feature 1")
assert.Contains(ctx.ReleaseNotes, "fixed bug 2") assert.Contains(t, ctx.ReleaseNotes, "fixed bug 2")
} }
func TestChangelogOfFirstRelease(t *testing.T) { func TestChangelogOfFirstRelease(t *testing.T) {
var assert = assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
@ -236,15 +224,14 @@ func TestChangelogOfFirstRelease(t *testing.T) {
Config: config.Project{}, Config: config.Project{},
} }
testlib.AssertSkipped(t, Pipe{}.Run(ctx)) testlib.AssertSkipped(t, Pipe{}.Run(ctx))
assert.Equal("v0.0.1", ctx.Git.CurrentTag) assert.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
assert.Contains(ctx.ReleaseNotes, "## Changelog") assert.Contains(t, ctx.ReleaseNotes, "## Changelog")
for _, msg := range msgs { for _, msg := range msgs {
assert.Contains(ctx.ReleaseNotes, msg) assert.Contains(t, ctx.ReleaseNotes, msg)
} }
} }
func TestCustomReleaseNotes(t *testing.T) { func TestCustomReleaseNotes(t *testing.T) {
var assert = assert.New(t)
_, back := testlib.Mktmp(t) _, back := testlib.Mktmp(t)
defer back() defer back()
testlib.GitInit(t) testlib.GitInit(t)
@ -255,6 +242,6 @@ func TestCustomReleaseNotes(t *testing.T) {
ReleaseNotes: "custom", ReleaseNotes: "custom",
} }
testlib.AssertSkipped(t, Pipe{}.Run(ctx)) testlib.AssertSkipped(t, Pipe{}.Run(ctx))
assert.Equal("v0.0.1", ctx.Git.CurrentTag) assert.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
assert.Equal(ctx.ReleaseNotes, "custom") assert.Equal(t, ctx.ReleaseNotes, "custom")
} }

View File

@ -8,15 +8,13 @@ import (
) )
func TestSkipPipe(t *testing.T) { func TestSkipPipe(t *testing.T) {
var assert = assert.New(t)
var reason = "this is a test" var reason = "this is a test"
var err = Skip(reason) var err = Skip(reason)
assert.Error(err) assert.Error(t, err)
assert.Equal(reason, err.Error()) assert.Equal(t, reason, err.Error())
} }
func TestIsSkip(t *testing.T) { func TestIsSkip(t *testing.T) {
var assert = assert.New(t) assert.True(t, IsSkip(Skip("whatever")))
assert.True(IsSkip(Skip("whatever"))) assert.False(t, IsSkip(errors.New("nope")))
assert.False(IsSkip(errors.New("nope")))
} }

View File

@ -10,7 +10,6 @@ import (
) )
func TestDescribeBody(t *testing.T) { func TestDescribeBody(t *testing.T) {
var assert = assert.New(t)
var changelog = "\nfeature1: description\nfeature2: other description" var changelog = "\nfeature1: description\nfeature2: other description"
var ctx = &context.Context{ var ctx = &context.Context{
ReleaseNotes: changelog, ReleaseNotes: changelog,
@ -20,52 +19,49 @@ func TestDescribeBody(t *testing.T) {
}, },
} }
out, err := describeBodyVersion(ctx, "go version go1.9 darwin/amd64") out, err := describeBodyVersion(ctx, "go version go1.9 darwin/amd64")
assert.NoError(err) assert.NoError(t, err)
bts, err := ioutil.ReadFile("testdata/release1.txt") bts, err := ioutil.ReadFile("testdata/release1.txt")
assert.NoError(err) assert.NoError(t, err)
ioutil.WriteFile("testdata/release1.txt", out.Bytes(), 0755) // ioutil.WriteFile("testdata/release1.txt", out.Bytes(), 0755)
assert.Equal(string(bts), out.String()) assert.Equal(t, string(bts), out.String())
} }
func TestDescribeBodyNoDockerImages(t *testing.T) { func TestDescribeBodyNoDockerImages(t *testing.T) {
var assert = assert.New(t)
var changelog = "\nfeature1: description\nfeature2: other description" var changelog = "\nfeature1: description\nfeature2: other description"
var ctx = &context.Context{ var ctx = &context.Context{
ReleaseNotes: changelog, ReleaseNotes: changelog,
} }
out, err := describeBodyVersion(ctx, "go version go1.9 darwin/amd64") out, err := describeBodyVersion(ctx, "go version go1.9 darwin/amd64")
assert.NoError(err) assert.NoError(t, err)
bts, err := ioutil.ReadFile("testdata/release2.txt") bts, err := ioutil.ReadFile("testdata/release2.txt")
assert.NoError(err) assert.NoError(t, err)
ioutil.WriteFile("testdata/release2.txt", out.Bytes(), 0755) // ioutil.WriteFile("testdata/release2.txt", out.Bytes(), 0755)
assert.Equal(string(bts), out.String()) assert.Equal(t, string(bts), out.String())
} }
func TestDontEscapeHTML(t *testing.T) { func TestDontEscapeHTML(t *testing.T) {
var assert = assert.New(t)
var changelog = "<h1>test</h1>" var changelog = "<h1>test</h1>"
var ctx = &context.Context{ var ctx = &context.Context{
ReleaseNotes: changelog, ReleaseNotes: changelog,
} }
out, err := describeBody(ctx) out, err := describeBody(ctx)
assert.NoError(err) assert.NoError(t, err)
assert.Contains(out.String(), changelog) assert.Contains(t, out.String(), changelog)
} }
func TestGoVersionFails(t *testing.T) { func TestGoVersionFails(t *testing.T) {
var assert = assert.New(t)
var path = os.Getenv("PATH") var path = os.Getenv("PATH")
defer func() { defer func() {
assert.NoError(os.Setenv("PATH", path)) assert.NoError(t, os.Setenv("PATH", path))
}() }()
assert.NoError(os.Setenv("PATH", "")) assert.NoError(t, os.Setenv("PATH", ""))
var ctx = &context.Context{ var ctx = &context.Context{
ReleaseNotes: "changelog", ReleaseNotes: "changelog",
} }
_, err := describeBody(ctx) _, err := describeBody(ctx)
assert.Error(err) assert.Error(t, err)
} }

View File

@ -19,13 +19,12 @@ func TestPipeDescription(t *testing.T) {
} }
func TestRunPipe(t *testing.T) { func TestRunPipe(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.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(err) assert.NoError(t, err)
debfile, err := os.Create(filepath.Join(folder, "bin.deb")) debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
assert.NoError(err) assert.NoError(t, err)
var config = config.Project{ var config = config.Project{
Dist: folder, Dist: folder,
Release: config.Release{ Release: config.Release{
@ -41,15 +40,14 @@ func TestRunPipe(t *testing.T) {
ctx.AddArtifact(tarfile.Name()) ctx.AddArtifact(tarfile.Name())
ctx.AddArtifact(debfile.Name()) ctx.AddArtifact(debfile.Name())
client := &DummyClient{} client := &DummyClient{}
assert.NoError(doRun(ctx, client)) assert.NoError(t, doRun(ctx, client))
assert.True(client.CreatedRelease) assert.True(t, client.CreatedRelease)
assert.True(client.UploadedFile) assert.True(t, client.UploadedFile)
assert.Contains(client.UploadedFileNames, "bin.deb") assert.Contains(t, client.UploadedFileNames, "bin.deb")
assert.Contains(client.UploadedFileNames, "bin.tar.gz") assert.Contains(t, client.UploadedFileNames, "bin.tar.gz")
} }
func TestRunPipeReleaseCreationFailed(t *testing.T) { func TestRunPipeReleaseCreationFailed(t *testing.T) {
var assert = assert.New(t)
var config = config.Project{ var config = config.Project{
Release: config.Release{ Release: config.Release{
GitHub: config.Repo{ GitHub: config.Repo{
@ -64,13 +62,12 @@ func TestRunPipeReleaseCreationFailed(t *testing.T) {
client := &DummyClient{ client := &DummyClient{
FailToCreateRelease: true, FailToCreateRelease: true,
} }
assert.Error(doRun(ctx, client)) assert.Error(t, doRun(ctx, client))
assert.False(client.CreatedRelease) assert.False(t, client.CreatedRelease)
assert.False(client.UploadedFile) assert.False(t, client.UploadedFile)
} }
func TestRunPipeWithFileThatDontExist(t *testing.T) { func TestRunPipeWithFileThatDontExist(t *testing.T) {
var assert = assert.New(t)
var config = config.Project{ var config = config.Project{
Release: config.Release{ Release: config.Release{
GitHub: config.Repo{ GitHub: config.Repo{
@ -84,17 +81,16 @@ func TestRunPipeWithFileThatDontExist(t *testing.T) {
ctx.Publish = true ctx.Publish = true
ctx.AddArtifact("this-file-wont-exist-hopefully") ctx.AddArtifact("this-file-wont-exist-hopefully")
client := &DummyClient{} client := &DummyClient{}
assert.Error(doRun(ctx, client)) assert.Error(t, doRun(ctx, client))
assert.True(client.CreatedRelease) assert.True(t, client.CreatedRelease)
assert.False(client.UploadedFile) assert.False(t, client.UploadedFile)
} }
func TestRunPipeUploadFailure(t *testing.T) { func TestRunPipeUploadFailure(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest") folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err) assert.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(err) assert.NoError(t, err)
var config = config.Project{ var config = config.Project{
Release: config.Release{ Release: config.Release{
GitHub: config.Repo{ GitHub: config.Repo{
@ -110,21 +106,20 @@ func TestRunPipeUploadFailure(t *testing.T) {
client := &DummyClient{ client := &DummyClient{
FailToUpload: true, FailToUpload: true,
} }
assert.Error(doRun(ctx, client)) assert.Error(t, doRun(ctx, client))
assert.True(client.CreatedRelease) assert.True(t, client.CreatedRelease)
assert.False(client.UploadedFile) assert.False(t, client.UploadedFile)
} }
func TestSkipPublish(t *testing.T) { func TestSkipPublish(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Publish: false, Publish: false,
Parallelism: 1, Parallelism: 1,
} }
client := &DummyClient{} client := &DummyClient{}
testlib.AssertSkipped(t, doRun(ctx, client)) testlib.AssertSkipped(t, doRun(ctx, client))
assert.False(client.CreatedRelease) assert.False(t, client.CreatedRelease)
assert.False(client.UploadedFile) assert.False(t, client.UploadedFile)
} }
type DummyClient struct { type DummyClient struct {

View File

@ -29,24 +29,22 @@ func TestRunPipeMissingInfo(t *testing.T) {
pipeline.Skip("no summary nor description were provided"): {}, pipeline.Skip("no summary nor description were provided"): {},
} { } {
t.Run(fmt.Sprintf("testing if %v happens", eerr), func(t *testing.T) { t.Run(fmt.Sprintf("testing if %v happens", eerr), func(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Snapcraft: snap, Snapcraft: snap,
}, },
} }
assert.Equal(eerr, Pipe{}.Run(ctx)) assert.Equal(t, eerr, Pipe{}.Run(ctx))
}) })
} }
} }
func TestRunPipe(t *testing.T) { func TestRunPipe(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "archivetest") folder, err := ioutil.TempDir("", "archivetest")
assert.NoError(err) assert.NoError(t, err)
var dist = filepath.Join(folder, "dist") var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755)) assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(err) assert.NoError(t, err)
var ctx = &context.Context{ var ctx = &context.Context{
Version: "testversion", Version: "testversion",
Config: config.Project{ Config: config.Project{
@ -59,16 +57,15 @@ func TestRunPipe(t *testing.T) {
}, },
} }
addBinaries(t, ctx, "mybin", dist) addBinaries(t, ctx, "mybin", dist)
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
} }
func TestRunPipeWithName(t *testing.T) { func TestRunPipeWithName(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "archivetest") folder, err := ioutil.TempDir("", "archivetest")
assert.NoError(err) assert.NoError(t, err)
var dist = filepath.Join(folder, "dist") var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755)) assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(err) assert.NoError(t, err)
var ctx = &context.Context{ var ctx = &context.Context{
Version: "testversion", Version: "testversion",
Config: config.Project{ Config: config.Project{
@ -82,22 +79,21 @@ func TestRunPipeWithName(t *testing.T) {
}, },
} }
addBinaries(t, ctx, "testprojectname", dist) addBinaries(t, ctx, "testprojectname", dist)
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "testprojectname_linuxamd64", "prime", "meta", "snap.yaml")) yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "testprojectname_linuxamd64", "prime", "meta", "snap.yaml"))
assert.NoError(err) assert.NoError(t, err)
var metadata Metadata var metadata Metadata
err = yaml.Unmarshal(yamlFile, &metadata) err = yaml.Unmarshal(yamlFile, &metadata)
assert.NoError(err) assert.NoError(t, err)
assert.Equal(metadata.Name, "testsnapname") assert.Equal(t, metadata.Name, "testsnapname")
} }
func TestRunPipeWithPlugsAndDaemon(t *testing.T) { func TestRunPipeWithPlugsAndDaemon(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "archivetest") folder, err := ioutil.TempDir("", "archivetest")
assert.NoError(err) assert.NoError(t, err)
var dist = filepath.Join(folder, "dist") var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755)) assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(err) assert.NoError(t, err)
var ctx = &context.Context{ var ctx = &context.Context{
Version: "testversion", Version: "testversion",
Config: config.Project{ Config: config.Project{
@ -116,23 +112,22 @@ func TestRunPipeWithPlugsAndDaemon(t *testing.T) {
}, },
} }
addBinaries(t, ctx, "mybin", dist) addBinaries(t, ctx, "mybin", dist)
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(t, Pipe{}.Run(ctx))
yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "mybin_linuxamd64", "prime", "meta", "snap.yaml")) yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "mybin_linuxamd64", "prime", "meta", "snap.yaml"))
assert.NoError(err) assert.NoError(t, err)
var metadata Metadata var metadata Metadata
err = yaml.Unmarshal(yamlFile, &metadata) err = yaml.Unmarshal(yamlFile, &metadata)
assert.NoError(err) assert.NoError(t, err)
assert.Equal(metadata.Apps["mybin"].Plugs, []string{"home", "network"}) assert.Equal(t, metadata.Apps["mybin"].Plugs, []string{"home", "network"})
assert.Equal(metadata.Apps["mybin"].Daemon, "simple") assert.Equal(t, metadata.Apps["mybin"].Daemon, "simple")
} }
func TestNoSnapcraftInPath(t *testing.T) { func TestNoSnapcraftInPath(t *testing.T) {
var assert = assert.New(t)
var path = os.Getenv("PATH") var path = os.Getenv("PATH")
defer func() { defer func() {
assert.NoError(os.Setenv("PATH", path)) assert.NoError(t, os.Setenv("PATH", path))
}() }()
assert.NoError(os.Setenv("PATH", "")) assert.NoError(t, os.Setenv("PATH", ""))
var ctx = &context.Context{ var ctx = &context.Context{
Config: config.Project{ Config: config.Project{
Snapcraft: config.Snapcraft{ Snapcraft: config.Snapcraft{
@ -141,11 +136,10 @@ func TestNoSnapcraftInPath(t *testing.T) {
}, },
}, },
} }
assert.EqualError(Pipe{}.Run(ctx), ErrNoSnapcraft.Error()) assert.EqualError(t, Pipe{}.Run(ctx), ErrNoSnapcraft.Error())
} }
func addBinaries(t *testing.T, ctx *context.Context, name, dist string) { func addBinaries(t *testing.T, ctx *context.Context, name, dist string) {
var assert = assert.New(t)
for _, plat := range []string{ for _, plat := range []string{
"linuxamd64", "linuxamd64",
"linux386", "linux386",
@ -155,10 +149,10 @@ func addBinaries(t *testing.T, ctx *context.Context, name, dist string) {
"linuxwtf", "linuxwtf",
} { } {
var folder = name + "_" + plat var folder = name + "_" + plat
assert.NoError(os.Mkdir(filepath.Join(dist, folder), 0755)) assert.NoError(t, os.Mkdir(filepath.Join(dist, folder), 0755))
var binPath = filepath.Join(dist, folder, name) var binPath = filepath.Join(dist, folder, name)
_, err := os.Create(binPath) _, err := os.Create(binPath)
assert.NoError(err) assert.NoError(t, err)
ctx.AddBinary(plat, folder, name, binPath) ctx.AddBinary(plat, folder, name, binPath)
} }
} }