github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/identity/v3/federation/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/identity/v3/federation"
     8  	"github.com/vnpaycloud-console/gophercloud/v2/pagination"
     9  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    10  	"github.com/vnpaycloud-console/gophercloud/v2/testhelper/client"
    11  )
    12  
    13  func TestListMappings(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  	HandleListMappingsSuccessfully(t)
    17  
    18  	count := 0
    19  	err := federation.ListMappings(client.ServiceClient()).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
    20  		count++
    21  
    22  		actual, err := federation.ExtractMappings(page)
    23  		th.AssertNoErr(t, err)
    24  
    25  		th.CheckDeepEquals(t, ExpectedMappingsSlice, actual)
    26  
    27  		return true, nil
    28  	})
    29  	th.AssertNoErr(t, err)
    30  	th.CheckEquals(t, count, 1)
    31  }
    32  
    33  func TestListMappingsAllPages(t *testing.T) {
    34  	th.SetupHTTP()
    35  	defer th.TeardownHTTP()
    36  	HandleListMappingsSuccessfully(t)
    37  
    38  	allPages, err := federation.ListMappings(client.ServiceClient()).AllPages(context.TODO())
    39  	th.AssertNoErr(t, err)
    40  	actual, err := federation.ExtractMappings(allPages)
    41  	th.AssertNoErr(t, err)
    42  	th.CheckDeepEquals(t, ExpectedMappingsSlice, actual)
    43  }
    44  
    45  func TestCreateMappings(t *testing.T) {
    46  	th.SetupHTTP()
    47  	defer th.TeardownHTTP()
    48  	HandleCreateMappingSuccessfully(t)
    49  
    50  	createOpts := federation.CreateMappingOpts{
    51  		Rules: []federation.MappingRule{
    52  			{
    53  				Local: []federation.RuleLocal{
    54  					{
    55  						User: &federation.RuleUser{
    56  							Name: "{0}",
    57  						},
    58  					},
    59  					{
    60  						Group: &federation.Group{
    61  							ID: "0cd5e9",
    62  						},
    63  					},
    64  				},
    65  				Remote: []federation.RuleRemote{
    66  					{
    67  						Type: "UserName",
    68  					},
    69  					{
    70  						Type: "orgPersonType",
    71  						NotAnyOf: []string{
    72  							"Contractor",
    73  							"Guest",
    74  						},
    75  					},
    76  				},
    77  			},
    78  		},
    79  	}
    80  
    81  	actual, err := federation.CreateMapping(context.TODO(), client.ServiceClient(), "ACME", createOpts).Extract()
    82  	th.AssertNoErr(t, err)
    83  	th.CheckDeepEquals(t, MappingACME, *actual)
    84  }
    85  
    86  func TestGetMapping(t *testing.T) {
    87  	th.SetupHTTP()
    88  	defer th.TeardownHTTP()
    89  	HandleGetMappingSuccessfully(t)
    90  
    91  	actual, err := federation.GetMapping(context.TODO(), client.ServiceClient(), "ACME").Extract()
    92  	th.AssertNoErr(t, err)
    93  	th.CheckDeepEquals(t, MappingACME, *actual)
    94  }
    95  
    96  func TestUpdateMapping(t *testing.T) {
    97  	th.SetupHTTP()
    98  	defer th.TeardownHTTP()
    99  	HandleUpdateMappingSuccessfully(t)
   100  
   101  	updateOpts := federation.UpdateMappingOpts{
   102  		Rules: []federation.MappingRule{
   103  			{
   104  				Local: []federation.RuleLocal{
   105  					{
   106  						User: &federation.RuleUser{
   107  							Name: "{0}",
   108  						},
   109  					},
   110  					{
   111  						Group: &federation.Group{
   112  							ID: "0cd5e9",
   113  						},
   114  					},
   115  				},
   116  				Remote: []federation.RuleRemote{
   117  					{
   118  						Type: "UserName",
   119  					},
   120  					{
   121  						Type: "orgPersonType",
   122  						AnyOneOf: []string{
   123  							"Contractor",
   124  							"SubContractor",
   125  						},
   126  					},
   127  				},
   128  			},
   129  		},
   130  	}
   131  
   132  	actual, err := federation.UpdateMapping(context.TODO(), client.ServiceClient(), "ACME", updateOpts).Extract()
   133  	th.AssertNoErr(t, err)
   134  	th.CheckDeepEquals(t, MappingUpdated, *actual)
   135  }
   136  
   137  func TestDeleteMapping(t *testing.T) {
   138  	th.SetupHTTP()
   139  	defer th.TeardownHTTP()
   140  	HandleDeleteMappingSuccessfully(t)
   141  
   142  	res := federation.DeleteMapping(context.TODO(), client.ServiceClient(), "ACME")
   143  	th.AssertNoErr(t, res.Err)
   144  }