-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ServerDisks doc_test * Server add `AdditionalDisks` in `ServerDetails`
- Loading branch information
Showing
6 changed files
with
268 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package glesys | ||
|
||
import "context" | ||
|
||
// ServerDisksService provides functions to interact with serverdisks | ||
type ServerDisksService struct { | ||
client clientInterface | ||
} | ||
|
||
// CreateServerDiskParams specifies the details for a new serverdisk | ||
type CreateServerDiskParams struct { | ||
Name string `json:"name"` | ||
ServerID string `json:"serverid"` | ||
SizeInGIB int `json:"sizeingib"` | ||
} | ||
|
||
// ServerDiskDetails represents any extra disks for a server | ||
type ServerDiskDetails struct { | ||
ID string `json:"id"` | ||
Name string `json:"name,omitempty"` | ||
SizeInGIB int `json:"sizeingib"` | ||
SCSIID int `json:"scsiid"` | ||
} | ||
|
||
// ServerDiskReconfigureParams parameters for updating a ServerDisk | ||
type EditServerDiskParams struct { | ||
ID string `json:"id"` | ||
Name string `json:"name,omitempty"` | ||
SizeInGIB int `json:"sizeingib,omitempty"` | ||
} | ||
|
||
// ServerDiskLimitsDetails represents the disk limits for a server | ||
type ServerDiskLimitsDetails struct { | ||
MinSizeInGIB int `json:"minsizeingib"` | ||
MaxSizeInGIB int `json:"maxsizeingib"` | ||
MaxNumDisks int `json:"maxnumdisks"` | ||
CurrentNumDisks int `json:"currentnumdisks"` | ||
} | ||
|
||
// Create - Creates an additional serverdisk using CreateServerDiskParams | ||
func (s *ServerDisksService) Create(context context.Context, params CreateServerDiskParams) (*ServerDiskDetails, error) { | ||
data := struct { | ||
Response struct { | ||
Disk ServerDiskDetails | ||
} | ||
}{} | ||
err := s.client.post(context, "serverdisk/create", &data, params) | ||
return &data.Response.Disk, err | ||
} | ||
|
||
// UpdateName - Modifies a serverdisk name using EditServerDiskParams | ||
func (s *ServerDisksService) UpdateName(context context.Context, params EditServerDiskParams) (*ServerDiskDetails, error) { | ||
data := struct { | ||
Response struct { | ||
Disk ServerDiskDetails | ||
} | ||
}{} | ||
err := s.client.post(context, "serverdisk/updatename", &data, params) | ||
return &data.Response.Disk, err | ||
} | ||
|
||
// Reconfigure - Modifies a serverdisk using EditServerDiskParams | ||
func (s *ServerDisksService) Reconfigure(context context.Context, params EditServerDiskParams) (*ServerDiskDetails, error) { | ||
data := struct { | ||
Response struct { | ||
Disk ServerDiskDetails | ||
} | ||
}{} | ||
err := s.client.post(context, "serverdisk/reconfigure", &data, params) | ||
return &data.Response.Disk, err | ||
} | ||
|
||
// Delete - deletes a serverdisk | ||
func (s *ServerDisksService) Delete(context context.Context, diskID string) error { | ||
return s.client.post(context, "serverdisk/delete", nil, struct { | ||
DiskID string `json:"id"` | ||
}{diskID}) | ||
} | ||
|
||
// Limits - retrieve serverdisk limits for a specific server | ||
func (s *ServerDisksService) Limits(context context.Context, serverID string) (*ServerDiskLimitsDetails, error) { | ||
data := struct { | ||
Response struct { | ||
Limits ServerDiskLimitsDetails | ||
} | ||
}{} | ||
err := s.client.post(context, "serverdisk/limits", &data, | ||
struct { | ||
ServerID string `json:"serverid"` | ||
}{serverID}) | ||
return &data.Response.Limits, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package glesys | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestServerDisk_Create(t *testing.T) { | ||
c := &mockClient{body: `{ "response": { "disk": { "id": "aaaaa-bbbbbb-cccccc", | ||
"sizeingib": 200, | ||
"name": "Diskett", | ||
"scsiid": 1 | ||
}}}`} | ||
s := ServerDisksService{client: c} | ||
|
||
params := CreateServerDiskParams{ | ||
ServerID: "wps123456", | ||
Name: "Diskett", | ||
SizeInGIB: 200, | ||
} | ||
|
||
disk, _ := s.Create(context.Background(), params) | ||
|
||
assert.Equal(t, "serverdisk/create", c.lastPath, "correct path is used") | ||
assert.Equal(t, 200, disk.SizeInGIB, "size is correct") | ||
assert.Equal(t, "Diskett", disk.Name, "correct name variable") | ||
} | ||
|
||
func TestServerDisk_UpdateName(t *testing.T) { | ||
c := &mockClient{body: `{ "response": { "disk": { "id": "aaaaa-bbbbbb-cccccc", | ||
"sizeingib": 200, | ||
"name": "Extradisk", | ||
"scsiid": 1 | ||
}}}`} | ||
s := ServerDisksService{client: c} | ||
|
||
params := EditServerDiskParams{ | ||
ID: "aaaaa-bbbbbb-cccccc", | ||
Name: "Extradisk", | ||
} | ||
|
||
disk, _ := s.UpdateName(context.Background(), params) | ||
|
||
assert.Equal(t, "serverdisk/updatename", c.lastPath, "correct path is used") | ||
assert.Equal(t, 200, disk.SizeInGIB, "size is correct") | ||
assert.Equal(t, "Extradisk", disk.Name, "correct name variable") | ||
} | ||
|
||
func TestServerDisk_Reconfigure(t *testing.T) { | ||
c := &mockClient{body: `{ "response": { "disk": { "id": "aaaaa-bbbbbb-cccccc", | ||
"sizeingib": 250, | ||
"name": "Diskett", | ||
"scsiid": 1 | ||
}}}`} | ||
s := ServerDisksService{client: c} | ||
|
||
params := EditServerDiskParams{ | ||
ID: "aaaaa-bbbbbb-cccccc", | ||
SizeInGIB: 250, | ||
} | ||
|
||
disk, _ := s.Reconfigure(context.Background(), params) | ||
|
||
assert.Equal(t, "serverdisk/reconfigure", c.lastPath, "correct path is used") | ||
assert.Equal(t, 250, disk.SizeInGIB, "size is correct") | ||
assert.Equal(t, "Diskett", disk.Name, "correct name variable") | ||
} | ||
|
||
func TestServerDisk_Delete(t *testing.T) { | ||
c := &mockClient{} | ||
s := ServerDisksService{client: c} | ||
|
||
id := "aaaaa-bbbbbb-cccccc" | ||
|
||
_ = s.Delete(context.Background(), id) | ||
|
||
assert.Equal(t, "serverdisk/delete", c.lastPath, "correct path is used") | ||
} | ||
|
||
func TestServerDisk_Limits(t *testing.T) { | ||
c := &mockClient{body: `{ "response": { "limits": { "minsizeingib": 10, | ||
"maxsizeingib": 1024, | ||
"currentnumdisks": 1, | ||
"maxnumdisks": 3 | ||
}}}`} | ||
s := ServerDisksService{client: c} | ||
|
||
limits, _ := s.Limits(context.Background(), "wps12345") | ||
|
||
assert.Equal(t, "serverdisk/limits", c.lastPath, "correct path is used") | ||
assert.Equal(t, 1024, limits.MaxSizeInGIB, "max size is correct") | ||
assert.Equal(t, 3, limits.MaxNumDisks, "max number of disks correct") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters