ChooseVersion prefers exact URL matches now.
diff --git a/openstack/utils/choose_version_test.go b/openstack/utils/choose_version_test.go
index a252790..d2aec8a 100644
--- a/openstack/utils/choose_version_test.go
+++ b/openstack/utils/choose_version_test.go
@@ -8,34 +8,37 @@
"github.com/rackspace/gophercloud/testhelper"
)
+func setupVersionHandler() {
+ testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ fmt.Fprintf(w, `
+ {
+ "versions": {
+ "values": [
+ {
+ "status": "stable",
+ "id": "v3.0",
+ "links": [
+ { "href": "%s/v3.0", "rel": "self" }
+ ]
+ },
+ {
+ "status": "stable",
+ "id": "v2.0",
+ "links": [
+ { "href": "%s/v2.0", "rel": "self" }
+ ]
+ }
+ ]
+ }
+ }
+ `, testhelper.Server.URL, testhelper.Server.URL)
+ })
+}
+
func TestChooseVersion(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
-
- testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- fmt.Fprintf(w, `
- {
- "versions": {
- "values": [
- {
- "status": "stable",
- "id": "v3.0",
- "links": [
- { "href": "https://example.com:1000/", "rel": "self" }
- ]
- },
- {
- "status": "stable",
- "id": "v2.0",
- "links": [
- { "href": "https://example.com:2000/", "rel": "self" }
- ]
- }
- ]
- }
- }
- `)
- })
+ setupVersionHandler()
v2 := &Version{ID: "v2.0", Priority: 2}
v3 := &Version{ID: "v3.0", Priority: 3}
@@ -50,7 +53,30 @@
t.Errorf("Expected %#v to win, but %#v did instead", v3, v)
}
- expected := "https://example.com:1000/"
+ expected := testhelper.Endpoint() + "v3.0"
+ if endpoint != expected {
+ t.Errorf("Expected endpoint [%s], but was [%s] instead", expected, endpoint)
+ }
+}
+
+func TestChooseVersionOpinionatedLink(t *testing.T) {
+ testhelper.SetupHTTP()
+ defer testhelper.TeardownHTTP()
+ setupVersionHandler()
+
+ 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})
+ 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)
}