Skip to content

Commit

Permalink
Merge pull request Masterminds#34 from Masterminds/fix/33
Browse files Browse the repository at this point in the history
Fixed Masterminds#33: xml parsing errors were returned from lookups
  • Loading branch information
mattfarina committed Apr 27, 2016
2 parents c92afd1 + 519b965 commit 56971a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions vcs_remote_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ func detectVcsFromRemote(vcsURL string) (Type, string, error) {
return t, vcsURL, nil
}

// Need to test for vanity or paths like golang.org/x/

// TODO: Test for 3xx redirect codes and handle appropriately.

// Pages like https://golang.org/x/net provide an html document with
// meta tags containing a location to work with. The go tool uses
// a meta tag with the name go-import which is what we use here.
Expand All @@ -117,10 +113,14 @@ func detectVcsFromRemote(vcsURL string) (Type, string, error) {
return NoVCS, "", ErrCannotDetectVCS
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return NoVCS, "", ErrCannotDetectVCS
}

t, nu, err := parseImportFromBody(u, resp.Body)
if err != nil {
return NoVCS, "", err
// TODO(mattfarina): Log the parsing error
return NoVCS, "", ErrCannotDetectVCS
} else if t == "" || nu == "" {
return NoVCS, "", ErrCannotDetectVCS
}
Expand Down Expand Up @@ -299,6 +299,7 @@ func get(url string) ([]byte, error) {
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
// TODO(mattfarina): log the failed status
return nil, fmt.Errorf("%s: %s", url, resp.Status)
}
b, err := ioutil.ReadAll(resp.Body)
Expand Down
6 changes: 6 additions & 0 deletions vcs_remote_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ func TestVCSLookup(t *testing.T) {
"https://github.com/masterminds": {work: false, t: Git},
"https://github.com/Masterminds/VCSTestRepo": {work: true, t: Git},
"https://bitbucket.org/mattfarina/testhgrepo": {work: true, t: Hg},
"https://bitbucket.org/mattfarina/repo-does-not-exist": {work: false, t: Hg},
"https://bitbucket.org/mattfarina/private-repo-for-vcs-testing": {work: false, t: Hg},
"https://launchpad.net/govcstestbzrrepo/trunk": {work: true, t: Bzr},
"https://launchpad.net/~mattfarina/+junk/mygovcstestbzrrepo": {work: true, t: Bzr},
"https://launchpad.net/~mattfarina/+junk/mygovcstestbzrrepo/trunk": {work: true, t: Bzr},
Expand Down Expand Up @@ -56,6 +58,10 @@ func TestVCSLookup(t *testing.T) {
t.Errorf("Error detecting VCS from URL(%s): %s", u, err)
}

if err != nil && err != ErrCannotDetectVCS && c.work == false {
t.Errorf("Unexpected error returned (%s): %s", u, err)
}

if c.work == true && ty != c.t {
t.Errorf("Incorrect VCS type returned(%s)", u)
}
Expand Down

0 comments on commit 56971a5

Please sign in to comment.