ChooseVersion accounts for missing /s.
diff --git a/openstack/utils/choose_version.go b/openstack/utils/choose_version.go
index 088e086..57e2a81 100644
--- a/openstack/utils/choose_version.go
+++ b/openstack/utils/choose_version.go
@@ -69,6 +69,13 @@
var highest *Version
var endpoint string
+ normalize := func(endpoint string) string {
+ if !strings.HasSuffix(endpoint, "/") {
+ return endpoint + "/"
+ }
+ return endpoint
+ }
+
for _, value := range resp.Versions.Values {
href := ""
for _, link := range value.Links {
@@ -79,7 +86,7 @@
if matching, ok := byID[value.ID]; ok {
// Prefer a version that exactly matches the provided endpoint.
- if href == identityEndpoint {
+ if normalize(href) == normalize(identityEndpoint) {
if href == "" {
return nil, "", fmt.Errorf("Endpoint missing in version %s response from %s", value.ID, normalized)
}
diff --git a/openstack/utils/choose_version_test.go b/openstack/utils/choose_version_test.go
index d2aec8a..4a8a443 100644
--- a/openstack/utils/choose_version_test.go
+++ b/openstack/utils/choose_version_test.go
@@ -67,7 +67,7 @@
v2 := &Version{ID: "v2.0", Priority: 2}
v3 := &Version{ID: "v3.0", Priority: 3}
- v, endpoint, err := ChooseVersion(testhelper.Endpoint()+"v2.0", []*Version{v2, v3})
+ v, endpoint, err := ChooseVersion(testhelper.Endpoint()+"v2.0/", []*Version{v2, v3})
if err != nil {
t.Fatalf("Unexpected error from ChooseVersion: %v", err)
}