-
-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from goreleaser/tests
Increasing test coverage
- Loading branch information
Showing
19 changed files
with
430 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
language: go | ||
go: 1.8 | ||
install: make setup | ||
install: | ||
- make setup | ||
- gem install fpm | ||
script: | ||
- make test | ||
after_success: | ||
- go get github.com/mattn/goveralls | ||
- goveralls -coverprofile=coverage.out -service=travis-ci -repotoken="$COVERALLS_TOKEN" | ||
- test -n "$TRAVIS_TAG" && gem install fpm && go run main.go | ||
- test -n "$TRAVIS_TAG" && go run main.go | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package archive | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/goreleaser/goreleaser/config" | ||
"github.com/goreleaser/goreleaser/context" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDescription(t *testing.T) { | ||
assert.NotEmpty(t, Pipe{}.Description()) | ||
} | ||
|
||
func TestRunPipe(t *testing.T) { | ||
var assert = assert.New(t) | ||
folder, err := ioutil.TempDir("", "archivetest") | ||
assert.NoError(err) | ||
current, err := os.Getwd() | ||
assert.NoError(err) | ||
assert.NoError(os.Chdir(folder)) | ||
defer func() { | ||
assert.NoError(os.Chdir(current)) | ||
}() | ||
var dist = filepath.Join(folder, "dist") | ||
assert.NoError(os.Mkdir(dist, 0755)) | ||
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755)) | ||
_, err = os.Create(filepath.Join(dist, "mybin", "mybin")) | ||
assert.NoError(err) | ||
readme, err := os.Create(filepath.Join(folder, "README.md")) | ||
assert.NoError(err) | ||
var ctx = &context.Context{ | ||
Archives: map[string]string{ | ||
"darwinamd64": "mybin", | ||
}, | ||
Config: config.Project{ | ||
Dist: dist, | ||
Archive: config.Archive{ | ||
Files: []string{ | ||
"README.md", | ||
}, | ||
}, | ||
}, | ||
} | ||
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)) | ||
}) | ||
} | ||
t.Run("Removed README", func(t *testing.T) { | ||
assert.NoError(os.Remove(readme.Name())) | ||
assert.Error(Pipe{}.Run(ctx)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package fpm | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/goreleaser/goreleaser/config" | ||
"github.com/goreleaser/goreleaser/context" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDescription(t *testing.T) { | ||
assert.NotEmpty(t, Pipe{}.Description()) | ||
} | ||
|
||
func TestRunPipeNoFormats(t *testing.T) { | ||
var assert = assert.New(t) | ||
var ctx = &context.Context{ | ||
Config: config.Project{}, | ||
} | ||
assert.NoError(Pipe{}.Run(ctx)) | ||
} | ||
|
||
func TestRunPipe(t *testing.T) { | ||
var assert = assert.New(t) | ||
folder, err := ioutil.TempDir("", "archivetest") | ||
assert.NoError(err) | ||
var dist = filepath.Join(folder, "dist") | ||
assert.NoError(os.Mkdir(dist, 0755)) | ||
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755)) | ||
_, err = os.Create(filepath.Join(dist, "mybin", "mybin")) | ||
assert.NoError(err) | ||
var ctx = &context.Context{ | ||
Archives: map[string]string{ | ||
"linuxamd64": "mybin", | ||
}, | ||
Config: config.Project{ | ||
Dist: dist, | ||
Build: config.Build{ | ||
Goarch: []string{ | ||
"amd64", | ||
"i386", | ||
}, | ||
Binary: "mybin", | ||
}, | ||
FPM: config.FPM{ | ||
Formats: []string{"deb"}, | ||
Dependencies: []string{"make"}, | ||
Conflicts: []string{"git"}, | ||
}, | ||
}, | ||
} | ||
assert.NoError(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)) | ||
}() | ||
os.Setenv("PATH", "") | ||
var ctx = &context.Context{ | ||
Config: config.Project{ | ||
FPM: config.FPM{ | ||
Formats: []string{"deb"}, | ||
}, | ||
}, | ||
} | ||
assert.EqualError(Pipe{}.Run(ctx), ErrNoFPM.Error()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package git | ||
|
||
import ( | ||
"errors" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func git(args ...string) (output string, err error) { | ||
var cmd = exec.Command("git", args...) | ||
bts, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return "", errors.New(string(bts)) | ||
} | ||
return string(bts), err | ||
} | ||
|
||
func cleanGit(args ...string) (output string, err error) { | ||
output, err = git(args...) | ||
return strings.Replace(strings.Split(output, "\n")[0], "'", "", -1), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.