Skip to content

Commit

Permalink
do dynamic lookup of Repo source for custom imports.
Browse files Browse the repository at this point in the history
Fixes Masterminds/glide-report#6.
Added unit tests for Remote() function with packages
that require dynamic resolution.
  • Loading branch information
dmitris committed Aug 13, 2018
1 parent 3e13fd1 commit a70376e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,11 @@ func (d *Dependency) Remote() string {
r = d.Repository
} else {
r = "https://" + d.Name
repo, err := vcs.NewRepo("https://"+d.Name, "")
// TODO: change the function signature and return the error (?)
if err == nil {
r = repo.Remote()
}
}

f, nr, _ := mirrors.Get(r)
Expand Down
19 changes: 19 additions & 0 deletions cfg/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import:
- package: github.com/Masterminds/structable
- package: github.com/Masterminds/cookoo/color
- package: github.com/Masterminds/cookoo/convert
- package: golang.org/x/crypto
testImport:
- package: github.com/kylelemons/go-gypsy
Expand Down Expand Up @@ -176,3 +177,21 @@ func TestOwners(t *testing.T) {
t.Error("Unable to parse owners from yaml")
}
}

func TestRemote(t *testing.T) {
tests := []struct {
name string
remote string
}{
{"golang.org/x/crypto", "https://go.googlesource.com/crypto"},
{"gopkg.in/yaml.v2", "https://gopkg.in/yaml.v2"},
{"github.com/Masterminds/glide", "https://github.com/Masterminds/glide"},
}
for _, tt := range tests {
d := Dependency{Name: tt.name}
r := d.Remote()
if r != tt.remote {
t.Errorf("Bad remote - want %s, got %s", tt.remote, r)
}
}
}

0 comments on commit a70376e

Please sign in to comment.