blob: 3f7681c8247713163ac8889fa5710724aeb918f4 [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
11//const instanceID = "{instanceID}"
12
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",
39 }
40
41 th.AssertDeepEquals(t, expected, instance)
42}
43
44func TestList(t *testing.T) {
45 th.SetupHTTP()
46 defer th.TeardownHTTP()
47
48 HandleListSuccessfully(t)
49
50 count := 0
51
52 List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
53 count++
54 actual, err := ExtractBackups(page)
55 th.AssertNoErr(t, err)
56
57 expected := []Backup{
58 Backup{
59 Created: "2014-06-18T21:23:35",
60 Description: "Backup from Restored Instance",
61 ID: "87972694-4be2-40f5-83f8-501656e0032a",
62 InstanceID: "29af2cd9-0674-48ab-b87a-b160f00208e6",
63 LocationRef: "http://localhost/path/to/backup",
64 Name: "restored_backup",
65 ParentID: "",
66 Size: 0.141026,
67 Status: "COMPLETED",
68 Updated: "2014-06-18T21:24:39",
69 },
70 }
71
72 th.AssertDeepEquals(t, expected, actual)
73
74 return true, nil
75 })
76
77 if count != 1 {
78 t.Errorf("Expected 1 page, got %d", count)
79 }
80}