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/sessions" |
| 10 | th "github.com/rackspace/gophercloud/testhelper" |
| 11 | ) |
| 12 | |
| 13 | func TestSession(t *testing.T) { |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 14 | client := setup(t) |
| 15 | |
| 16 | ids := createLB(t, client, 1) |
| 17 | lbID := ids[0] |
| 18 | |
| 19 | getSession(t, client, lbID) |
| 20 | |
| 21 | enableSession(t, client, lbID) |
| 22 | waitForLB(client, lbID, "ACTIVE") |
| 23 | |
| 24 | disableSession(t, client, lbID) |
| 25 | waitForLB(client, lbID, "ACTIVE") |
| 26 | |
| 27 | deleteLB(t, client, lbID) |
| 28 | } |
| 29 | |
| 30 | func getSession(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
| 31 | sp, err := sessions.Get(client, lbID).Extract() |
| 32 | th.AssertNoErr(t, err) |
| 33 | t.Logf("Session config: Type [%s]", sp.Type) |
| 34 | } |
| 35 | |
| 36 | func enableSession(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
| 37 | opts := sessions.CreateOpts{Type: sessions.HTTPCOOKIE} |
| 38 | err := sessions.Enable(client, lbID, opts).ExtractErr() |
| 39 | th.AssertNoErr(t, err) |
| 40 | t.Logf("Enable %s sessions for %d", opts.Type, lbID) |
| 41 | } |
| 42 | |
| 43 | func disableSession(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
| 44 | err := sessions.Disable(client, lbID).ExtractErr() |
| 45 | th.AssertNoErr(t, err) |
| 46 | t.Logf("Disable sessions for %d", lbID) |
| 47 | } |