change all time fields to have type time.Time (#190)
* add Volume.Unmarshal
* add volumetenants.VolumeExt.Unmarshal
* create servers.Server time.Time fields
* json.Unmarshal can correctly handle time.RFC3339 (Server time fields)
* add v3 Token UnmarshalJSON method
* check for empty string when unmarshaling time
* add Member UnmarshalJSON
* v3 tokens.Token ExtractInto
* v3 trust.Trust UnmarshalJSON
* time.Time fields swift response objects
* time.Time fields for orchestration response objects
* time.Time fields for shared file systems response objects
* if we don't use pointers for the custom time fields, we don't need to check if they're nil
* style guide fixes: 'r' for receiver, 's' for struct
* remove unnecessary pointers from UnmarshalJSON methods
diff --git a/openstack/identity/v3/extensions/trusts/results.go b/openstack/identity/v3/extensions/trusts/results.go
index 3d3c7f2..bdd8e84 100644
--- a/openstack/identity/v3/extensions/trusts/results.go
+++ b/openstack/identity/v3/extensions/trusts/results.go
@@ -1,7 +1,5 @@
package trusts
-import "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
-
type TrusteeUser struct {
ID string `json:"id"`
}
@@ -19,11 +17,6 @@
RedelegationCount int `json:"redelegation_count"`
}
-type Token struct {
- tokens.Token
- Trust Trust `json:"OS-TRUST:trust"`
-}
-
type TokenExt struct {
- Token Token `json:"token"`
+ Trust Trust `json:"OS-TRUST:trust"`
}
diff --git a/openstack/identity/v3/extensions/trusts/testing/fixtures.go b/openstack/identity/v3/extensions/trusts/testing/fixtures.go
index b4106a3..e311526 100644
--- a/openstack/identity/v3/extensions/trusts/testing/fixtures.go
+++ b/openstack/identity/v3/extensions/trusts/testing/fixtures.go
@@ -4,24 +4,13 @@
"fmt"
"net/http"
"testing"
- "time"
- "github.com/gophercloud/gophercloud"
- "github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts"
"github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
"github.com/gophercloud/gophercloud/testhelper"
)
// HandleCreateTokenWithTrustID verifies that providing certain AuthOptions and Scope results in an expected JSON structure.
func HandleCreateTokenWithTrustID(t *testing.T, options tokens.AuthOptionsBuilder, requestJSON string) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
-
- client := gophercloud.ServiceClient{
- ProviderClient: &gophercloud.ProviderClient{},
- Endpoint: testhelper.Endpoint(),
- }
-
testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "POST")
testhelper.TestHeader(t, r, "Content-Type", "application/json")
@@ -75,30 +64,4 @@
}
}`)
})
-
- var actual trusts.TokenExt
- err := tokens.Create(&client, options).ExtractInto(&actual)
- if err != nil {
- t.Errorf("Create returned an error: %v", err)
- }
- expected := trusts.TokenExt{
- Token: trusts.Token{
- Token: tokens.Token{
- ExpiresAt: gophercloud.JSONRFC3339Milli(time.Date(2013, 02, 27, 18, 30, 59, 999999000, time.UTC)),
- },
- Trust: trusts.Trust{
- ID: "fe0aef",
- Impersonation: false,
- TrusteeUser: trusts.TrusteeUser{
- ID: "0ca8f6",
- },
- TrustorUser: trusts.TrustorUser{
- ID: "bd263c",
- },
- RedelegatedTrustID: "3ba234",
- RedelegationCount: 2,
- },
- },
- }
- testhelper.AssertDeepEquals(t, expected, actual)
}
diff --git a/openstack/identity/v3/extensions/trusts/testing/requests_test.go b/openstack/identity/v3/extensions/trusts/testing/requests_test.go
index f0e41dc..f8a65ad 100644
--- a/openstack/identity/v3/extensions/trusts/testing/requests_test.go
+++ b/openstack/identity/v3/extensions/trusts/testing/requests_test.go
@@ -2,12 +2,18 @@
import (
"testing"
+ "time"
"github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts"
"github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
+ th "github.com/gophercloud/gophercloud/testhelper"
+ "github.com/gophercloud/gophercloud/testhelper/client"
)
func TestCreateUserIDPasswordTrustID(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
ao := trusts.AuthOptsExt{
TrustID: "de0945a",
AuthOptionsBuilder: &tokens.AuthOptions{
@@ -32,4 +38,37 @@
}
}
`)
+
+ var actual struct {
+ tokens.Token
+ trusts.TokenExt
+ }
+ err := tokens.Create(client.ServiceClient(), ao).ExtractInto(&actual)
+ if err != nil {
+ t.Errorf("Create returned an error: %v", err)
+ }
+ expected := struct {
+ tokens.Token
+ trusts.TokenExt
+ }{
+ tokens.Token{
+ ExpiresAt: time.Date(2013, 02, 27, 18, 30, 59, 999999000, time.UTC),
+ },
+ trusts.TokenExt{
+ Trust: trusts.Trust{
+ ID: "fe0aef",
+ Impersonation: false,
+ TrusteeUser: trusts.TrusteeUser{
+ ID: "0ca8f6",
+ },
+ TrustorUser: trusts.TrustorUser{
+ ID: "bd263c",
+ },
+ RedelegatedTrustID: "3ba234",
+ RedelegationCount: 2,
+ },
+ },
+ }
+
+ th.AssertDeepEquals(t, expected, actual)
}