github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/internal/acceptance/openstack/compute/v2/limits_test.go (about)

     1  //go:build acceptance || compute || limits
     2  
     3  package v2
     4  
     5  import (
     6  	"context"
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/vnpaycloud-console/gophercloud/v2/internal/acceptance/clients"
    11  	"github.com/vnpaycloud-console/gophercloud/v2/internal/acceptance/tools"
    12  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/compute/v2/limits"
    13  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    14  )
    15  
    16  func TestLimits(t *testing.T) {
    17  	client, err := clients.NewComputeV2Client()
    18  	th.AssertNoErr(t, err)
    19  
    20  	limits, err := limits.Get(context.TODO(), client, nil).Extract()
    21  	th.AssertNoErr(t, err)
    22  
    23  	tools.PrintResource(t, limits)
    24  
    25  	th.AssertEquals(t, 10240, limits.Absolute.MaxPersonalitySize)
    26  }
    27  
    28  func TestLimitsForTenant(t *testing.T) {
    29  	clients.RequireAdmin(t)
    30  
    31  	client, err := clients.NewComputeV2Client()
    32  	th.AssertNoErr(t, err)
    33  
    34  	// I think this is the easiest way to get the tenant ID while being
    35  	// agnostic to Identity v2 and v3.
    36  	// Technically we're just returning the limits for ourselves, but it's
    37  	// the fact that we're specifying a tenant ID that is important here.
    38  	endpointParts := strings.Split(client.Endpoint, "/")
    39  	tenantID := endpointParts[4]
    40  
    41  	getOpts := limits.GetOpts{
    42  		TenantID: tenantID,
    43  	}
    44  
    45  	limits, err := limits.Get(context.TODO(), client, getOpts).Extract()
    46  	th.AssertNoErr(t, err)
    47  
    48  	tools.PrintResource(t, limits)
    49  
    50  	th.AssertEquals(t, 10240, limits.Absolute.MaxPersonalitySize)
    51  }