Skip to content

Commit 9152721

Browse files
eyakubovichjrperritt
authored andcommitted
Always set error on response in token create (gophercloud#109) (gophercloud#92)
If there was a network error, http response will be nil but error needs to be propogated out.
1 parent c5d17b8 commit 9152721

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

openstack/identity/v3/tokens/requests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ func Create(c *gophercloud.ServiceClient, opts AuthOptionsBuilder) (r CreateResu
158158
resp, err := c.Post(tokenURL(c), b, &r.Body, &gophercloud.RequestOpts{
159159
MoreHeaders: map[string]string{"X-Auth-Token": ""},
160160
})
161+
r.Err = err
161162
if resp != nil {
162-
r.Err = err
163163
r.Header = resp.Header
164164
}
165165
return

openstack/testing/client_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestAuthenticatedClientV3(t *testing.T) {
5252
Username: "me",
5353
Password: "secret",
5454
DomainName: "default",
55-
TenantName: "project",
55+
TenantName: "project",
5656
IdentityEndpoint: th.Endpoint(),
5757
}
5858
client, err := openstack.AuthenticatedClient(options)
@@ -291,3 +291,25 @@ func TestIdentityAdminV3Client(t *testing.T) {
291291
th.AssertNoErr(t, err)
292292
th.CheckEquals(t, "http://localhost:35357/", sc.Endpoint)
293293
}
294+
295+
func testAuthenticatedClientFails(t *testing.T, endpoint string) {
296+
options := gophercloud.AuthOptions{
297+
Username: "me",
298+
Password: "secret",
299+
DomainName: "default",
300+
TenantName: "project",
301+
IdentityEndpoint: endpoint,
302+
}
303+
_, err := openstack.AuthenticatedClient(options)
304+
if err == nil {
305+
t.Fatal("expected error but call succeeded")
306+
}
307+
}
308+
309+
func TestAuthenticatedClientV3Fails(t *testing.T) {
310+
testAuthenticatedClientFails(t, "http://bad-address.example.com/v3")
311+
}
312+
313+
func TestAuthenticatedClientV2Fails(t *testing.T) {
314+
testAuthenticatedClientFails(t, "http://bad-address.example.com/v2.0")
315+
}

0 commit comments

Comments
 (0)