mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
commit
ef68fce2a8
@ -13,7 +13,7 @@ install:
|
||||
- export PATH=/snap/bin:$PATH
|
||||
- sudo snap install snapcraft --candidate --classic
|
||||
script:
|
||||
- make test
|
||||
- make ci
|
||||
- test -n "$TRAVIS_TAG" || go run main.go --skip-validate --skip-publish
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
@ -11,31 +11,28 @@ import (
|
||||
)
|
||||
|
||||
func TestChecksums(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
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)
|
||||
assert.NoError(err)
|
||||
assert.Equal("5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269", sum)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269", sum)
|
||||
}
|
||||
|
||||
func TestOpenFailure(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
sum, err := SHA256("/tmp/this-file-wont-exist-I-hope")
|
||||
assert.Empty(sum)
|
||||
assert.Error(err)
|
||||
assert.Empty(t, sum)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestFileDoesntExist(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var path = filepath.Join(folder, "subject")
|
||||
file, err := os.Create(path)
|
||||
assert.NoError(err)
|
||||
assert.NoError(file.Close())
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, file.Close())
|
||||
_, err = doCalculate(sha256.New(), file)
|
||||
assert.Error(err)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
@ -12,9 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func TestRepo(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
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) {
|
||||
@ -22,12 +21,11 @@ func TestLoadReader(t *testing.T) {
|
||||
fpm:
|
||||
homepage: http://goreleaser.github.io
|
||||
`
|
||||
var assert = assert.New(t)
|
||||
buf := strings.NewReader(conf)
|
||||
prop, err := LoadReader(buf)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal("http://goreleaser.github.io", prop.FPM.Homepage, "yaml did not load correctly")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "http://goreleaser.github.io", prop.FPM.Homepage, "yaml did not load correctly")
|
||||
}
|
||||
|
||||
type errorReader struct{}
|
||||
@ -36,33 +34,28 @@ func (errorReader) Read(p []byte) (n int, err error) {
|
||||
return 1, fmt.Errorf("error")
|
||||
}
|
||||
func TestLoadBadReader(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, err := LoadReader(errorReader{})
|
||||
assert.Error(err)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestFile(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
f, err := ioutil.TempFile(os.TempDir(), "config")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
_, err = Load(filepath.Join(f.Name()))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestFileNotFound(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, err := Load("/nope/no-way.yml")
|
||||
assert.Error(err)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestInvalidFields(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, 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) {
|
||||
var assert = assert.New(t)
|
||||
_, 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")
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestMultipleAdds(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var artifacts = []string{
|
||||
"dist/a",
|
||||
"dist/b",
|
||||
@ -32,7 +31,7 @@ func TestMultipleAdds(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
assert.NoError(g.Wait())
|
||||
assert.NoError(t, g.Wait())
|
||||
for _, d := range dockerfiles {
|
||||
d := d
|
||||
g.Go(func() error {
|
||||
@ -40,15 +39,14 @@ func TestMultipleAdds(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
assert.NoError(g.Wait())
|
||||
assert.Len(ctx.Artifacts, len(artifacts))
|
||||
assert.Contains(ctx.Artifacts, "a", "b", "c", "d")
|
||||
assert.Len(ctx.Dockers, len(dockerfiles))
|
||||
assert.Contains(ctx.Dockers, "a/b:1.0.0", "c/d:2.0.0", "e/f:3.0.0")
|
||||
assert.NoError(t, g.Wait())
|
||||
assert.Len(t, ctx.Artifacts, len(artifacts))
|
||||
assert.Contains(t, ctx.Artifacts, "a", "b", "c", "d")
|
||||
assert.Len(t, ctx.Dockers, len(dockerfiles))
|
||||
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) {
|
||||
var assert = assert.New(t)
|
||||
var list = map[string]string{
|
||||
"a": "folder/a",
|
||||
"b": "folder/b",
|
||||
@ -67,7 +65,7 @@ func TestMultipleBinaryAdds(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
assert.NoError(g.Wait())
|
||||
assert.Len(ctx.Binaries["linuxamd64"], len(list))
|
||||
assert.Len(ctx.Binaries, 1)
|
||||
assert.NoError(t, g.Wait())
|
||||
assert.Len(t, ctx.Binaries["linuxamd64"], len(list))
|
||||
assert.Len(t, ctx.Binaries, 1)
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ func init() {
|
||||
}
|
||||
|
||||
func TestRelease(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := setup(t)
|
||||
defer back()
|
||||
var flags = fakeFlags{
|
||||
@ -29,11 +28,10 @@ func TestRelease(t *testing.T) {
|
||||
"parallelism": "4",
|
||||
},
|
||||
}
|
||||
assert.NoError(Release(flags))
|
||||
assert.NoError(t, Release(flags))
|
||||
}
|
||||
|
||||
func TestSnapshotRelease(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := setup(t)
|
||||
defer back()
|
||||
var flags = fakeFlags{
|
||||
@ -42,17 +40,16 @@ func TestSnapshotRelease(t *testing.T) {
|
||||
"parallelism": "4",
|
||||
},
|
||||
}
|
||||
assert.NoError(Release(flags))
|
||||
assert.NoError(t, Release(flags))
|
||||
}
|
||||
|
||||
func TestConfigFileIsSetAndDontExist(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var flags = fakeFlags{
|
||||
flags: map[string]string{
|
||||
"config": "/this/wont/exist",
|
||||
},
|
||||
}
|
||||
assert.Error(Release(flags))
|
||||
assert.Error(t, Release(flags))
|
||||
}
|
||||
|
||||
func TestConfigFlagNotSetButExists(t *testing.T) {
|
||||
@ -81,17 +78,15 @@ func TestConfigFlagNotSetButExists(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReleaseNotesFileDontExist(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var flags = fakeFlags{
|
||||
flags: map[string]string{
|
||||
"release-notes": "/this/also/wont/exist",
|
||||
},
|
||||
}
|
||||
assert.Error(Release(flags))
|
||||
assert.Error(t, Release(flags))
|
||||
}
|
||||
|
||||
func TestCustomReleaseNotesFile(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, back := setup(t)
|
||||
defer back()
|
||||
var releaseNotes = filepath.Join(folder, "notes.md")
|
||||
@ -104,11 +99,10 @@ func TestCustomReleaseNotesFile(t *testing.T) {
|
||||
"parallelism": "4",
|
||||
},
|
||||
}
|
||||
assert.NoError(Release(flags))
|
||||
assert.NoError(t, Release(flags))
|
||||
}
|
||||
|
||||
func TestBrokenPipe(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := setup(t)
|
||||
defer back()
|
||||
createFile(t, "main.go", "not a valid go file")
|
||||
@ -119,41 +113,38 @@ func TestBrokenPipe(t *testing.T) {
|
||||
"parallelism": "4",
|
||||
},
|
||||
}
|
||||
assert.Error(Release(flags))
|
||||
assert.Error(t, Release(flags))
|
||||
}
|
||||
|
||||
func TestInitProject(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := setup(t)
|
||||
defer back()
|
||||
var filename = "test_goreleaser.yml"
|
||||
assert.NoError(InitProject(filename))
|
||||
assert.NoError(t, InitProject(filename))
|
||||
|
||||
file, err := os.Open(filename)
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
out, err := ioutil.ReadAll(file)
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
|
||||
var config = config.Project{}
|
||||
assert.NoError(yaml.Unmarshal(out, &config))
|
||||
assert.NoError(t, yaml.Unmarshal(out, &config))
|
||||
}
|
||||
|
||||
func TestInitProjectFileExist(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := setup(t)
|
||||
defer back()
|
||||
var filename = "test_goreleaser.yml"
|
||||
createFile(t, filename, "")
|
||||
assert.Error(InitProject(filename))
|
||||
assert.Error(t, InitProject(filename))
|
||||
}
|
||||
|
||||
func TestInitProjectDefaultPipeFails(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := setup(t)
|
||||
defer back()
|
||||
var filename = "test_goreleaser.yml"
|
||||
assert.NoError(os.RemoveAll(".git"))
|
||||
assert.Error(InitProject(filename))
|
||||
assert.NoError(t, os.RemoveAll(".git"))
|
||||
assert.Error(t, InitProject(filename))
|
||||
}
|
||||
|
||||
// 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()) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleaser")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
previous, err := os.Getwd()
|
||||
assert.NoError(err)
|
||||
assert.NoError(os.Chdir(folder))
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, os.Chdir(folder))
|
||||
createGoreleaserYaml(t)
|
||||
createMainGo(t)
|
||||
testlib.GitInit(t)
|
||||
@ -197,13 +187,12 @@ func setup(t *testing.T) (current string, back func()) {
|
||||
testlib.GitTag(t, "v0.0.2")
|
||||
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/fake.git")
|
||||
return folder, func() {
|
||||
assert.NoError(os.Chdir(previous))
|
||||
assert.NoError(t, os.Chdir(previous))
|
||||
}
|
||||
}
|
||||
|
||||
func createFile(t *testing.T, filename, contents string) {
|
||||
var assert = assert.New(t)
|
||||
assert.NoError(ioutil.WriteFile(filename, []byte(contents), 0644))
|
||||
assert.NoError(t, ioutil.WriteFile(filename, []byte(contents), 0644))
|
||||
}
|
||||
|
||||
func createMainGo(t *testing.T) {
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestFormatFor(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Archive: config.Archive{
|
||||
@ -23,6 +22,6 @@ func TestFormatFor(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.Equal("zip", For(ctx, "windowsamd64"))
|
||||
assert.Equal("tar.gz", For(ctx, "linux386"))
|
||||
assert.Equal(t, "zip", For(ctx, "windowsamd64"))
|
||||
assert.Equal(t, "tar.gz", For(ctx, "linux386"))
|
||||
}
|
||||
|
@ -7,24 +7,24 @@ import (
|
||||
)
|
||||
|
||||
func TestEnv(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
assert.Equal(
|
||||
t,
|
||||
[]string{"GOOS=linux", "GOARCH=arm64", "GOARM=6"},
|
||||
New("linux", "arm64", "6").Env(),
|
||||
)
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
assert.Equal(
|
||||
t,
|
||||
"linuxarm7",
|
||||
New("linux", "arm", "7").String(),
|
||||
)
|
||||
}
|
||||
|
||||
func TestPrettyString(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
assert.Equal(
|
||||
t,
|
||||
"linux/arm646",
|
||||
New("linux", "arm64", "6").PrettyString(),
|
||||
)
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestAllBuildTargets(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var build = config.Build{
|
||||
Goos: []string{
|
||||
"linux",
|
||||
@ -41,7 +40,7 @@ func TestAllBuildTargets(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.Equal([]Target{
|
||||
assert.Equal(t, []Target{
|
||||
New("linux", "386", ""),
|
||||
New("linux", "amd64", ""),
|
||||
New("linux", "arm", "6"),
|
||||
|
@ -1,25 +1,21 @@
|
||||
package git_test
|
||||
package git
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/git"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGit(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
out, err := git.Run("init")
|
||||
assert.NoError(err)
|
||||
assert.Contains(out, "Initialized empty Git repository")
|
||||
out, err := Run("status")
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, out)
|
||||
|
||||
out, err = git.Run("command-that-dont-exist")
|
||||
assert.Error(err)
|
||||
assert.Empty(out)
|
||||
out, err = Run("command-that-dont-exist")
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, out)
|
||||
assert.Equal(
|
||||
t,
|
||||
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.\n",
|
||||
err.Error(),
|
||||
)
|
||||
|
@ -11,8 +11,6 @@ import (
|
||||
)
|
||||
|
||||
func TestChecksums(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
|
||||
var config = config.Project{
|
||||
Checksum: config.Checksum{
|
||||
NameTemplate: "{{.ProjectName }}_{{.Tag}}_{{.Version}}_checksums.txt",
|
||||
@ -28,13 +26,11 @@ func TestChecksums(t *testing.T) {
|
||||
}
|
||||
|
||||
name, err := ForChecksums(ctx)
|
||||
assert.NoError(err)
|
||||
assert.Equal("testcheck_v1.0.0_1.0.0_checksums.txt", name)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "testcheck_v1.0.0_1.0.0_checksums.txt", name)
|
||||
}
|
||||
|
||||
func TestNameFor(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
|
||||
var config = config.Project{
|
||||
Archive: config.Archive{
|
||||
NameTemplate: "{{.Binary}}_{{.Os}}_{{.Arch}}_{{.Tag}}_{{.Version}}",
|
||||
@ -54,13 +50,11 @@ func TestNameFor(t *testing.T) {
|
||||
}
|
||||
|
||||
name, err := For(ctx, buildtarget.New("darwin", "amd64", ""))
|
||||
assert.NoError(err)
|
||||
assert.Equal("test_Darwin_x86_64_v1.2.3_1.2.3", name)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "test_Darwin_x86_64_v1.2.3_1.2.3", name)
|
||||
}
|
||||
|
||||
func TestNameForBuild(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Archive: config.Archive{
|
||||
@ -83,12 +77,11 @@ func TestNameForBuild(t *testing.T) {
|
||||
config.Build{Binary: "foo"},
|
||||
buildtarget.New("darwin", "amd64", ""),
|
||||
)
|
||||
assert.NoError(err)
|
||||
assert.Equal("foo_Darwin_x86_64_v1.2.3_1.2.3", name)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "foo_Darwin_x86_64_v1.2.3_1.2.3", name)
|
||||
}
|
||||
|
||||
func TestInvalidNameTemplate(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Archive: config.Archive{
|
||||
@ -102,11 +95,10 @@ func TestInvalidNameTemplate(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := For(ctx, buildtarget.New("darwin", "amd64", ""))
|
||||
assert.Error(err)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestNameDefaultTemplate(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Archive: config.Archive{
|
||||
@ -123,8 +115,8 @@ func TestNameDefaultTemplate(t *testing.T) {
|
||||
} {
|
||||
t.Run(key, func(t *testing.T) {
|
||||
name, err := For(ctx, target)
|
||||
assert.NoError(err)
|
||||
assert.Equal(key, name)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, key, name)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -9,43 +9,38 @@ import (
|
||||
|
||||
// GitInit inits a new git project
|
||||
func GitInit(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
out, err := fakeGit("init")
|
||||
assert.NoError(err)
|
||||
assert.Contains(out, "Initialized empty Git repository")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, out, "Initialized empty Git repository")
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
// GitRemoteAdd adds the given url as remote
|
||||
func GitRemoteAdd(t *testing.T, url string) {
|
||||
var assert = assert.New(t)
|
||||
out, err := fakeGit("remote", "add", "origin", url)
|
||||
assert.NoError(err)
|
||||
assert.Empty(out)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, out)
|
||||
}
|
||||
|
||||
// GitCommit creates a git commits
|
||||
func GitCommit(t *testing.T, msg string) {
|
||||
var assert = assert.New(t)
|
||||
out, err := fakeGit("commit", "--allow-empty", "-m", msg)
|
||||
assert.NoError(err)
|
||||
assert.Contains(out, "master", msg)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, out, "master", msg)
|
||||
}
|
||||
|
||||
// GitTag creates a git tag
|
||||
func GitTag(t *testing.T, tag string) {
|
||||
var assert = assert.New(t)
|
||||
out, err := fakeGit("tag", tag)
|
||||
assert.NoError(err)
|
||||
assert.Empty(out)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, out)
|
||||
}
|
||||
|
||||
// GitAdd adds all files to stage
|
||||
func GitAdd(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
out, err := fakeGit("add", "-A")
|
||||
assert.NoError(err)
|
||||
assert.Empty(out)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, out)
|
||||
}
|
||||
|
||||
func fakeGit(args ...string) (string, error) {
|
||||
|
@ -12,13 +12,12 @@ import (
|
||||
// Mktmp creates a new tempdir, cd into it and provides a back function that
|
||||
// cd into the previous directory.
|
||||
func Mktmp(t *testing.T) (folder string, back func()) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
current, err := os.Getwd()
|
||||
assert.NoError(err)
|
||||
assert.NoError(os.Chdir(folder))
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, os.Chdir(folder))
|
||||
return folder, func() {
|
||||
assert.NoError(os.Chdir(current))
|
||||
assert.NoError(t, os.Chdir(current))
|
||||
}
|
||||
}
|
||||
|
@ -8,13 +8,12 @@ import (
|
||||
)
|
||||
|
||||
func TestMkTemp(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
current, err := os.Getwd()
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
folder, back := Mktmp(t)
|
||||
assert.NotEmpty(folder)
|
||||
assert.NotEmpty(t, folder)
|
||||
back()
|
||||
newCurrent, err := os.Getwd()
|
||||
assert.NoError(err)
|
||||
assert.Equal(current, newCurrent)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, current, newCurrent)
|
||||
}
|
||||
|
@ -16,19 +16,18 @@ func TestDescription(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunPipe(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
var dist = filepath.Join(folder, "dist")
|
||||
assert.NoError(os.Mkdir(dist, 0755))
|
||||
assert.NoError(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(dist, 0755))
|
||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin_darwin_amd64"), 0755))
|
||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin_windows_amd64"), 0755))
|
||||
_, 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"))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
_, err = os.Create(filepath.Join(folder, "README.md"))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Dist: dist,
|
||||
@ -50,25 +49,24 @@ func TestRunPipe(t *testing.T) {
|
||||
for _, format := range []string{"tar.gz", "zip"} {
|
||||
t.Run("Archive format "+format, func(t *testing.T) {
|
||||
ctx.Config.Archive.Format = format
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunPipeBinary(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
var dist = filepath.Join(folder, "dist")
|
||||
assert.NoError(os.Mkdir(dist, 0755))
|
||||
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin_darwin"), 0755))
|
||||
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin_win"), 0755))
|
||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin_darwin"), 0755))
|
||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin_win"), 0755))
|
||||
_, 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"))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
_, err = os.Create(filepath.Join(folder, "README.md"))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
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("windowsamd64", "mybin_win", "mybin.exe", filepath.Join(dist, "mybin_win", "mybin.exe"))
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.Contains(ctx.Artifacts, "mybin_darwin/mybin")
|
||||
assert.Contains(ctx.Artifacts, "mybin_win/mybin.exe")
|
||||
assert.Len(ctx.Artifacts, 2)
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
assert.Contains(t, ctx.Artifacts, "mybin_darwin/mybin")
|
||||
assert.Contains(t, ctx.Artifacts, "mybin_win/mybin.exe")
|
||||
assert.Len(t, ctx.Artifacts, 2)
|
||||
}
|
||||
|
||||
func TestRunPipeDistRemoved(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Dist: "/path/nope",
|
||||
@ -99,11 +96,10 @@ func TestRunPipeDistRemoved(t *testing.T) {
|
||||
},
|
||||
}
|
||||
ctx.AddBinary("windowsamd64", "nope", "no", "blah")
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestRunPipeInvalidGlob(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Dist: "/tmp",
|
||||
@ -115,14 +111,13 @@ func TestRunPipeInvalidGlob(t *testing.T) {
|
||||
},
|
||||
}
|
||||
ctx.AddBinary("windowsamd64", "whatever", "foo", "bar")
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestRunPipeGlobFailsToAdd(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, back := testlib.Mktmp(t)
|
||||
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{
|
||||
Config: config.Project{
|
||||
@ -135,5 +130,5 @@ func TestRunPipeGlobFailsToAdd(t *testing.T) {
|
||||
},
|
||||
}
|
||||
ctx.AddBinary("windows386", "mybin", "mybin", "dist/mybin")
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
@ -45,16 +45,14 @@ var defaultTemplateData = templateData{
|
||||
}
|
||||
|
||||
func assertDefaultTemplateData(t *testing.T, formulae string) {
|
||||
assert := assert.New(t)
|
||||
assert.Contains(formulae, "class Test < Formula")
|
||||
assert.Contains(formulae, `homepage "https://google.com"`)
|
||||
assert.Contains(formulae, `url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`)
|
||||
assert.Contains(formulae, `sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`)
|
||||
assert.Contains(formulae, `version "0.1.3"`)
|
||||
assert.Contains(t, formulae, "class Test < Formula")
|
||||
assert.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"`)
|
||||
assert.Contains(t, formulae, `sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`)
|
||||
assert.Contains(t, formulae, `version "0.1.3"`)
|
||||
}
|
||||
|
||||
func TestFullFormulae(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
data := defaultTemplateData
|
||||
data.Caveats = "Here are some caveats"
|
||||
data.Dependencies = []string{"gtk+"}
|
||||
@ -63,37 +61,34 @@ func TestFullFormulae(t *testing.T) {
|
||||
data.Install = []string{"custom install script", "another install script"}
|
||||
data.Tests = []string{`system "#{bin}/foo -version"`}
|
||||
out, err := doBuildFormula(data)
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
formulae := out.String()
|
||||
|
||||
bts, err := ioutil.ReadFile("testdata/test.rb")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
// ioutil.WriteFile("testdata/test.rb", []byte(formulae), 0644)
|
||||
|
||||
assert.Equal(string(bts), formulae)
|
||||
assert.Equal(t, string(bts), formulae)
|
||||
}
|
||||
|
||||
func TestFormulaeSimple(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
out, err := doBuildFormula(defaultTemplateData)
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
formulae := out.String()
|
||||
assertDefaultTemplateData(t, formulae)
|
||||
assert.NotContains(formulae, "def caveats")
|
||||
assert.NotContains(formulae, "depends_on")
|
||||
assert.NotContains(formulae, "def plist;")
|
||||
assert.NotContains(t, formulae, "def caveats")
|
||||
assert.NotContains(t, formulae, "depends_on")
|
||||
assert.NotContains(t, formulae, "def plist;")
|
||||
}
|
||||
|
||||
func TestSplit(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
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) {
|
||||
assert := assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.0.1",
|
||||
@ -131,27 +126,27 @@ func TestRunPipe(t *testing.T) {
|
||||
var path = filepath.Join(folder, "bin.tar.gz")
|
||||
ctx.AddBinary("darwinamd64", "bin", "bin", path)
|
||||
client := &DummyClient{}
|
||||
assert.Error(doRun(ctx, client))
|
||||
assert.False(client.CreatedFile)
|
||||
assert.Error(t, doRun(ctx, client))
|
||||
assert.False(t, client.CreatedFile)
|
||||
|
||||
_, err = os.Create(path)
|
||||
assert.NoError(err)
|
||||
assert.NoError(doRun(ctx, client))
|
||||
assert.True(client.CreatedFile)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, doRun(ctx, client))
|
||||
assert.True(t, client.CreatedFile)
|
||||
|
||||
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.Equal(string(bts), client.Content)
|
||||
|
||||
assert.Equal(t, string(bts), client.Content)
|
||||
}
|
||||
|
||||
func TestRunPipeFormatOverride(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var path = filepath.Join(folder, "bin.zip")
|
||||
_, err = os.Create(path)
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
@ -175,13 +170,12 @@ func TestRunPipeFormatOverride(t *testing.T) {
|
||||
}
|
||||
ctx.AddBinary("darwinamd64", "bin", "bin", path)
|
||||
client := &DummyClient{}
|
||||
assert.NoError(doRun(ctx, client))
|
||||
assert.True(client.CreatedFile)
|
||||
assert.Contains(client.Content, "bin.zip")
|
||||
assert.NoError(t, doRun(ctx, client))
|
||||
assert.True(t, client.CreatedFile)
|
||||
assert.Contains(t, client.Content, "bin.zip")
|
||||
}
|
||||
|
||||
func TestRunPipeNoDarwin64Build(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Archive: config.Archive{
|
||||
@ -197,23 +191,21 @@ func TestRunPipeNoDarwin64Build(t *testing.T) {
|
||||
Publish: true,
|
||||
}
|
||||
client := &DummyClient{}
|
||||
assert.Equal(ErrNoDarwin64Build, doRun(ctx, client))
|
||||
assert.False(client.CreatedFile)
|
||||
assert.Equal(t, ErrNoDarwin64Build, doRun(ctx, client))
|
||||
assert.False(t, client.CreatedFile)
|
||||
}
|
||||
|
||||
func TestRunPipeBrewNotSetup(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Publish: true,
|
||||
}
|
||||
client := &DummyClient{}
|
||||
testlib.AssertSkipped(t, doRun(ctx, client))
|
||||
assert.False(client.CreatedFile)
|
||||
assert.False(t, client.CreatedFile)
|
||||
}
|
||||
|
||||
func TestRunPipeBinaryRelease(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Publish: true,
|
||||
Config: config.Project{
|
||||
@ -231,21 +223,19 @@ func TestRunPipeBinaryRelease(t *testing.T) {
|
||||
ctx.AddBinary("darwinamd64", "foo", "bar", "baz")
|
||||
client := &DummyClient{}
|
||||
testlib.AssertSkipped(t, doRun(ctx, client))
|
||||
assert.False(client.CreatedFile)
|
||||
assert.False(t, client.CreatedFile)
|
||||
}
|
||||
|
||||
func TestRunPipeNoPublish(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Publish: false,
|
||||
}
|
||||
client := &DummyClient{}
|
||||
testlib.AssertSkipped(t, doRun(ctx, client))
|
||||
assert.False(client.CreatedFile)
|
||||
assert.False(t, client.CreatedFile)
|
||||
}
|
||||
|
||||
func TestRunPipeDraftRelease(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Publish: true,
|
||||
Config: config.Project{
|
||||
@ -262,11 +252,10 @@ func TestRunPipeDraftRelease(t *testing.T) {
|
||||
}
|
||||
client := &DummyClient{}
|
||||
testlib.AssertSkipped(t, doRun(ctx, client))
|
||||
assert.False(client.CreatedFile)
|
||||
assert.False(t, client.CreatedFile)
|
||||
}
|
||||
|
||||
func TestRunPipeFormatBinary(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Archive: config.Archive{
|
||||
@ -276,7 +265,7 @@ func TestRunPipeFormatBinary(t *testing.T) {
|
||||
}
|
||||
client := &DummyClient{}
|
||||
testlib.AssertSkipped(t, doRun(ctx, client))
|
||||
assert.False(client.CreatedFile)
|
||||
assert.False(t, client.CreatedFile)
|
||||
}
|
||||
|
||||
type DummyClient struct {
|
||||
|
@ -28,7 +28,6 @@ func TestRunInvalidCommand(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuild(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var config = config.Project{
|
||||
Builds: []config.Build{
|
||||
{
|
||||
@ -39,13 +38,12 @@ func TestBuild(t *testing.T) {
|
||||
},
|
||||
}
|
||||
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) {
|
||||
assert := assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var binary = filepath.Join(folder, "testing")
|
||||
var pre = filepath.Join(folder, "pre")
|
||||
var post = filepath.Join(folder, "post")
|
||||
@ -69,16 +67,15 @@ func TestRunFullPipe(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(context.New(config)))
|
||||
assert.True(exists(binary), binary)
|
||||
assert.True(exists(pre), pre)
|
||||
assert.True(exists(post), post)
|
||||
assert.NoError(t, Pipe{}.Run(context.New(config)))
|
||||
assert.True(t, exists(binary), binary)
|
||||
assert.True(t, exists(pre), pre)
|
||||
assert.True(t, exists(post), post)
|
||||
}
|
||||
|
||||
func TestRunPipeFormatBinary(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var binary = filepath.Join(folder, "binary-testing")
|
||||
var config = config.Project{
|
||||
ProjectName: "testing",
|
||||
@ -99,14 +96,13 @@ func TestRunPipeFormatBinary(t *testing.T) {
|
||||
NameTemplate: "binary-{{.Binary}}",
|
||||
},
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(context.New(config)))
|
||||
assert.True(exists(binary))
|
||||
assert.NoError(t, Pipe{}.Run(context.New(config)))
|
||||
assert.True(t, exists(binary))
|
||||
}
|
||||
|
||||
func TestRunPipeArmBuilds(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var binary = filepath.Join(folder, "armtesting")
|
||||
var config = config.Project{
|
||||
Dist: folder,
|
||||
@ -128,12 +124,11 @@ func TestRunPipeArmBuilds(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(context.New(config)))
|
||||
assert.True(exists(binary), binary)
|
||||
assert.NoError(t, Pipe{}.Run(context.New(config)))
|
||||
assert.True(t, exists(binary), binary)
|
||||
}
|
||||
|
||||
func TestBuildFailed(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var config = config.Project{
|
||||
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) {
|
||||
assert := assert.New(t)
|
||||
var config = config.Project{
|
||||
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) {
|
||||
var assert = assert.New(t)
|
||||
for _, format := range []string{"tar.gz", "zip", "binary"} {
|
||||
var config = config.Project{
|
||||
ProjectName: "nameeeee",
|
||||
@ -190,12 +183,11 @@ func TestRunInvalidNametemplate(t *testing.T) {
|
||||
NameTemplate: "{{.Binary}",
|
||||
},
|
||||
}
|
||||
assert.Error(Pipe{}.Run(context.New(config)))
|
||||
assert.Error(t, Pipe{}.Run(context.New(config)))
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunInvalidLdflags(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var config = config.Project{
|
||||
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) {
|
||||
assert := assert.New(t)
|
||||
var config = config.Project{
|
||||
Builds: []config.Build{
|
||||
{
|
||||
@ -232,11 +223,11 @@ func TestRunPipeFailingHooks(t *testing.T) {
|
||||
var ctx = context.New(config)
|
||||
t.Run("pre-hook", func(t *testing.T) {
|
||||
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) {
|
||||
ctx.Config.Builds[0].Hooks.Post = "exit 1"
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestLdFlagsFullTemplate(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var config = config.Project{
|
||||
Builds: []config.Build{
|
||||
{
|
||||
@ -26,16 +25,15 @@ func TestLdFlagsFullTemplate(t *testing.T) {
|
||||
Config: config,
|
||||
}
|
||||
flags, err := ldflags(ctx, ctx.Config.Builds[0])
|
||||
assert.NoError(err)
|
||||
assert.Contains(flags, "-s -w")
|
||||
assert.Contains(flags, "-X main.version=1.2.3")
|
||||
assert.Contains(flags, "-X main.tag=v1.2.3")
|
||||
assert.Contains(flags, "-X main.commit=123")
|
||||
assert.Contains(flags, "-X main.date=")
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, flags, "-s -w")
|
||||
assert.Contains(t, flags, "-X main.version=1.2.3")
|
||||
assert.Contains(t, flags, "-X main.tag=v1.2.3")
|
||||
assert.Contains(t, flags, "-X main.commit=123")
|
||||
assert.Contains(t, flags, "-X main.date=")
|
||||
}
|
||||
|
||||
func TestInvalidTemplate(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var config = config.Project{
|
||||
Builds: []config.Build{
|
||||
{Ldflags: "{invalid{.Template}}}{{}}}"},
|
||||
@ -45,6 +43,6 @@ func TestInvalidTemplate(t *testing.T) {
|
||||
Config: config,
|
||||
}
|
||||
flags, err := ldflags(ctx, ctx.Config.Builds[0])
|
||||
assert.Error(err)
|
||||
assert.Equal(flags, "")
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, flags, "")
|
||||
}
|
||||
|
@ -15,13 +15,12 @@ func TestDescription(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPipe(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var binary = "binary"
|
||||
var checksums = binary + "_checksums.txt"
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
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{
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
@ -32,17 +31,16 @@ func TestPipe(t *testing.T) {
|
||||
},
|
||||
}
|
||||
ctx.AddArtifact(file)
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.Contains(ctx.Artifacts, checksums, binary)
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
assert.Contains(t, ctx.Artifacts, checksums, binary)
|
||||
bts, err := ioutil.ReadFile(filepath.Join(folder, checksums))
|
||||
assert.NoError(err)
|
||||
assert.Equal(string(bts), "61d034473102d7dac305902770471fd50f4c5b26f6831a56dd90b5184b3c30fc binary\n")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, string(bts), "61d034473102d7dac305902770471fd50f4c5b26f6831a56dd90b5184b3c30fc binary\n")
|
||||
}
|
||||
|
||||
func TestPipeFileNotExist(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
@ -53,14 +51,13 @@ func TestPipeFileNotExist(t *testing.T) {
|
||||
}
|
||||
ctx.AddArtifact("nope")
|
||||
err = Pipe{}.Run(ctx)
|
||||
assert.Error(err)
|
||||
assert.Contains(err.Error(), "/nope: no such file or directory")
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "/nope: no such file or directory")
|
||||
}
|
||||
|
||||
func TestPipeInvalidNameTemplate(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
@ -72,16 +69,15 @@ func TestPipeInvalidNameTemplate(t *testing.T) {
|
||||
}
|
||||
ctx.AddArtifact("whatever")
|
||||
err = Pipe{}.Run(ctx)
|
||||
assert.Error(err)
|
||||
assert.Equal(`template: name:1: unexpected "}" in operand`, err.Error())
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, `template: name:1: unexpected "}" in operand`, err.Error())
|
||||
}
|
||||
|
||||
func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
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{
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
@ -92,6 +88,6 @@ func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) {
|
||||
}
|
||||
ctx.AddArtifact("nope")
|
||||
err = Pipe{}.Run(ctx)
|
||||
assert.Error(err)
|
||||
assert.Contains(err.Error(), "/checksums.txt: permission denied")
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "/checksums.txt: permission denied")
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func TestDistDoesNotExist(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
assert.NoError(
|
||||
t,
|
||||
Pipe{}.Run(
|
||||
&context.Context{
|
||||
Config: config.Project{
|
||||
@ -25,42 +25,39 @@ func TestDistDoesNotExist(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPopulatedDistExists(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "disttest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
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"))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Dist: dist,
|
||||
},
|
||||
}
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
ctx.RmDist = true
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
_, err = os.Stat(dist)
|
||||
assert.False(os.IsExist(err))
|
||||
assert.False(t, os.IsExist(err))
|
||||
}
|
||||
|
||||
func TestEmptyDistExists(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "disttest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var dist = filepath.Join(folder, "dist")
|
||||
assert.NoError(os.Mkdir(dist, 0755))
|
||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Dist: dist,
|
||||
},
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
_, err = os.Stat(dist)
|
||||
assert.False(os.IsExist(err))
|
||||
assert.False(t, os.IsExist(err))
|
||||
}
|
||||
|
||||
func TestDescription(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
assert.NotEmpty(Pipe{}.Description())
|
||||
assert.NotEmpty(t, Pipe{}.Description())
|
||||
}
|
||||
|
@ -15,27 +15,27 @@ func TestDescription(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFillBasicData(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.Equal("goreleaser", ctx.Config.Release.GitHub.Owner)
|
||||
assert.Equal("goreleaser", ctx.Config.Release.GitHub.Name)
|
||||
assert.NotEmpty(ctx.Config.Builds)
|
||||
assert.Equal("goreleaser", ctx.Config.Builds[0].Binary)
|
||||
assert.Equal(".", ctx.Config.Builds[0].Main)
|
||||
assert.Contains(ctx.Config.Builds[0].Goos, "darwin")
|
||||
assert.Contains(ctx.Config.Builds[0].Goos, "linux")
|
||||
assert.Contains(ctx.Config.Builds[0].Goarch, "386")
|
||||
assert.Contains(ctx.Config.Builds[0].Goarch, "amd64")
|
||||
assert.Equal("tar.gz", ctx.Config.Archive.Format)
|
||||
assert.Contains(ctx.Config.Brew.Install, "bin.install \"goreleaser\"")
|
||||
assert.Contains(ctx.Config.Brew.CommitAuthor.Name, "goreleaserbot")
|
||||
assert.Contains(ctx.Config.Brew.CommitAuthor.Email, "goreleaser@carlosbecker.com")
|
||||
assert.Empty(ctx.Config.Dockers)
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
||||
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
||||
assert.NotEmpty(t, ctx.Config.Builds)
|
||||
assert.Equal(t, "goreleaser", ctx.Config.Builds[0].Binary)
|
||||
assert.Equal(t, ".", ctx.Config.Builds[0].Main)
|
||||
assert.Contains(t, ctx.Config.Builds[0].Goos, "darwin")
|
||||
assert.Contains(t, ctx.Config.Builds[0].Goos, "linux")
|
||||
assert.Contains(t, ctx.Config.Builds[0].Goarch, "386")
|
||||
assert.Contains(t, ctx.Config.Builds[0].Goarch, "amd64")
|
||||
assert.Equal(t, "tar.gz", ctx.Config.Archive.Format)
|
||||
assert.Contains(t, ctx.Config.Brew.Install, "bin.install \"goreleaser\"")
|
||||
assert.Empty(t, ctx.Config.Dockers)
|
||||
assert.Equal(t, ctx.Config.Brew.CommitAuthor.Name, "goreleaserbot")
|
||||
assert.Equal(t, ctx.Config.Brew.CommitAuthor.Email, "goreleaser@carlosbecker.com")
|
||||
assert.NotEmpty(
|
||||
t,
|
||||
ctx.Config.Archive.NameTemplate,
|
||||
ctx.Config.Builds[0].Ldflags,
|
||||
ctx.Config.Archive.Files,
|
||||
@ -43,7 +43,6 @@ func TestFillBasicData(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFillPartial(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
@ -73,18 +72,17 @@ func TestFillPartial(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.Len(ctx.Config.Archive.Files, 1)
|
||||
assert.Equal(`bin.install "testreleaser"`, ctx.Config.Brew.Install)
|
||||
assert.NotEmpty(ctx.Config.Dockers[0].Binary)
|
||||
assert.NotEmpty(ctx.Config.Dockers[0].Goos)
|
||||
assert.NotEmpty(ctx.Config.Dockers[0].Goarch)
|
||||
assert.NotEmpty(ctx.Config.Dockers[0].Dockerfile)
|
||||
assert.Empty(ctx.Config.Dockers[0].Goarm)
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
assert.Len(t, ctx.Config.Archive.Files, 1)
|
||||
assert.Equal(t, `bin.install "testreleaser"`, ctx.Config.Brew.Install)
|
||||
assert.NotEmpty(t, ctx.Config.Dockers[0].Binary)
|
||||
assert.NotEmpty(t, ctx.Config.Dockers[0].Goos)
|
||||
assert.NotEmpty(t, ctx.Config.Dockers[0].Goarch)
|
||||
assert.NotEmpty(t, ctx.Config.Dockers[0].Dockerfile)
|
||||
assert.Empty(t, ctx.Config.Dockers[0].Goarm)
|
||||
}
|
||||
|
||||
func TestFillSingleBuild(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
@ -93,23 +91,22 @@ func TestFillSingleBuild(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.Len(ctx.Config.Builds, 1)
|
||||
assert.Equal(ctx.Config.Builds[0].Binary, "goreleaser")
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
assert.Len(t, ctx.Config.Builds, 1)
|
||||
assert.Equal(t, ctx.Config.Builds[0].Binary, "goreleaser")
|
||||
}
|
||||
|
||||
func TestNotAGitRepo(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
previous, err := os.Getwd()
|
||||
assert.NoError(err)
|
||||
assert.NoError(os.Chdir(folder))
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, os.Chdir(folder))
|
||||
defer func() {
|
||||
assert.NoError(os.Chdir(previous))
|
||||
assert.NoError(t, os.Chdir(previous))
|
||||
}()
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
@ -7,20 +7,17 @@ import (
|
||||
)
|
||||
|
||||
func TestRepoName(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
repo, err := remoteRepo()
|
||||
assert.NoError(err)
|
||||
assert.Equal("goreleaser/goreleaser", repo.String())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "goreleaser/goreleaser", repo.String())
|
||||
}
|
||||
|
||||
func TestExtractReporFromGitURL(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
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) {
|
||||
var assert = assert.New(t)
|
||||
repo := extractRepoFromURL("https://github.com/goreleaser/goreleaser.git")
|
||||
assert.Equal("goreleaser/goreleaser", repo.String())
|
||||
assert.Equal(t, "goreleaser/goreleaser", repo.String())
|
||||
}
|
||||
|
@ -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
|
||||
if !ctx.Publish {
|
||||
return pipeline.Skip("--skip-publish is set")
|
||||
|
@ -15,15 +15,14 @@ import (
|
||||
)
|
||||
|
||||
func TestRunPipe(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "archivetest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var dist = filepath.Join(folder, "dist")
|
||||
assert.NoError(os.Mkdir(dist, 0755))
|
||||
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||
_, err = os.Create(binPath)
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var images = []string{
|
||||
"goreleaser/test_run_pipe:1.0.0",
|
||||
"goreleaser/test_run_pipe:latest",
|
||||
@ -60,34 +59,31 @@ func TestRunPipe(t *testing.T) {
|
||||
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} {
|
||||
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
|
||||
// the step ran
|
||||
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
|
||||
// it should fail
|
||||
assert.Error(
|
||||
assert.Error(t,
|
||||
exec.Command("docker", "rmi", "goreleaser/test_run_pipe_nope:1.0.0").Run(),
|
||||
)
|
||||
}
|
||||
|
||||
func TestDescription(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
assert.NotEmpty(Pipe{}.Description())
|
||||
assert.NotEmpty(t, Pipe{}.Description())
|
||||
}
|
||||
|
||||
func TestNoDockers(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
assert.True(pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{}))))
|
||||
assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{}))))
|
||||
}
|
||||
|
||||
func TestNoDockerWithoutImageName(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
assert.True(pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{
|
||||
assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{
|
||||
Dockers: []config.Docker{
|
||||
{
|
||||
Goos: "linux",
|
||||
@ -97,12 +93,11 @@ func TestNoDockerWithoutImageName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDockerNotInPath(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var path = os.Getenv("PATH")
|
||||
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{
|
||||
Version: "1.0.0",
|
||||
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())
|
||||
}
|
||||
|
13
pipeline/env/env_test.go
vendored
13
pipeline/env/env_test.go
vendored
@ -16,25 +16,23 @@ func TestDescription(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidEnv(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
assert.NoError(os.Setenv("GITHUB_TOKEN", "asdf"))
|
||||
assert.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf"))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
Publish: true,
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestInvalidEnv(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
assert.NoError(os.Unsetenv("GITHUB_TOKEN"))
|
||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
Publish: true,
|
||||
}
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
type flags struct {
|
||||
@ -54,8 +52,7 @@ func TestInvalidEnvChecksSkipped(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(fmt.Sprintf("%v", flag), func(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
assert.NoError(os.Unsetenv("GITHUB_TOKEN"))
|
||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: flag.Validate,
|
||||
|
@ -25,15 +25,14 @@ func TestRunPipeNoFormats(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunPipe(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "archivetest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var dist = filepath.Join(folder, "dist")
|
||||
assert.NoError(os.Mkdir(dist, 0755))
|
||||
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||
var binPath = filepath.Join(dist, "mybin", "mybin")
|
||||
_, err = os.Create(binPath)
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Version: "1.0.0",
|
||||
Config: config.Project{
|
||||
@ -54,16 +53,15 @@ func TestRunPipe(t *testing.T) {
|
||||
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} {
|
||||
ctx.AddBinary(plat, "mybin", "mybin", binPath)
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestNoFPMInPath(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var path = os.Getenv("PATH")
|
||||
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{
|
||||
Version: "1.0.0",
|
||||
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) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "archivetest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var dist = filepath.Join(folder, "dist")
|
||||
assert.NoError(os.Mkdir(dist, 0755))
|
||||
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
||||
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
||||
var ctx = &context.Context{
|
||||
Version: "1.0.0",
|
||||
Config: config.Project{
|
||||
@ -95,11 +92,10 @@ func TestCreateFileDoesntExist(t *testing.T) {
|
||||
},
|
||||
}
|
||||
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) {
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Version: "1.0.0",
|
||||
Config: config.Project{
|
||||
@ -108,5 +104,5 @@ func TestRunPipeWithExtraFiles(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
@ -18,17 +18,15 @@ func TestDescription(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNotAGitFolder(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestSingleCommit(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
@ -38,22 +36,20 @@ func TestSingleCommit(t *testing.T) {
|
||||
Config: config.Project{},
|
||||
}
|
||||
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) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestNoTagsSnapshot(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
@ -68,11 +64,10 @@ func TestNoTagsSnapshot(t *testing.T) {
|
||||
Publish: false,
|
||||
}
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
assert.Contains(ctx.Version, "SNAPSHOT-")
|
||||
assert.Contains(t, ctx.Version, "SNAPSHOT-")
|
||||
}
|
||||
|
||||
func TestNoTagsSnapshotInvalidTemplate(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
@ -86,14 +81,13 @@ func TestNoTagsSnapshotInvalidTemplate(t *testing.T) {
|
||||
Snapshot: true,
|
||||
Publish: false,
|
||||
}
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
// TestNoTagsNoSnapshot covers the situation where a repository
|
||||
// only contains simple commits and no tags. In this case you have
|
||||
// to set the --snapshot flag otherwise an error is returned.
|
||||
func TestNoTagsNoSnapshot(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
@ -107,11 +101,10 @@ func TestNoTagsNoSnapshot(t *testing.T) {
|
||||
Snapshot: false,
|
||||
Publish: false,
|
||||
}
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestInvalidTagFormat(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
@ -121,32 +114,30 @@ func TestInvalidTagFormat(t *testing.T) {
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
assert.EqualError(Pipe{}.Run(ctx), "sadasd is not in a valid version format")
|
||||
assert.Equal("sadasd", ctx.Git.CurrentTag)
|
||||
assert.EqualError(t, Pipe{}.Run(ctx), "sadasd is not in a valid version format")
|
||||
assert.Equal(t, "sadasd", ctx.Git.CurrentTag)
|
||||
}
|
||||
|
||||
func TestDirty(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
dummy, err := os.Create(filepath.Join(folder, "dummy"))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
testlib.GitAdd(t)
|
||||
testlib.GitCommit(t, "commit2")
|
||||
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{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
err = Pipe{}.Run(ctx)
|
||||
assert.Error(err)
|
||||
assert.Contains(err.Error(), "git is currently in a dirty state:")
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "git is currently in a dirty state:")
|
||||
}
|
||||
|
||||
func TestTagIsNotLastCommit(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
@ -158,12 +149,11 @@ func TestTagIsNotLastCommit(t *testing.T) {
|
||||
Validate: true,
|
||||
}
|
||||
err := Pipe{}.Run(ctx)
|
||||
assert.Error(err)
|
||||
assert.Contains(err.Error(), "git tag v0.0.1 was not made against commit")
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "git tag v0.0.1 was not made against commit")
|
||||
}
|
||||
|
||||
func TestValidState(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
@ -175,10 +165,10 @@ func TestValidState(t *testing.T) {
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.Equal("v0.0.2", ctx.Git.CurrentTag)
|
||||
assert.NotContains("commit4", ctx.ReleaseNotes)
|
||||
assert.NotContains("commit3", ctx.ReleaseNotes)
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
assert.Equal(t, "v0.0.2", ctx.Git.CurrentTag)
|
||||
assert.NotContains(t, "commit4", ctx.ReleaseNotes)
|
||||
assert.NotContains(t, "commit3", ctx.ReleaseNotes)
|
||||
}
|
||||
|
||||
func TestNoValidate(t *testing.T) {
|
||||
@ -197,7 +187,6 @@ func TestNoValidate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChangelog(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
@ -210,15 +199,14 @@ func TestChangelog(t *testing.T) {
|
||||
Config: config.Project{},
|
||||
}
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
assert.Equal("v0.0.2", ctx.Git.CurrentTag)
|
||||
assert.Contains(ctx.ReleaseNotes, "## Changelog")
|
||||
assert.NotContains(ctx.ReleaseNotes, "first")
|
||||
assert.Contains(ctx.ReleaseNotes, "added feature 1")
|
||||
assert.Contains(ctx.ReleaseNotes, "fixed bug 2")
|
||||
assert.Equal(t, "v0.0.2", ctx.Git.CurrentTag)
|
||||
assert.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
||||
assert.NotContains(t, ctx.ReleaseNotes, "first")
|
||||
assert.Contains(t, ctx.ReleaseNotes, "added feature 1")
|
||||
assert.Contains(t, ctx.ReleaseNotes, "fixed bug 2")
|
||||
}
|
||||
|
||||
func TestChangelogOfFirstRelease(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
@ -236,15 +224,14 @@ func TestChangelogOfFirstRelease(t *testing.T) {
|
||||
Config: config.Project{},
|
||||
}
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
assert.Equal("v0.0.1", ctx.Git.CurrentTag)
|
||||
assert.Contains(ctx.ReleaseNotes, "## Changelog")
|
||||
assert.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
||||
assert.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
||||
for _, msg := range msgs {
|
||||
assert.Contains(ctx.ReleaseNotes, msg)
|
||||
assert.Contains(t, ctx.ReleaseNotes, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomReleaseNotes(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
@ -255,6 +242,6 @@ func TestCustomReleaseNotes(t *testing.T) {
|
||||
ReleaseNotes: "custom",
|
||||
}
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
assert.Equal("v0.0.1", ctx.Git.CurrentTag)
|
||||
assert.Equal(ctx.ReleaseNotes, "custom")
|
||||
assert.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
||||
assert.Equal(t, ctx.ReleaseNotes, "custom")
|
||||
}
|
||||
|
@ -8,15 +8,13 @@ import (
|
||||
)
|
||||
|
||||
func TestSkipPipe(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var reason = "this is a test"
|
||||
var err = Skip(reason)
|
||||
assert.Error(err)
|
||||
assert.Equal(reason, err.Error())
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, reason, err.Error())
|
||||
}
|
||||
|
||||
func TestIsSkip(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
assert.True(IsSkip(Skip("whatever")))
|
||||
assert.False(IsSkip(errors.New("nope")))
|
||||
assert.True(t, IsSkip(Skip("whatever")))
|
||||
assert.False(t, IsSkip(errors.New("nope")))
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
)
|
||||
|
||||
func TestDescribeBody(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var changelog = "\nfeature1: description\nfeature2: other description"
|
||||
var ctx = &context.Context{
|
||||
ReleaseNotes: changelog,
|
||||
@ -20,52 +19,49 @@ func TestDescribeBody(t *testing.T) {
|
||||
},
|
||||
}
|
||||
out, err := describeBodyVersion(ctx, "go version go1.9 darwin/amd64")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
|
||||
bts, err := ioutil.ReadFile("testdata/release1.txt")
|
||||
assert.NoError(err)
|
||||
ioutil.WriteFile("testdata/release1.txt", out.Bytes(), 0755)
|
||||
assert.NoError(t, err)
|
||||
// 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) {
|
||||
var assert = assert.New(t)
|
||||
var changelog = "\nfeature1: description\nfeature2: other description"
|
||||
var ctx = &context.Context{
|
||||
ReleaseNotes: changelog,
|
||||
}
|
||||
out, err := describeBodyVersion(ctx, "go version go1.9 darwin/amd64")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
|
||||
bts, err := ioutil.ReadFile("testdata/release2.txt")
|
||||
assert.NoError(err)
|
||||
ioutil.WriteFile("testdata/release2.txt", out.Bytes(), 0755)
|
||||
assert.NoError(t, err)
|
||||
// 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) {
|
||||
var assert = assert.New(t)
|
||||
var changelog = "<h1>test</h1>"
|
||||
var ctx = &context.Context{
|
||||
ReleaseNotes: changelog,
|
||||
}
|
||||
out, err := describeBody(ctx)
|
||||
assert.NoError(err)
|
||||
assert.Contains(out.String(), changelog)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, out.String(), changelog)
|
||||
}
|
||||
|
||||
func TestGoVersionFails(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var path = os.Getenv("PATH")
|
||||
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{
|
||||
ReleaseNotes: "changelog",
|
||||
}
|
||||
_, err := describeBody(ctx)
|
||||
assert.Error(err)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
@ -19,13 +19,12 @@ func TestPipeDescription(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunPipe(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
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"))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var config = config.Project{
|
||||
Dist: folder,
|
||||
Release: config.Release{
|
||||
@ -41,15 +40,14 @@ func TestRunPipe(t *testing.T) {
|
||||
ctx.AddArtifact(tarfile.Name())
|
||||
ctx.AddArtifact(debfile.Name())
|
||||
client := &DummyClient{}
|
||||
assert.NoError(doRun(ctx, client))
|
||||
assert.True(client.CreatedRelease)
|
||||
assert.True(client.UploadedFile)
|
||||
assert.Contains(client.UploadedFileNames, "bin.deb")
|
||||
assert.Contains(client.UploadedFileNames, "bin.tar.gz")
|
||||
assert.NoError(t, doRun(ctx, client))
|
||||
assert.True(t, client.CreatedRelease)
|
||||
assert.True(t, client.UploadedFile)
|
||||
assert.Contains(t, client.UploadedFileNames, "bin.deb")
|
||||
assert.Contains(t, client.UploadedFileNames, "bin.tar.gz")
|
||||
}
|
||||
|
||||
func TestRunPipeReleaseCreationFailed(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var config = config.Project{
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
@ -64,13 +62,12 @@ func TestRunPipeReleaseCreationFailed(t *testing.T) {
|
||||
client := &DummyClient{
|
||||
FailToCreateRelease: true,
|
||||
}
|
||||
assert.Error(doRun(ctx, client))
|
||||
assert.False(client.CreatedRelease)
|
||||
assert.False(client.UploadedFile)
|
||||
assert.Error(t, doRun(ctx, client))
|
||||
assert.False(t, client.CreatedRelease)
|
||||
assert.False(t, client.UploadedFile)
|
||||
}
|
||||
|
||||
func TestRunPipeWithFileThatDontExist(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var config = config.Project{
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
@ -84,17 +81,16 @@ func TestRunPipeWithFileThatDontExist(t *testing.T) {
|
||||
ctx.Publish = true
|
||||
ctx.AddArtifact("this-file-wont-exist-hopefully")
|
||||
client := &DummyClient{}
|
||||
assert.Error(doRun(ctx, client))
|
||||
assert.True(client.CreatedRelease)
|
||||
assert.False(client.UploadedFile)
|
||||
assert.Error(t, doRun(ctx, client))
|
||||
assert.True(t, client.CreatedRelease)
|
||||
assert.False(t, client.UploadedFile)
|
||||
}
|
||||
|
||||
func TestRunPipeUploadFailure(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var config = config.Project{
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
@ -110,21 +106,20 @@ func TestRunPipeUploadFailure(t *testing.T) {
|
||||
client := &DummyClient{
|
||||
FailToUpload: true,
|
||||
}
|
||||
assert.Error(doRun(ctx, client))
|
||||
assert.True(client.CreatedRelease)
|
||||
assert.False(client.UploadedFile)
|
||||
assert.Error(t, doRun(ctx, client))
|
||||
assert.True(t, client.CreatedRelease)
|
||||
assert.False(t, client.UploadedFile)
|
||||
}
|
||||
|
||||
func TestSkipPublish(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Publish: false,
|
||||
Parallelism: 1,
|
||||
}
|
||||
client := &DummyClient{}
|
||||
testlib.AssertSkipped(t, doRun(ctx, client))
|
||||
assert.False(client.CreatedRelease)
|
||||
assert.False(client.UploadedFile)
|
||||
assert.False(t, client.CreatedRelease)
|
||||
assert.False(t, client.UploadedFile)
|
||||
}
|
||||
|
||||
type DummyClient struct {
|
||||
|
@ -29,24 +29,22 @@ func TestRunPipeMissingInfo(t *testing.T) {
|
||||
pipeline.Skip("no summary nor description were provided"): {},
|
||||
} {
|
||||
t.Run(fmt.Sprintf("testing if %v happens", eerr), func(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Snapcraft: snap,
|
||||
},
|
||||
}
|
||||
assert.Equal(eerr, Pipe{}.Run(ctx))
|
||||
assert.Equal(t, eerr, Pipe{}.Run(ctx))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunPipe(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "archivetest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var dist = filepath.Join(folder, "dist")
|
||||
assert.NoError(os.Mkdir(dist, 0755))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Version: "testversion",
|
||||
Config: config.Project{
|
||||
@ -59,16 +57,15 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
}
|
||||
addBinaries(t, ctx, "mybin", dist)
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestRunPipeWithName(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "archivetest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var dist = filepath.Join(folder, "dist")
|
||||
assert.NoError(os.Mkdir(dist, 0755))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Version: "testversion",
|
||||
Config: config.Project{
|
||||
@ -82,22 +79,21 @@ func TestRunPipeWithName(t *testing.T) {
|
||||
},
|
||||
}
|
||||
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"))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var metadata Metadata
|
||||
err = yaml.Unmarshal(yamlFile, &metadata)
|
||||
assert.NoError(err)
|
||||
assert.Equal(metadata.Name, "testsnapname")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, metadata.Name, "testsnapname")
|
||||
}
|
||||
|
||||
func TestRunPipeWithPlugsAndDaemon(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "archivetest")
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var dist = filepath.Join(folder, "dist")
|
||||
assert.NoError(os.Mkdir(dist, 0755))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, os.Mkdir(dist, 0755))
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Version: "testversion",
|
||||
Config: config.Project{
|
||||
@ -116,23 +112,22 @@ func TestRunPipeWithPlugsAndDaemon(t *testing.T) {
|
||||
},
|
||||
}
|
||||
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"))
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
var metadata Metadata
|
||||
err = yaml.Unmarshal(yamlFile, &metadata)
|
||||
assert.NoError(err)
|
||||
assert.Equal(metadata.Apps["mybin"].Plugs, []string{"home", "network"})
|
||||
assert.Equal(metadata.Apps["mybin"].Daemon, "simple")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, metadata.Apps["mybin"].Plugs, []string{"home", "network"})
|
||||
assert.Equal(t, metadata.Apps["mybin"].Daemon, "simple")
|
||||
}
|
||||
|
||||
func TestNoSnapcraftInPath(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var path = os.Getenv("PATH")
|
||||
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{
|
||||
Config: config.Project{
|
||||
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) {
|
||||
var assert = assert.New(t)
|
||||
for _, plat := range []string{
|
||||
"linuxamd64",
|
||||
"linux386",
|
||||
@ -155,10 +149,10 @@ func addBinaries(t *testing.T, ctx *context.Context, name, dist string) {
|
||||
"linuxwtf",
|
||||
} {
|
||||
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)
|
||||
_, err := os.Create(binPath)
|
||||
assert.NoError(err)
|
||||
assert.NoError(t, err)
|
||||
ctx.AddBinary(plat, folder, name, binPath)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user