blob: 2bf5ce6b85420114f7c0dd8a11d24f3028457fea [file] [log] [blame]
Joe Topjiana08c1d22016-11-04 10:33:00 -06001// +build acceptance compute limits
2
3package v2
4
5import (
6 "strings"
7 "testing"
8
9 "github.com/gophercloud/gophercloud/acceptance/clients"
10 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/limits"
11)
12
13func TestLimits(t *testing.T) {
14 client, err := clients.NewComputeV2Client()
15 if err != nil {
16 t.Fatalf("Unable to create a compute client: %v", err)
17 }
18
19 limits, err := limits.Get(client, nil).Extract()
20 if err != nil {
21 t.Fatalf("Unable to get limits: %v", err)
22 }
23
24 t.Logf("Limits for scoped user:")
25 t.Logf("%#v", limits)
26}
27
28func TestLimitsForTenant(t *testing.T) {
29 client, err := clients.NewComputeV2Client()
30 if err != nil {
31 t.Fatalf("Unable to create a compute client: %v", err)
32 }
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(client, getOpts).Extract()
46 if err != nil {
47 t.Fatalf("Unable to get absolute limits: %v", err)
48 }
49
50 t.Logf("Limits for tenant %s:", tenantID)
51 t.Logf("%#v", limits)
52}