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