This repository was archived by the owner on Aug 1, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +62
-5
lines changed
openstack/compute/v2/extensions/adminactions Expand file tree Collapse file tree 2 files changed +62
-5
lines changed Original file line number Diff line number Diff line change 11package adminactions
22
3- import "github.com/rackspace/gophercloud"
3+ import (
4+ "fmt"
5+
6+ "github.com/rackspace/gophercloud"
7+ )
48
59func actionURL (client * gophercloud.ServiceClient , id string ) string {
610 return client .ServiceURL ("servers" , id , "action" )
@@ -21,12 +25,17 @@ type CreateBackupOpts struct {
2125func (opts CreateBackupOpts ) ToCreateBackupMap () (map [string ]interface {}, error ) {
2226 backup := make (map [string ]interface {})
2327
24- if opts .Name != "" {
25- backup ["name" ] = opts .Name
28+ if opts .Name == "" {
29+ return nil , fmt .Errorf ("CreateBackupOpts.Name cannot be blank." )
30+ }
31+ if opts .BackupType == "" {
32+ return nil , fmt .Errorf ("CreateBackupOpts.BackupType cannot be blank." )
2633 }
27- if opts .BackupType != "" {
28- backup [ "backup_type" ] = opts . BackupType
34+ if opts .Rotation < 0 {
35+ return nil , fmt . Errorf ( "CreateBackupOpts.Rotation must 0 or greater." )
2936 }
37+ backup ["name" ] = opts .Name
38+ backup ["backup_type" ] = opts .BackupType
3039 backup ["rotation" ] = opts .Rotation
3140
3241 return map [string ]interface {}{"createBackup" : backup }, nil
Original file line number Diff line number Diff line change 11package adminactions
22
33import (
4+ "fmt"
45 "testing"
56
67 th "github.com/rackspace/gophercloud/testhelper"
@@ -23,6 +24,53 @@ func TestCreateBackup(t *testing.T) {
2324 th .AssertNoErr (t , err )
2425}
2526
27+ func TestCreateBackupNoName (t * testing.T ) {
28+ th .SetupHTTP ()
29+ defer th .TeardownHTTP ()
30+
31+ mockCreateBackupResponse (t , serverID )
32+
33+ err := CreateBackup (client .ServiceClient (), serverID , CreateBackupOpts {
34+ BackupType : "daily" ,
35+ Rotation : 1 ,
36+ }).ExtractErr ()
37+ if err == nil {
38+ fmt .Errorf ("CreateBackup without a specified Name should throw an Error." )
39+ }
40+ }
41+
42+ func TestCreateBackupNegativeRotation (t * testing.T ) {
43+ th .SetupHTTP ()
44+ defer th .TeardownHTTP ()
45+
46+ mockCreateBackupResponse (t , serverID )
47+
48+ err := CreateBackup (client .ServiceClient (), serverID , CreateBackupOpts {
49+ Name : "Backup 1" ,
50+ BackupType : "daily" ,
51+ Rotation : - 1 ,
52+ }).ExtractErr ()
53+ if err == nil {
54+ fmt .Errorf ("CreateBackup without a negative Rotation should throw an Error." )
55+ }
56+ }
57+
58+ func TestCreateBackupNoType (t * testing.T ) {
59+ th .SetupHTTP ()
60+ defer th .TeardownHTTP ()
61+
62+ mockCreateBackupResponse (t , serverID )
63+
64+ err := CreateBackup (client .ServiceClient (), serverID , CreateBackupOpts {
65+ Name : "Backup 1" ,
66+
67+ Rotation : 1 ,
68+ }).ExtractErr ()
69+ if err == nil {
70+ fmt .Errorf ("CreateBackup without a specified BackupType should throw an Error." )
71+ }
72+ }
73+
2674func TestInjectNetworkInfo (t * testing.T ) {
2775 th .SetupHTTP ()
2876 defer th .TeardownHTTP ()
You can’t perform that action at this time.
0 commit comments