Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +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/lbs" |
| 10 | "github.com/rackspace/gophercloud/rackspace/lb/v1/monitors" |
| 11 | th "github.com/rackspace/gophercloud/testhelper" |
| 12 | ) |
| 13 | |
| 14 | func TestMonitors(t *testing.T) { |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 15 | client := setup(t) |
| 16 | |
| 17 | ids := createLB(t, client, 1) |
| 18 | lbID := ids[0] |
| 19 | |
| 20 | getMonitor(t, client, lbID) |
| 21 | |
| 22 | updateMonitor(t, client, lbID) |
| 23 | |
| 24 | deleteMonitor(t, client, lbID) |
| 25 | |
| 26 | deleteLB(t, client, lbID) |
| 27 | } |
| 28 | |
| 29 | func getMonitor(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
| 30 | hm, err := monitors.Get(client, lbID).Extract() |
| 31 | th.AssertNoErr(t, err) |
| 32 | t.Logf("Health monitor for LB %d: Type [%s] Delay [%d] Timeout [%d] AttemptLimit [%d]", |
| 33 | lbID, hm.Type, hm.Delay, hm.Timeout, hm.AttemptLimit) |
| 34 | } |
| 35 | |
| 36 | func updateMonitor(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
| 37 | opts := monitors.UpdateHTTPMonitorOpts{ |
| 38 | AttemptLimit: 3, |
| 39 | Delay: 10, |
| 40 | Timeout: 10, |
| 41 | BodyRegex: "hello is it me you're looking for", |
| 42 | Path: "/foo", |
| 43 | StatusRegex: "200", |
| 44 | Type: monitors.HTTP, |
| 45 | } |
| 46 | |
| 47 | err := monitors.Update(client, lbID, opts).ExtractErr() |
| 48 | th.AssertNoErr(t, err) |
| 49 | |
| 50 | waitForLB(client, lbID, lbs.ACTIVE) |
| 51 | t.Logf("Updated monitor for LB %d", lbID) |
| 52 | } |
| 53 | |
| 54 | func deleteMonitor(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
| 55 | err := monitors.Delete(client, lbID).ExtractErr() |
| 56 | th.AssertNoErr(t, err) |
| 57 | |
| 58 | waitForLB(client, lbID, lbs.ACTIVE) |
| 59 | t.Logf("Deleted monitor for LB %d", lbID) |
| 60 | } |