Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 1 | package backups |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud/pagination" |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud/rackspace/db/v1/datastores" |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
Jamie Hannaford | e052473 | 2015-02-16 14:44:13 +0100 | [diff] [blame] | 12 | const backupID = "61f12fef-edb1-4561-8122-e7c00ef26a82" |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 13 | |
| 14 | func 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 Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 40 | Datastore: datastores.DatastorePartial{ |
Jamie Hannaford | c1c6bf8 | 2015-02-17 16:53:38 +0100 | [diff] [blame] | 41 | Version: "5.1", |
| 42 | Type: "MySQL", |
| 43 | VersionID: "20000000-0000-0000-0000-000000000002", |
| 44 | }, |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | th.AssertDeepEquals(t, expected, instance) |
| 48 | } |
| 49 | |
| 50 | func 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 Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 75 | Datastore: datastores.DatastorePartial{ |
Jamie Hannaford | c1c6bf8 | 2015-02-17 16:53:38 +0100 | [diff] [blame] | 76 | Version: "5.1", |
| 77 | Type: "MySQL", |
| 78 | VersionID: "20000000-0000-0000-0000-000000000002", |
| 79 | }, |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 80 | }, |
| 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 Hannaford | e052473 | 2015-02-16 14:44:13 +0100 | [diff] [blame] | 92 | |
| 93 | func 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 Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 113 | Datastore: datastores.DatastorePartial{ |
Jamie Hannaford | c1c6bf8 | 2015-02-17 16:53:38 +0100 | [diff] [blame] | 114 | Version: "5.1", |
| 115 | Type: "MySQL", |
| 116 | VersionID: "20000000-0000-0000-0000-000000000002", |
| 117 | }, |
Jamie Hannaford | e052473 | 2015-02-16 14:44:13 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | th.AssertDeepEquals(t, expected, instance) |
| 121 | } |
| 122 | |
| 123 | func 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 | } |