Skip to content

Commit a70376e

Browse files
committed
do dynamic lookup of Repo source for custom imports.
Fixes Masterminds/glide-report#6. Added unit tests for Remote() function with packages that require dynamic resolution.
1 parent 3e13fd1 commit a70376e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

cfg/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ func (d *Dependency) Remote() string {
469469
r = d.Repository
470470
} else {
471471
r = "https://" + d.Name
472+
repo, err := vcs.NewRepo("https://"+d.Name, "")
473+
// TODO: change the function signature and return the error (?)
474+
if err == nil {
475+
r = repo.Remote()
476+
}
472477
}
473478

474479
f, nr, _ := mirrors.Get(r)

cfg/config_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import:
3636
- package: github.com/Masterminds/structable
3737
- package: github.com/Masterminds/cookoo/color
3838
- package: github.com/Masterminds/cookoo/convert
39+
- package: golang.org/x/crypto
3940
4041
testImport:
4142
- package: github.com/kylelemons/go-gypsy
@@ -176,3 +177,21 @@ func TestOwners(t *testing.T) {
176177
t.Error("Unable to parse owners from yaml")
177178
}
178179
}
180+
181+
func TestRemote(t *testing.T) {
182+
tests := []struct {
183+
name string
184+
remote string
185+
}{
186+
{"golang.org/x/crypto", "https://go.googlesource.com/crypto"},
187+
{"gopkg.in/yaml.v2", "https://gopkg.in/yaml.v2"},
188+
{"github.com/Masterminds/glide", "https://github.com/Masterminds/glide"},
189+
}
190+
for _, tt := range tests {
191+
d := Dependency{Name: tt.name}
192+
r := d.Remote()
193+
if r != tt.remote {
194+
t.Errorf("Bad remote - want %s, got %s", tt.remote, r)
195+
}
196+
}
197+
}

0 commit comments

Comments
 (0)