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

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/huaweicloud/golangsdk/openstack/identity/v3/projects"
     7  	"github.com/huaweicloud/golangsdk/pagination"
     8  	th "github.com/huaweicloud/golangsdk/testhelper"
     9  	"github.com/huaweicloud/golangsdk/testhelper/client"
    10  )
    11  
    12  func TestListProjects(t *testing.T) {
    13  	th.SetupHTTP()
    14  	defer th.TeardownHTTP()
    15  	HandleListProjectsSuccessfully(t)
    16  
    17  	count := 0
    18  	err := projects.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
    19  		count++
    20  
    21  		actual, err := projects.ExtractProjects(page)
    22  		th.AssertNoErr(t, err)
    23  
    24  		th.CheckDeepEquals(t, ExpectedProjectSlice, actual)
    25  
    26  		return true, nil
    27  	})
    28  	th.AssertNoErr(t, err)
    29  	th.CheckEquals(t, count, 1)
    30  }
    31  
    32  func TestGetProject(t *testing.T) {
    33  	th.SetupHTTP()
    34  	defer th.TeardownHTTP()
    35  	HandleGetProjectSuccessfully(t)
    36  
    37  	actual, err := projects.Get(client.ServiceClient(), "1234").Extract()
    38  	th.AssertNoErr(t, err)
    39  	th.CheckDeepEquals(t, RedTeam, *actual)
    40  }
    41  
    42  func TestCreateProject(t *testing.T) {
    43  	th.SetupHTTP()
    44  	defer th.TeardownHTTP()
    45  	HandleCreateProjectSuccessfully(t)
    46  
    47  	createOpts := projects.CreateOpts{
    48  		Name:        "Red Team",
    49  		Description: "The team that is red",
    50  	}
    51  
    52  	actual, err := projects.Create(client.ServiceClient(), createOpts).Extract()
    53  	th.AssertNoErr(t, err)
    54  	th.CheckDeepEquals(t, RedTeam, *actual)
    55  }
    56  
    57  func TestDeleteProject(t *testing.T) {
    58  	th.SetupHTTP()
    59  	defer th.TeardownHTTP()
    60  	HandleDeleteProjectSuccessfully(t)
    61  
    62  	res := projects.Delete(client.ServiceClient(), "1234")
    63  	th.AssertNoErr(t, res.Err)
    64  }
    65  
    66  func TestUpdateProject(t *testing.T) {
    67  	th.SetupHTTP()
    68  	defer th.TeardownHTTP()
    69  	HandleUpdateProjectSuccessfully(t)
    70  
    71  	updateOpts := projects.UpdateOpts{
    72  		Name:        "Bright Red Team",
    73  		Description: "The team that is bright red",
    74  	}
    75  
    76  	actual, err := projects.Update(client.ServiceClient(), "1234", updateOpts).Extract()
    77  	th.AssertNoErr(t, err)
    78  	th.CheckDeepEquals(t, UpdatedRedTeam, *actual)
    79  }