Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 1 | // +build acceptance lbs |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | "github.com/rackspace/gophercloud/rackspace/lb/v1/throttle" |
| 10 | th "github.com/rackspace/gophercloud/testhelper" |
| 11 | ) |
| 12 | |
| 13 | func TestThrottle(t *testing.T) { |
Jamie Hannaford | 82ce916 | 2014-11-10 12:18:35 +0100 | [diff] [blame^] | 14 | return |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 15 | client := setup(t) |
| 16 | |
| 17 | ids := createLB(t, client, 1) |
| 18 | lbID := ids[0] |
| 19 | |
| 20 | getThrottleConfig(t, client, lbID) |
| 21 | |
| 22 | createThrottleConfig(t, client, lbID) |
| 23 | waitForLB(client, lbID, "ACTIVE") |
| 24 | |
| 25 | deleteThrottleConfig(t, client, lbID) |
| 26 | waitForLB(client, lbID, "ACTIVE") |
| 27 | |
| 28 | deleteLB(t, client, lbID) |
| 29 | } |
| 30 | |
| 31 | func getThrottleConfig(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
| 32 | sp, err := throttle.Get(client, lbID).Extract() |
| 33 | th.AssertNoErr(t, err) |
| 34 | t.Logf("Throttle config: MaxConns [%s]", sp.MaxConnections) |
| 35 | } |
| 36 | |
| 37 | func createThrottleConfig(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
| 38 | opts := throttle.CreateOpts{MaxConnections: 200} |
| 39 | err := throttle.Create(client, lbID, opts).ExtractErr() |
| 40 | th.AssertNoErr(t, err) |
| 41 | t.Logf("Enable throttling for %d", lbID) |
| 42 | } |
| 43 | |
| 44 | func deleteThrottleConfig(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
| 45 | err := throttle.Delete(client, lbID).ExtractErr() |
| 46 | th.AssertNoErr(t, err) |
| 47 | t.Logf("Disable throttling for %d", lbID) |
| 48 | } |