blob: 8d85655f6b1f1311bcd6976c564fef56515bed20 [file] [log] [blame]
Jamie Hannafordbde72602014-11-10 10:32:26 +01001// +build acceptance lbs
2
3package v1
4
5import (
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
13func TestSession(t *testing.T) {
Jamie Hannafordbde72602014-11-10 10:32:26 +010014 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
30func 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
36func 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
43func 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}