Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 1 | package backups |
| 2 | |
| 3 | import ( |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 4 | "testing" |
| 5 | |
Jamie Hannaford | be00824 | 2015-02-17 14:56:41 +0100 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud/testhelper/fixture" |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 7 | ) |
| 8 | |
Jamie Hannaford | e052473 | 2015-02-16 14:44:13 +0100 | [diff] [blame] | 9 | var singleBackup = ` |
| 10 | { |
| 11 | "backup": { |
| 12 | "created": "2014-02-13T21:47:16", |
| 13 | "description": "My Backup", |
| 14 | "id": "61f12fef-edb1-4561-8122-e7c00ef26a82", |
| 15 | "instance_id": "d4603f69-ec7e-4e9b-803f-600b9205576f", |
| 16 | "locationRef": null, |
| 17 | "name": "snapshot", |
| 18 | "parent_id": null, |
| 19 | "size": 100, |
| 20 | "status": "NEW", |
| 21 | "datastore": { |
| 22 | "version": "5.1", |
| 23 | "type": "MySQL", |
| 24 | "version_id": "20000000-0000-0000-0000-000000000002" |
| 25 | }, |
| 26 | "updated": "2014-02-13T21:47:16" |
| 27 | } |
| 28 | } |
| 29 | ` |
| 30 | |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 31 | func HandleCreateSuccessfully(t *testing.T) { |
| 32 | requestJSON := ` |
| 33 | { |
| 34 | "backup": { |
| 35 | "description": "My Backup", |
| 36 | "instance": "d4603f69-ec7e-4e9b-803f-600b9205576f", |
| 37 | "name": "snapshot" |
| 38 | } |
| 39 | } |
| 40 | ` |
| 41 | |
Jamie Hannaford | be00824 | 2015-02-17 14:56:41 +0100 | [diff] [blame] | 42 | fixture.SetupHandler(t, "/backups", "POST", requestJSON, singleBackup, 202) |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | func HandleListSuccessfully(t *testing.T) { |
| 46 | responseJSON := ` |
| 47 | { |
| 48 | "backups": [ |
| 49 | { |
| 50 | "status": "COMPLETED", |
| 51 | "updated": "2014-06-18T21:24:39", |
| 52 | "description": "Backup from Restored Instance", |
Jamie Hannaford | e052473 | 2015-02-16 14:44:13 +0100 | [diff] [blame] | 53 | "datastore": { |
| 54 | "version": "5.1", |
| 55 | "type": "MySQL", |
| 56 | "version_id": "20000000-0000-0000-0000-000000000002" |
| 57 | }, |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 58 | "id": "87972694-4be2-40f5-83f8-501656e0032a", |
| 59 | "size": 0.141026, |
| 60 | "name": "restored_backup", |
| 61 | "created": "2014-06-18T21:23:35", |
| 62 | "instance_id": "29af2cd9-0674-48ab-b87a-b160f00208e6", |
| 63 | "parent_id": null, |
| 64 | "locationRef": "http://localhost/path/to/backup" |
| 65 | } |
| 66 | ] |
| 67 | } |
| 68 | ` |
| 69 | |
Jamie Hannaford | be00824 | 2015-02-17 14:56:41 +0100 | [diff] [blame] | 70 | fixture.SetupHandler(t, "/backups", "GET", "", responseJSON, 200) |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 71 | } |
Jamie Hannaford | e052473 | 2015-02-16 14:44:13 +0100 | [diff] [blame] | 72 | |
| 73 | func HandleGetSuccessfully(t *testing.T, backupID string) { |
Jamie Hannaford | be00824 | 2015-02-17 14:56:41 +0100 | [diff] [blame] | 74 | fixture.SetupHandler(t, "/backups/"+backupID, "GET", "", singleBackup, 200) |
Jamie Hannaford | e052473 | 2015-02-16 14:44:13 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | func HandleDeleteSuccessfully(t *testing.T, backupID string) { |
Jamie Hannaford | be00824 | 2015-02-17 14:56:41 +0100 | [diff] [blame] | 78 | fixture.SetupHandler(t, "/backups/"+backupID, "DELETE", "", "", 202) |
Jamie Hannaford | e052473 | 2015-02-16 14:44:13 +0100 | [diff] [blame] | 79 | } |