blob: 3402e3af39d3aa6530ff43d13f4d6c816ab42635 [file] [log] [blame]
Jamie Hannaford302c0b62015-02-16 14:12:34 +01001package backups
2
3import (
Jamie Hannaford302c0b62015-02-16 14:12:34 +01004 "testing"
5
Jamie Hannafordbe008242015-02-17 14:56:41 +01006 "github.com/rackspace/gophercloud/testhelper/fixture"
Jamie Hannaford302c0b62015-02-16 14:12:34 +01007)
8
Jamie Hannaforde0524732015-02-16 14:44:13 +01009var 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 Hannaford302c0b62015-02-16 14:12:34 +010031func 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 Hannafordbe008242015-02-17 14:56:41 +010042 fixture.SetupHandler(t, "/backups", "POST", requestJSON, singleBackup, 202)
Jamie Hannaford302c0b62015-02-16 14:12:34 +010043}
44
45func 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 Hannaforde0524732015-02-16 14:44:13 +010053 "datastore": {
54 "version": "5.1",
55 "type": "MySQL",
56 "version_id": "20000000-0000-0000-0000-000000000002"
57 },
Jamie Hannaford302c0b62015-02-16 14:12:34 +010058 "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 Hannafordbe008242015-02-17 14:56:41 +010070 fixture.SetupHandler(t, "/backups", "GET", "", responseJSON, 200)
Jamie Hannaford302c0b62015-02-16 14:12:34 +010071}
Jamie Hannaforde0524732015-02-16 14:44:13 +010072
73func HandleGetSuccessfully(t *testing.T, backupID string) {
Jamie Hannafordbe008242015-02-17 14:56:41 +010074 fixture.SetupHandler(t, "/backups/"+backupID, "GET", "", singleBackup, 200)
Jamie Hannaforde0524732015-02-16 14:44:13 +010075}
76
77func HandleDeleteSuccessfully(t *testing.T, backupID string) {
Jamie Hannafordbe008242015-02-17 14:56:41 +010078 fixture.SetupHandler(t, "/backups/"+backupID, "DELETE", "", "", 202)
Jamie Hannaforde0524732015-02-16 14:44:13 +010079}