Skip to content

Commit

Permalink
add a unit test of FindRemotes function
Browse files Browse the repository at this point in the history
  • Loading branch information
tamada committed May 17, 2019
1 parent 5d43e71 commit c0dd8f7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
[submodule "testdata/helloworld2"]
path = testdata/other/helloworld
url = https://htamada@bitbucket.org/htamada/helloworld2.git
[submodule "docs/themes/hugo-theme-massively"]
path = docs/themes/hugo-theme-massively
url = https://github.com/curtistimson/hugo-theme-massively.git
[submodule "docs/themes/cayman-hugo-theme"]
path = docs/themes/cayman-hugo-theme
url = https://github.com/zwbetz-gh/cayman-hugo-theme.git
4 changes: 2 additions & 2 deletions add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func (add *Command) AddRepositoriesToGroup(db *common.Database, opt *options) []
FindRemotes function returns the remote of the given git repository.
*/
func FindRemotes(path string) ([]common.Remote, error) {
r, err := git.PlainOpen(path)
var repo, err = git.PlainOpen(path)
if err != nil {
return nil, err
}
remotes, err := r.Remotes()
remotes, err := repo.Remotes()
if err != nil {
return nil, err
}
Expand Down
19 changes: 19 additions & 0 deletions add/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,22 @@ func TestAddFailed(t *testing.T) {
}
}
}

func TestFindRemotes(t *testing.T) {
var testdata = []struct {
path string
errorFlag bool
count int
}{
{"../testdata/dummygit", true, 0},
}
for _, td := range testdata {
var remotes, err = FindRemotes(td.path)
if (err == nil) == td.errorFlag {
t.Errorf("%s: error flag did not match, wont: %v, got: %v, %v", td.path, td.errorFlag, !td.errorFlag, err)
}
if err != nil && td.count != len(remotes) {
t.Errorf("%s: remote count did not match, wont: %d, got: %d", td.path, td.count, len(remotes))
}
}
}
1 change: 1 addition & 0 deletions testdata/dummygit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is dummy!

0 comments on commit c0dd8f7

Please sign in to comment.