blob: 78fbae7ffc97109d42459d6b8a87e8e3823ae89f [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
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02009 "gerrit.mcp.mirantis.net/debian/gophercloud.git/acceptance/clients"
10 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/compute/v2/extensions/limits"
Joe Topjiana08c1d22016-11-04 10:33:00 -060011)
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}