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 1
1
package adminactions
2
2
3
- import "github.com/rackspace/gophercloud"
3
+ import (
4
+ "fmt"
5
+
6
+ "github.com/rackspace/gophercloud"
7
+ )
4
8
5
9
func actionURL (client * gophercloud.ServiceClient , id string ) string {
6
10
return client .ServiceURL ("servers" , id , "action" )
@@ -21,12 +25,17 @@ type CreateBackupOpts struct {
21
25
func (opts CreateBackupOpts ) ToCreateBackupMap () (map [string ]interface {}, error ) {
22
26
backup := make (map [string ]interface {})
23
27
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." )
26
33
}
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." )
29
36
}
37
+ backup ["name" ] = opts .Name
38
+ backup ["backup_type" ] = opts .BackupType
30
39
backup ["rotation" ] = opts .Rotation
31
40
32
41
return map [string ]interface {}{"createBackup" : backup }, nil
Original file line number Diff line number Diff line change 1
1
package adminactions
2
2
3
3
import (
4
+ "fmt"
4
5
"testing"
5
6
6
7
th "github.com/rackspace/gophercloud/testhelper"
@@ -23,6 +24,53 @@ func TestCreateBackup(t *testing.T) {
23
24
th .AssertNoErr (t , err )
24
25
}
25
26
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
+
26
74
func TestInjectNetworkInfo (t * testing.T ) {
27
75
th .SetupHTTP ()
28
76
defer th .TeardownHTTP ()
You can’t perform that action at this time.
0 commit comments