Skip to content

Commit

Permalink
Merge pull request #140 from carolynvs/fix-v3-token-conn-error
Browse files Browse the repository at this point in the history
Properly bubble up connection errors
  • Loading branch information
carolynvs authored Feb 8, 2017
2 parents a691287 + 59c49c0 commit 2b3ec26
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
7 changes: 4 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import:
repo: https://github.com/getcarina/libcarina.git
vcs: git
- package: github.com/gophercloud/gophercloud
version: magnum
version: preserve-token-conn-error
repo: https://github.com/carolynvs/gophercloud.git
vcs: git
subpackages:
- openstack
Expand Down
65 changes: 65 additions & 0 deletions magnum/account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package magnum

import (
"fmt"
"net/http"
"net/http/httptest"
"testing"

"github.com/getcarina/carina/common"
"github.com/stretchr/testify/assert"
)

const identityAPIVersion = "/v3/"

type handler func(w http.ResponseWriter, r *http.Request)

func identityHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")

switch r.RequestURI {
case identityAPIVersion + "/tokens":
fmt.Fprintln(w, `{"access":{"serviceCatalog":[{"endpoints":[{"tenantId":"963451","publicURL":"https:\/\/example.com:9511","region":"RegionOne"}],"name":"cloudContainer","type":"container-infra"}],"user":{"name":"fake-user","id":"fake-userid"},"token":{"expires":"3000-01-01T12:00:00Z","id":"fake-token","tenant":{"name":"fake-tenantname","id":"fake-tenantid"}}}}`)
default:
w.WriteHeader(404)
fmt.Fprintln(w, "unexpected request: "+r.RequestURI)
}
}

func createMockCarina(h handler) (*httptest.Server, *httptest.Server) {
return httptest.NewServer(http.HandlerFunc(h)), httptest.NewServer(http.HandlerFunc(identityHandler))
}

func createMagnumService(identityServer *httptest.Server, carinaServer *httptest.Server) *Magnum {
acct := &Account{
AuthEndpoint: identityServer.URL + identityAPIVersion,
EndpointOverride: carinaServer.URL,
UserName: "fake-user",
Password: "fake-password",
Domain: "Default",
Project: "Default",
Region: "RegionOne",
}

return &Magnum{Account: acct}
}

func TestGopherCloudIdentityV3ErrorHandlingWorkaround(t *testing.T) {
common.Log.RegisterTestLogger(t)

acct := &Account{
AuthEndpoint: "bork://example.com" + identityAPIVersion,
UserName: "fake-user",
Password: "fake-password",
Domain: "Default",
Project: "Default",
Region: "RegionOne",
}

svc := &Magnum{Account: acct}

_, err := svc.ListClusters()

assert.NotNil(t, err)
assert.Contains(t, err.Error(), "unsupported protocol scheme")
}

0 comments on commit 2b3ec26

Please sign in to comment.