diff --git a/go/vcs/discovery.go b/go/vcs/discovery.go index d5c3fc6b..c4b0e3d1 100644 --- a/go/vcs/discovery.go +++ b/go/vcs/discovery.go @@ -36,6 +36,9 @@ func parseMetaGoImports(r io.Reader) (imports []metaImport, err error) { for { t, err = d.Token() if err != nil { + if err == io.EOF { + err = nil + } return } if e, ok := t.(xml.StartElement); ok && strings.EqualFold(e.Name.Local, "body") { diff --git a/go/vcs/vcs_test.go b/go/vcs/vcs_test.go index 0b8dd8c8..226a3e41 100644 --- a/go/vcs/vcs_test.go +++ b/go/vcs/vcs_test.go @@ -8,6 +8,8 @@ import ( "io/ioutil" "os" "path/filepath" + "reflect" + "strings" "testing" ) @@ -84,3 +86,45 @@ func TestFromDir(t *testing.T) { os.RemoveAll(test.path) } } + +var parseMetaGoImportsTests = []struct { + in string + out []metaImport +}{ + { + ``, + []metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}}, + }, + { + ` + `, + []metaImport{ + {"foo/bar", "git", "https://github.com/rsc/foo/bar"}, + {"baz/quux", "git", "http://github.com/rsc/baz/quux"}, + }, + }, + { + ` + + `, + []metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}}, + }, + { + ` + `, + []metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}}, + }, +} + +func TestParseMetaGoImports(t *testing.T) { + for i, tt := range parseMetaGoImportsTests { + out, err := parseMetaGoImports(strings.NewReader(tt.in)) + if err != nil { + t.Errorf("test#%d: %v", i, err) + continue + } + if !reflect.DeepEqual(out, tt.out) { + t.Errorf("test#%d:\n\thave %q\n\twant %q", i, out, tt.out) + } + } +}