blob: 14eacc1d83ed27ca17adf3ac37078e9b16501db8 [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 Hannaforde0524732015-02-16 14:44:13 +010039 Datastore: Datastore{Version: "5.1", Type: "MySQL", VersionID: "20000000-0000-0000-0000-000000000002"},
Jamie Hannaford302c0b62015-02-16 14:12:34 +010040 }
41
42 th.AssertDeepEquals(t, expected, instance)
43}
44
45func TestList(t *testing.T) {
46 th.SetupHTTP()
47 defer th.TeardownHTTP()
48
49 HandleListSuccessfully(t)
50
51 count := 0
52
53 List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
54 count++
55 actual, err := ExtractBackups(page)
56 th.AssertNoErr(t, err)
57
58 expected := []Backup{
59 Backup{
60 Created: "2014-06-18T21:23:35",
61 Description: "Backup from Restored Instance",
62 ID: "87972694-4be2-40f5-83f8-501656e0032a",
63 InstanceID: "29af2cd9-0674-48ab-b87a-b160f00208e6",
64 LocationRef: "http://localhost/path/to/backup",
65 Name: "restored_backup",
66 ParentID: "",
67 Size: 0.141026,
68 Status: "COMPLETED",
69 Updated: "2014-06-18T21:24:39",
Jamie Hannaforde0524732015-02-16 14:44:13 +010070 Datastore: Datastore{Version: "5.1", Type: "MySQL", VersionID: "20000000-0000-0000-0000-000000000002"},
Jamie Hannaford302c0b62015-02-16 14:12:34 +010071 },
72 }
73
74 th.AssertDeepEquals(t, expected, actual)
75
76 return true, nil
77 })
78
79 if count != 1 {
80 t.Errorf("Expected 1 page, got %d", count)
81 }
82}
Jamie Hannaforde0524732015-02-16 14:44:13 +010083
84func TestGet(t *testing.T) {
85 th.SetupHTTP()
86 defer th.TeardownHTTP()
87
88 HandleGetSuccessfully(t, backupID)
89
90 instance, err := Get(fake.ServiceClient(), backupID).Extract()
91 th.AssertNoErr(t, err)
92
93 expected := &Backup{
94 Created: "2014-02-13T21:47:16",
95 Description: "My Backup",
96 ID: "61f12fef-edb1-4561-8122-e7c00ef26a82",
97 InstanceID: "d4603f69-ec7e-4e9b-803f-600b9205576f",
98 LocationRef: "",
99 Name: "snapshot",
100 ParentID: "",
101 Size: 100,
102 Status: "NEW",
103 Updated: "2014-02-13T21:47:16",
104 Datastore: Datastore{Version: "5.1", Type: "MySQL", VersionID: "20000000-0000-0000-0000-000000000002"},
105 }
106
107 th.AssertDeepEquals(t, expected, instance)
108}
109
110func TestDelete(t *testing.T) {
111 th.SetupHTTP()
112 defer th.TeardownHTTP()
113
114 HandleDeleteSuccessfully(t, backupID)
115
116 err := Delete(fake.ServiceClient(), backupID).ExtractErr()
117 th.AssertNoErr(t, err)
118}