blob: e5d8f7cefc2d8bb8b276f9132ba9710c5515db8c [file] [log] [blame]
Jamie Hannaford302c0b62015-02-16 14:12:34 +01001package backups
2
3import (
4 "testing"
5
6 "github.com/rackspace/gophercloud/pagination"
Jamie Hannaforda50d1352015-02-18 11:38:38 +01007 "github.com/rackspace/gophercloud/rackspace/db/v1/datastores"
Jamie Hannaford302c0b62015-02-16 14:12:34 +01008 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
10)
11
Jamie Hannaforde0524732015-02-16 14:44:13 +010012const backupID = "61f12fef-edb1-4561-8122-e7c00ef26a82"
Jamie Hannaford302c0b62015-02-16 14:12:34 +010013
14func TestCreate(t *testing.T) {
15 th.SetupHTTP()
16 defer th.TeardownHTTP()
17
18 HandleCreateSuccessfully(t)
19
20 opts := CreateOpts{
21 Name: "snapshot",
22 Description: "My Backup",
23 InstanceID: "d4603f69-ec7e-4e9b-803f-600b9205576f",
24 }
25
26 instance, err := Create(fake.ServiceClient(), opts).Extract()
27 th.AssertNoErr(t, err)
28
29 expected := &Backup{
30 Created: "2014-02-13T21:47:16",
31 Description: "My Backup",
32 ID: "61f12fef-edb1-4561-8122-e7c00ef26a82",
33 InstanceID: "d4603f69-ec7e-4e9b-803f-600b9205576f",
34 LocationRef: "",
35 Name: "snapshot",
36 ParentID: "",
37 Size: 100,
38 Status: "NEW",
39 Updated: "2014-02-13T21:47:16",
Jamie Hannaforda50d1352015-02-18 11:38:38 +010040 Datastore: datastores.DatastorePartial{
Jamie Hannafordc1c6bf82015-02-17 16:53:38 +010041 Version: "5.1",
42 Type: "MySQL",
43 VersionID: "20000000-0000-0000-0000-000000000002",
44 },
Jamie Hannaford302c0b62015-02-16 14:12:34 +010045 }
46
47 th.AssertDeepEquals(t, expected, instance)
48}
49
50func TestList(t *testing.T) {
51 th.SetupHTTP()
52 defer th.TeardownHTTP()
53
54 HandleListSuccessfully(t)
55
56 count := 0
57
58 List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
59 count++
60 actual, err := ExtractBackups(page)
61 th.AssertNoErr(t, err)
62
63 expected := []Backup{
64 Backup{
65 Created: "2014-06-18T21:23:35",
66 Description: "Backup from Restored Instance",
67 ID: "87972694-4be2-40f5-83f8-501656e0032a",
68 InstanceID: "29af2cd9-0674-48ab-b87a-b160f00208e6",
69 LocationRef: "http://localhost/path/to/backup",
70 Name: "restored_backup",
71 ParentID: "",
72 Size: 0.141026,
73 Status: "COMPLETED",
74 Updated: "2014-06-18T21:24:39",
Jamie Hannaforda50d1352015-02-18 11:38:38 +010075 Datastore: datastores.DatastorePartial{
Jamie Hannafordc1c6bf82015-02-17 16:53:38 +010076 Version: "5.1",
77 Type: "MySQL",
78 VersionID: "20000000-0000-0000-0000-000000000002",
79 },
Jamie Hannaford302c0b62015-02-16 14:12:34 +010080 },
81 }
82
83 th.AssertDeepEquals(t, expected, actual)
84
85 return true, nil
86 })
87
88 if count != 1 {
89 t.Errorf("Expected 1 page, got %d", count)
90 }
91}
Jamie Hannaforde0524732015-02-16 14:44:13 +010092
93func TestGet(t *testing.T) {
94 th.SetupHTTP()
95 defer th.TeardownHTTP()
96
97 HandleGetSuccessfully(t, backupID)
98
99 instance, err := Get(fake.ServiceClient(), backupID).Extract()
100 th.AssertNoErr(t, err)
101
102 expected := &Backup{
103 Created: "2014-02-13T21:47:16",
104 Description: "My Backup",
105 ID: "61f12fef-edb1-4561-8122-e7c00ef26a82",
106 InstanceID: "d4603f69-ec7e-4e9b-803f-600b9205576f",
107 LocationRef: "",
108 Name: "snapshot",
109 ParentID: "",
110 Size: 100,
111 Status: "NEW",
112 Updated: "2014-02-13T21:47:16",
Jamie Hannaforda50d1352015-02-18 11:38:38 +0100113 Datastore: datastores.DatastorePartial{
Jamie Hannafordc1c6bf82015-02-17 16:53:38 +0100114 Version: "5.1",
115 Type: "MySQL",
116 VersionID: "20000000-0000-0000-0000-000000000002",
117 },
Jamie Hannaforde0524732015-02-16 14:44:13 +0100118 }
119
120 th.AssertDeepEquals(t, expected, instance)
121}
122
123func TestDelete(t *testing.T) {
124 th.SetupHTTP()
125 defer th.TeardownHTTP()
126
127 HandleDeleteSuccessfully(t, backupID)
128
129 err := Delete(fake.ServiceClient(), backupID).ExtractErr()
130 th.AssertNoErr(t, err)
131}