Jamie Hannaford | 7afb7af | 2014-11-04 13:32:20 +0100 | [diff] [blame] | 1 | package monitors |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | th "github.com/rackspace/gophercloud/testhelper" |
| 7 | "github.com/rackspace/gophercloud/testhelper/client" |
| 8 | ) |
| 9 | |
| 10 | const lbID = 12345 |
| 11 | |
| 12 | func TestUpdateCONNECT(t *testing.T) { |
| 13 | th.SetupHTTP() |
| 14 | defer th.TeardownHTTP() |
| 15 | |
| 16 | mockUpdateConnectResponse(t, lbID) |
| 17 | |
| 18 | opts := UpdateConnectMonitorOpts{ |
| 19 | AttemptLimit: 3, |
| 20 | Delay: 10, |
| 21 | Timeout: 10, |
| 22 | } |
| 23 | |
| 24 | err := Update(client.ServiceClient(), lbID, opts).ExtractErr() |
| 25 | th.AssertNoErr(t, err) |
| 26 | } |
| 27 | |
| 28 | func TestUpdateHTTP(t *testing.T) { |
| 29 | th.SetupHTTP() |
| 30 | defer th.TeardownHTTP() |
| 31 | |
| 32 | mockUpdateHTTPResponse(t, lbID) |
| 33 | |
| 34 | opts := UpdateHTTPMonitorOpts{ |
| 35 | AttemptLimit: 3, |
| 36 | Delay: 10, |
| 37 | Timeout: 10, |
| 38 | BodyRegex: "{regex}", |
| 39 | Path: "/foo", |
| 40 | StatusRegex: "200", |
| 41 | Type: HTTPS, |
| 42 | } |
| 43 | |
| 44 | err := Update(client.ServiceClient(), lbID, opts).ExtractErr() |
| 45 | th.AssertNoErr(t, err) |
| 46 | } |
Jamie Hannaford | c9a4d89 | 2014-11-04 14:01:56 +0100 | [diff] [blame] | 47 | |
| 48 | func TestGet(t *testing.T) { |
| 49 | th.SetupHTTP() |
| 50 | defer th.TeardownHTTP() |
| 51 | |
| 52 | mockGetResponse(t, lbID) |
| 53 | |
| 54 | m, err := Get(client.ServiceClient(), lbID).Extract() |
| 55 | th.AssertNoErr(t, err) |
| 56 | |
| 57 | expected := &Monitor{ |
| 58 | Type: CONNECT, |
| 59 | Delay: 10, |
| 60 | Timeout: 10, |
| 61 | AttemptLimit: 3, |
| 62 | } |
| 63 | |
| 64 | th.AssertDeepEquals(t, expected, m) |
| 65 | } |
Jamie Hannaford | d7301dd | 2014-11-04 14:05:39 +0100 | [diff] [blame^] | 66 | |
| 67 | func TestDelete(t *testing.T) { |
| 68 | th.SetupHTTP() |
| 69 | defer th.TeardownHTTP() |
| 70 | |
| 71 | mockDeleteResponse(t, lbID) |
| 72 | |
| 73 | err := Delete(client.ServiceClient(), lbID).ExtractErr() |
| 74 | th.AssertNoErr(t, err) |
| 75 | } |