github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3/extensions/trusts/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/huaweicloud/golangsdk/openstack/identity/v3/extensions/trusts"
     8  	"github.com/huaweicloud/golangsdk/openstack/identity/v3/tokens"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  func TestCreateUserIDPasswordTrustID(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  
    17  	ao := trusts.AuthOptsExt{
    18  		TrustID: "de0945a",
    19  		AuthOptionsBuilder: &tokens.AuthOptions{
    20  			UserID:   "me",
    21  			Password: "squirrel!",
    22  		},
    23  	}
    24  	HandleCreateTokenWithTrustID(t, ao, `
    25  		{
    26  			"auth": {
    27  				"identity": {
    28  					"methods": ["password"],
    29  					"password": {
    30  						"user": { "id": "me", "password": "squirrel!" }
    31  					}
    32  				},
    33          "scope": {
    34              "OS-TRUST:trust": {
    35                  "id": "de0945a"
    36              }
    37          }
    38  			}
    39  		}
    40  	`)
    41  
    42  	var actual struct {
    43  		tokens.Token
    44  		trusts.TokenExt
    45  	}
    46  	err := tokens.Create(client.ServiceClient(), ao).ExtractInto(&actual)
    47  	if err != nil {
    48  		t.Errorf("Create returned an error: %v", err)
    49  	}
    50  	expected := struct {
    51  		tokens.Token
    52  		trusts.TokenExt
    53  	}{
    54  		tokens.Token{
    55  			ExpiresAt: time.Date(2013, 02, 27, 18, 30, 59, 999999000, time.UTC),
    56  		},
    57  		trusts.TokenExt{
    58  			Trust: trusts.Trust{
    59  				ID:            "fe0aef",
    60  				Impersonation: false,
    61  				TrusteeUser: trusts.TrusteeUser{
    62  					ID: "0ca8f6",
    63  				},
    64  				TrustorUser: trusts.TrustorUser{
    65  					ID: "bd263c",
    66  				},
    67  				RedelegatedTrustID: "3ba234",
    68  				RedelegationCount:  2,
    69  			},
    70  		},
    71  	}
    72  
    73  	th.AssertDeepEquals(t, expected, actual)
    74  }