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