remove extra slash from registry urls

A refactor introduced an extra `/` in the download url, which causes an
extra redirect during discovery.

Improve a registry test to verify that detection doesn't require the
registry after the modules have been fetched.
This commit is contained in:
James Bardin 2017-09-28 14:45:02 -04:00
parent 7a2af23d25
commit 1fbb2d611a
2 changed files with 16 additions and 4 deletions

View File

@ -79,7 +79,7 @@ func getStorage(s getter.Storage, key string, src string, mode GetMode) (string,
} }
const ( const (
registryAPI = "https://registry.terraform.io/v1/modules/" registryAPI = "https://registry.terraform.io/v1/modules"
xTerraformGet = "X-Terraform-Get" xTerraformGet = "X-Terraform-Get"
) )

View File

@ -102,7 +102,7 @@ func TestDetectRegistry(t *testing.T) {
defer server.Close() defer server.Close()
detector := registryDetector{ detector := registryDetector{
api: server.URL + "/v1/modules/", api: server.URL + "/v1/modules",
client: server.Client(), client: server.Client(),
} }
@ -181,7 +181,7 @@ func TestDetectors(t *testing.T) {
} }
regDetector := &registryDetector{ regDetector := &registryDetector{
api: server.URL + "/v1/modules/", api: server.URL + "/v1/modules",
client: server.Client(), client: server.Client(),
} }
@ -280,7 +280,7 @@ func TestRegistryGitHubArchive(t *testing.T) {
defer server.Close() defer server.Close()
regDetector := &registryDetector{ regDetector := &registryDetector{
api: server.URL + "/v1/modules/", api: server.URL + "/v1/modules",
client: server.Client(), client: server.Client(),
} }
@ -312,6 +312,18 @@ func TestRegistryGitHubArchive(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
// stop the registry server, and make sure that we don't need to call out again
server.Close()
tree = NewTree("", testConfig(t, "registry-tar-subdir"))
if err := tree.Load(storage, GetModeGet); err != nil {
t.Fatalf("err: %s", err)
}
if !tree.Loaded() {
t.Fatal("should be loaded")
}
actual := strings.TrimSpace(tree.String()) actual := strings.TrimSpace(tree.String())
expected := strings.TrimSpace(treeLoadSubdirStr) expected := strings.TrimSpace(treeLoadSubdirStr)
if actual != expected { if actual != expected {