diff --git a/registry/client.go b/registry/client.go index 06e54a27f..b4cd7989f 100644 --- a/registry/client.go +++ b/registry/client.go @@ -66,7 +66,11 @@ func NewClient(services *disco.Disco, creds auth.CredentialsSource, client *http // Discover qeuries the host, and returns the url for the registry. func (c *Client) Discover(host svchost.Hostname) *url.URL { - return c.services.DiscoverServiceURL(host, serviceID) + service := c.services.DiscoverServiceURL(host, serviceID) + if !strings.HasSuffix(service.Path, "/") { + service.Path += "/" + } + return service } // Versions queries the registry for a module, and returns the available versions. @@ -80,9 +84,6 @@ func (c *Client) Versions(module *regsrc.Module) (*response.ModuleVersions, erro if service == nil { return nil, fmt.Errorf("host %s does not provide Terraform modules", host) } - if !strings.HasSuffix(service.Path, "/") { - service.Path += "/" - } p, err := url.Parse(path.Join(module.Module(), "versions")) if err != nil { diff --git a/registry/test/mock_registry.go b/registry/test/mock_registry.go index 844f569c6..c1fabbc25 100644 --- a/registry/test/mock_registry.go +++ b/registry/test/mock_registry.go @@ -23,7 +23,9 @@ import ( // localhost.localdomain, and example.com to the test server. func Disco(s *httptest.Server) *disco.Disco { services := map[string]interface{}{ - "modules.v1": fmt.Sprintf("%s/v1/modules/", s.URL), + // Note that both with and without trailing slashes are supported behaviours + // TODO: add specific tests to enumerate both possibilities. + "modules.v1": fmt.Sprintf("%s/v1/modules", s.URL), } d := disco.NewDisco()