Skip to content

Commit

Permalink
Adding gometalinter testing
Browse files Browse the repository at this point in the history
Cleaned up code based on linter feedback
  • Loading branch information
mattfarina committed Jan 5, 2017
1 parent 6abbba9 commit 95aab3c
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 127 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: go

go:
- 1.3
- 1.4
- 1.5
- 1.6
- 1.7
Expand All @@ -18,6 +16,10 @@ before_script:
# - http://docs.travis-ci.com/user/workers/standard-infrastructure/
sudo: false

script:
- GO15VENDOREXPERIMENT=1 make setup
- GO15VENDOREXPERIMENT=1 make test

notifications:
webhooks:
urls:
Expand Down
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.PHONY: setup
setup:
go get -u gopkg.in/alecthomas/gometalinter.v1
gometalinter.v1 --install

.PHONY: test
test: validate lint
@echo "==> Running tests"
go test -v

.PHONY: validate
validate:
# misspell finds the work adresář (used in bzr.go) as a mispelling of
# address. It finds adres. An issue has been filed at
# https://github.com/client9/misspell/issues/99. In the meantime adding
# adres to the ignore list.
@echo "==> Running static validations"
@gometalinter.v1 \
--disable-all \
--linter "misspell:misspell -i adres -j 1 {path}/*.go:PATH:LINE:COL:MESSAGE" \
--enable deadcode \
--severity deadcode:error \
--enable gofmt \
--enable gosimple \
--enable ineffassign \
--enable misspell \
--enable vet \
--tests \
--vendor \
--deadline 60s \
./... || exit_code=1

.PHONY: lint
lint:
@echo "==> Running linters"
@gometalinter.v1 \
--disable-all \
--enable golint \
--vendor \
--deadline 60s \
./... || :
20 changes: 5 additions & 15 deletions bzr.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewBzrRepo(remote, local string) (*BzrRepo, error) {
// http://bazaar.launchpad.net/~mattfarina/govcstestbzrrepo/trunk/. Notice
// the change from https to http and the path chance.
// Here we set the remote to be the local one if none is passed in.
if err == nil && r.CheckLocal() == true && remote == "" {
if err == nil && r.CheckLocal() && remote == "" {
c := exec.Command("bzr", "info")
c.Dir = local
c.Env = envForDir(c.Dir)
Expand Down Expand Up @@ -226,11 +226,7 @@ func (s *BzrRepo) Tags() ([]string, error) {
// commit id or tag.
func (s *BzrRepo) IsReference(r string) bool {
_, err := s.RunFromDir("bzr", "revno", "-r", r)
if err == nil {
return true
}

return false
return err == nil
}

// IsDirty returns if the checkout has been modified from the checked
Expand Down Expand Up @@ -308,21 +304,14 @@ func (s *BzrRepo) Ping() bool {
// an error is returned. Launchpad returns a 404 for a codebase that
// does not exist. Otherwise it returns a JSON object describing it.
_, er := get("https://api.launchpad.net/1.0/" + try)
if er == nil {
return true
}
return false
return er == nil
}
}

// This is the same command that Go itself uses but it's not fast (or fast
// enough by my standards). A faster method would be useful.
_, err = s.run("bzr", "info", s.Remote())
if err != nil {
return false
}

return true
return err == nil
}

// ExportDir exports the current revision to the passed in directory.
Expand All @@ -340,6 +329,7 @@ func (s *BzrRepo) ExportDir(dir string) error {
// https://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/files/head:/po/
func (s *BzrRepo) isUnableToCreateDir(err error) bool {
msg := err.Error()

if strings.HasPrefix(msg, fmt.Sprintf("Parent directory of %s does not exist.", s.LocalPath())) ||
strings.HasPrefix(msg, fmt.Sprintf("Nadřazený adresář %s neexistuje.", s.LocalPath())) ||
strings.HasPrefix(msg, fmt.Sprintf("El directorio padre de %s no existe.", s.LocalPath())) ||
Expand Down
16 changes: 8 additions & 8 deletions bzr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestBzr(t *testing.T) {
}

// Verify Bzr repo is a Bzr repo
if repo.CheckLocal() == false {
if !repo.CheckLocal() {
t.Error("Problem checking out repo or Bzr CheckLocal is not working")
}

Expand All @@ -75,7 +75,7 @@ func TestBzr(t *testing.T) {
t.Error(nrerr)
}
// Verify the right oject is returned. It will check the local repo type.
if nrepo.CheckLocal() == false {
if !nrepo.CheckLocal() {
t.Error("Wrong version returned from NewRepo")
}

Expand Down Expand Up @@ -164,15 +164,15 @@ func TestBzr(t *testing.T) {
t.Error("Bzr is incorrectly returning branches")
}

if repo.IsReference("1.0.0") != true {
if !repo.IsReference("1.0.0") {
t.Error("Bzr is reporting a reference is not one")
}

if repo.IsReference("foo") == true {
t.Error("Bzr is reporting a non-existant reference is one")
if repo.IsReference("foo") {
t.Error("Bzr is reporting a non-existent reference is one")
}

if repo.IsDirty() == true {
if repo.IsDirty() {
t.Error("Bzr incorrectly reporting dirty")
}

Expand Down Expand Up @@ -227,7 +227,7 @@ func TestBzr(t *testing.T) {

_, err = os.Stat(filepath.Join(exportDir, string(repo.Vcs())))
if err != nil {
if found := os.IsNotExist(err); found == false {
if found := os.IsNotExist(err); !found {
t.Errorf("Error checking exported metadata in Bzr: %s", err)
}
} else {
Expand All @@ -250,7 +250,7 @@ func TestBzrCheckLocal(t *testing.T) {
}()

repo, _ := NewBzrRepo("", tempDir)
if repo.CheckLocal() == true {
if repo.CheckLocal() {
t.Error("Bzr CheckLocal does not identify non-Bzr location")
}

Expand Down
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "errors"
// The vcs package provides ways to work with errors that hide the underlying
// implementation details but make them accessible if needed. For basic errors
// that do not have underlying implementation specific details or the underlying
// details are likely not necessairy there are errors for comparison.
// details are not necessary there are errors for comparison.
//
// For example:
//
Expand Down
16 changes: 4 additions & 12 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewGitRepo(remote, local string) (*GitRepo, error) {

// Make sure the local Git repo is configured the same as the remote when
// A remote value was passed in.
if err == nil && r.CheckLocal() == true {
if err == nil && r.CheckLocal() {
c := exec.Command("git", "config", "--get", "remote.origin.url")
c.Dir = local
c.Env = envForDir(c.Dir)
Expand Down Expand Up @@ -143,7 +143,7 @@ func (s *GitRepo) Update() error {
return NewLocalError("Unable to update repository", err, "")
}

if detached == true {
if detached {
return nil
}

Expand Down Expand Up @@ -280,11 +280,7 @@ func (s *GitRepo) IsReference(r string) bool {
// not been checked out yet. This next step should pickup the other
// possible references.
_, err = s.RunFromDir("git", "show-ref", r)
if err == nil {
return true
}

return false
return err == nil
}

// IsDirty returns if the checkout has been modified from the checked
Expand Down Expand Up @@ -364,11 +360,7 @@ func (s *GitRepo) Ping() bool {
// remote needs to be different.
c.Env = mergeEnvLists([]string{"GIT_TERMINAL_PROMPT=0"}, os.Environ())
_, err := c.CombinedOutput()
if err != nil {
return false
}

return true
return err == nil
}

// ExportDir exports the current revision to the passed in directory.
Expand Down
16 changes: 8 additions & 8 deletions git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestGit(t *testing.T) {
}

// Verify Git repo is a Git repo
if repo.CheckLocal() == false {
if !repo.CheckLocal() {
t.Error("Problem checking out repo or Git CheckLocal is not working")
}

Expand All @@ -74,7 +74,7 @@ func TestGit(t *testing.T) {
t.Error(nrerr)
}
// Verify the right oject is returned. It will check the local repo type.
if nrepo.CheckLocal() == false {
if !nrepo.CheckLocal() {
t.Error("Wrong version returned from NewRepo")
}

Expand Down Expand Up @@ -198,15 +198,15 @@ func TestGit(t *testing.T) {
t.Error("Git is incorrectly returning branches")
}

if repo.IsReference("1.0.0") != true {
if !repo.IsReference("1.0.0") {
t.Error("Git is reporting a reference is not one")
}

if repo.IsReference("foo") == true {
t.Error("Git is reporting a non-existant reference is one")
if repo.IsReference("foo") {
t.Error("Git is reporting a non-existent reference is one")
}

if repo.IsDirty() == true {
if repo.IsDirty() {
t.Error("Git incorrectly reporting dirty")
}

Expand Down Expand Up @@ -261,7 +261,7 @@ func TestGit(t *testing.T) {

_, err = os.Stat(filepath.Join(exportDir, string(repo.Vcs())))
if err != nil {
if found := os.IsNotExist(err); found == false {
if found := os.IsNotExist(err); !found {
t.Errorf("Error checking exported metadata in Git: %s", err)
}
} else {
Expand All @@ -284,7 +284,7 @@ func TestGitCheckLocal(t *testing.T) {
}()

repo, _ := NewGitRepo("", tempDir)
if repo.CheckLocal() == true {
if repo.CheckLocal() {
t.Error("Git CheckLocal does not identify non-Git location")
}

Expand Down
14 changes: 3 additions & 11 deletions hg.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewHgRepo(remote, local string) (*HgRepo, error) {

// Make sure the local Hg repo is configured the same as the remote when
// A remote value was passed in.
if err == nil && r.CheckLocal() == true {
if err == nil && r.CheckLocal() {
// An Hg repo was found so test that the URL there matches
// the repo passed in here.
c := exec.Command("hg", "paths")
Expand Down Expand Up @@ -207,11 +207,7 @@ func (s *HgRepo) Tags() ([]string, error) {
// commit id, branch, or tag.
func (s *HgRepo) IsReference(r string) bool {
_, err := s.RunFromDir("hg", "log", "-r", r)
if err == nil {
return true
}

return false
return err == nil
}

// IsDirty returns if the checkout has been modified from the checked
Expand Down Expand Up @@ -305,11 +301,7 @@ func (s *HgRepo) TagsFromCommit(id string) ([]string, error) {
// Ping returns if remote location is accessible.
func (s *HgRepo) Ping() bool {
_, err := s.run("hg", "identify", s.Remote())
if err != nil {
return false
}

return true
return err == nil
}

// ExportDir exports the current revision to the passed in directory.
Expand Down
18 changes: 9 additions & 9 deletions hg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestHg(t *testing.T) {
}

// Verify Hg repo is a Hg repo
if repo.CheckLocal() == false {
if !repo.CheckLocal() {
t.Error("Problem checking out repo or Hg CheckLocal is not working")
}

Expand All @@ -75,7 +75,7 @@ func TestHg(t *testing.T) {
t.Error(nrerr)
}
// Verify the right oject is returned. It will check the local repo type.
if nrepo.CheckLocal() == false {
if !nrepo.CheckLocal() {
t.Error("Wrong version returned from NewRepo")
}

Expand Down Expand Up @@ -166,19 +166,19 @@ func TestHg(t *testing.T) {
t.Error("Hg is incorrectly returning branches")
}

if repo.IsReference("1.0.0") != true {
if !repo.IsReference("1.0.0") {
t.Error("Hg is reporting a reference is not one")
}

if repo.IsReference("test") != true {
if !repo.IsReference("test") {
t.Error("Hg is reporting a reference is not one")
}

if repo.IsReference("foo") == true {
t.Error("Hg is reporting a non-existant reference is one")
if repo.IsReference("foo") {
t.Error("Hg is reporting a non-existent reference is one")
}

if repo.IsDirty() == true {
if repo.IsDirty() {
t.Error("Hg incorrectly reporting dirty")
}

Expand Down Expand Up @@ -231,7 +231,7 @@ func TestHg(t *testing.T) {

_, err = os.Stat(filepath.Join(exportDir, string(repo.Vcs())))
if err != nil {
if found := os.IsNotExist(err); found == false {
if found := os.IsNotExist(err); !found {
t.Errorf("Error checking exported metadata in Hg: %s", err)
}
} else {
Expand All @@ -254,7 +254,7 @@ func TestHgCheckLocal(t *testing.T) {
}()

repo, _ := NewHgRepo("", tempDir)
if repo.CheckLocal() == true {
if repo.CheckLocal() {
t.Error("Hg CheckLocal does not identify non-Hg location")
}

Expand Down
4 changes: 2 additions & 2 deletions repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func TestTypeSwitch(t *testing.T) {

func TestDepInstalled(t *testing.T) {
i := depInstalled("git")
if i != true {
if !i {
t.Error("depInstalled not finding installed dep.")
}

i = depInstalled("thisreallyisntinstalled")
if i != false {
if i {
t.Error("depInstalled finding not installed dep.")
}
}
Loading

0 comments on commit 95aab3c

Please sign in to comment.