Ookay, last reshuffle.
* openstack.NewClient() normalizes the identity endpoint with a trailing slash, and sets base and endpoint.
* utils.ChooseVersion() checks suffixes first to short-circuit actual version calls.
* gophercloud.ProviderClient distinguishes between the root of all identity services (IdentityBase)
and the endpoint of the requested auth service (IdentityEndpoint).
diff --git a/openstack/utils/choose_version_test.go b/openstack/utils/choose_version_test.go
index b724ee8..9552696 100644
--- a/openstack/utils/choose_version_test.go
+++ b/openstack/utils/choose_version_test.go
@@ -40,10 +40,10 @@
defer testhelper.TeardownHTTP()
setupVersionHandler()
- v2 := &Version{ID: "v2.0", Priority: 2}
- v3 := &Version{ID: "v3.0", Priority: 3}
+ v2 := &Version{ID: "v2.0", Priority: 2, Suffix: "blarg"}
+ v3 := &Version{ID: "v3.0", Priority: 3, Suffix: "hargl"}
- v, endpoint, err := ChooseVersion(testhelper.Endpoint(), []*Version{v2, v3})
+ v, endpoint, err := ChooseVersion(testhelper.Endpoint(), "", []*Version{v2, v3})
if err != nil {
t.Fatalf("Unexpected error from ChooseVersion: %v", err)
@@ -64,10 +64,32 @@
defer testhelper.TeardownHTTP()
setupVersionHandler()
- v2 := &Version{ID: "v2.0", Priority: 2}
- v3 := &Version{ID: "v3.0", Priority: 3}
+ v2 := &Version{ID: "v2.0", Priority: 2, Suffix: "nope"}
+ v3 := &Version{ID: "v3.0", Priority: 3, Suffix: "northis"}
- v, endpoint, err := ChooseVersion(testhelper.Endpoint()+"v2.0/", []*Version{v2, v3})
+ v, endpoint, err := ChooseVersion(testhelper.Endpoint(), testhelper.Endpoint()+"v2.0/", []*Version{v2, v3})
+ if err != nil {
+ t.Fatalf("Unexpected error from ChooseVersion: %v", err)
+ }
+
+ if v != v2 {
+ t.Errorf("Expected %#v to win, but %#v did instead", v2, v)
+ }
+
+ expected := testhelper.Endpoint() + "v2.0/"
+ if endpoint != expected {
+ t.Errorf("Expected endpoint [%s], but was [%s] instead", expected, endpoint)
+ }
+}
+
+func TestChooseVersionFromSuffix(t *testing.T) {
+ testhelper.SetupHTTP()
+ defer testhelper.TeardownHTTP()
+
+ v2 := &Version{ID: "v2.0", Priority: 2, Suffix: "/v2.0/"}
+ v3 := &Version{ID: "v3.0", Priority: 3, Suffix: "/v3.0/"}
+
+ v, endpoint, err := ChooseVersion(testhelper.Endpoint(), testhelper.Endpoint()+"v2.0/", []*Version{v2, v3})
if err != nil {
t.Fatalf("Unexpected error from ChooseVersion: %v", err)
}