Skip to content

Commit

Permalink
[refactor] refactor the group of snapshot api v2
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Jun 1, 2024
1 parent 710c101 commit 3e5c676
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions test/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func TestListSnapshotFailure(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := v2.NewListSnapshotsByBlockVolumeIdRequest(1, 10, "fsffsfsdfdsfsdf")
_, sdkerr := vngcloud.VServerGateway().V2().VolumeService().ListSnapshotByVolumeId(opt)
_, sdkerr := vngcloud.VServerGateway().V2().VolumeService().ListSnapshotsByBlockVolumeId(opt)

t.Log("Result: ", sdkerr)
t.Log("PASS")
Expand All @@ -17,7 +17,7 @@ func TestListSnapshotFailure(t *ltesting.T) {
func TestListSnapshotSuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := v2.NewListSnapshotsByBlockVolumeIdRequest(1, 10, "vol-d360fd83-948d-4efa-ab46-aab97328e275")
snapshots, sdkerr := vngcloud.VServerGateway().V2().VolumeService().ListSnapshotByVolumeId(opt)
snapshots, sdkerr := vngcloud.VServerGateway().V2().VolumeService().ListSnapshotsByBlockVolumeId(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %v", sdkerr)
}
Expand All @@ -32,16 +32,16 @@ func TestListSnapshotSuccess(t *ltesting.T) {

func TestCreateSnapshotFailure(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := v2.NewCreateSnapshotByVolumeIdRequest("teasdadasdadst", "vol-d360fd83-948d-4efa-ab46-aab97328e275").WithPermanently(true)
_, sdkerr := vngcloud.VServerGateway().V2().VolumeService().CreateSnapshotByVolumeId(opt)
opt := v2.NewCreateSnapshotByBlockVolumeIdRequest("teasdadasdadst", "vol-d360fd83-948d-4efa-ab46-aab97328e275").WithPermanently(true)
_, sdkerr := vngcloud.VServerGateway().V2().VolumeService().CreateSnapshotByBlockVolumeId(opt)

t.Log("Result: ", sdkerr)
t.Log("PASS")
}

func TestDeleteSnapshot(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := v2.NewDeleteSnapshotByIdRequest("snap-vol-pt-03e5891b-1f89-4eb9-b2e6-be599f4e2a4b")
opt := v2.NewDeleteSnapshotByIdRequest("snap-vol-pt-03e5891b-xxxx-4eb9-b2e6-be599f4e2a4b")
sdkerr := vngcloud.VServerGateway().V2().VolumeService().DeleteSnapshotById(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %v", sdkerr)
Expand Down
4 changes: 2 additions & 2 deletions vngcloud/services/volume/ivolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type IVolumeServiceV2 interface {
GetUnderBlockVolumeId(popts lsvolumeSvcV2.IGetUnderBlockVolumeIdRequest) (*lsentity.Volume, lserr.ISdkError)

// Snapshot
ListSnapshotByVolumeId(popts lsvolumeSvcV2.IListSnapshotsByBlockVolumeIdRequest) (*lsentity.ListSnapshots, lserr.ISdkError)
CreateSnapshotByVolumeId(popts lsvolumeSvcV2.ICreateSnapshotByVolumeIdRequest) (*lsentity.Snapshot, lserr.ISdkError)
ListSnapshotsByBlockVolumeId(popts lsvolumeSvcV2.IListSnapshotsByBlockVolumeIdRequest) (*lsentity.ListSnapshots, lserr.ISdkError)
CreateSnapshotByBlockVolumeId(popts lsvolumeSvcV2.ICreateSnapshotByBlockVolumeIdRequest) (*lsentity.Snapshot, lserr.ISdkError)
DeleteSnapshotById(popts lsvolumeSvcV2.IDeleteSnapshotByIdRequest) lserr.ISdkError
}
8 changes: 4 additions & 4 deletions vngcloud/services/volume/v2/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ type IListSnapshotsByBlockVolumeIdRequest interface {
GetDefaultQuery() string
}

type ICreateSnapshotByVolumeIdRequest interface {
type ICreateSnapshotByBlockVolumeIdRequest interface {
GetBlockVolumeId() string
ToRequestBody() interface{}
WithDescription(pdesc string) ICreateSnapshotByVolumeIdRequest
WithPermanently(pval bool) ICreateSnapshotByVolumeIdRequest
WithRetainedDay(pval uint64) ICreateSnapshotByVolumeIdRequest
WithDescription(pdesc string) ICreateSnapshotByBlockVolumeIdRequest
WithPermanently(pval bool) ICreateSnapshotByBlockVolumeIdRequest
WithRetainedDay(pval uint64) ICreateSnapshotByBlockVolumeIdRequest
}

type IDeleteSnapshotByIdRequest interface {
Expand Down
6 changes: 3 additions & 3 deletions vngcloud/services/volume/v2/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
lserr "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/sdk_error"
)

func (s *VolumeServiceV2) ListSnapshotByVolumeId(popts IListSnapshotsByBlockVolumeIdRequest) (*lsentity.ListSnapshots, lserr.ISdkError) {
func (s *VolumeServiceV2) ListSnapshotsByBlockVolumeId(popts IListSnapshotsByBlockVolumeIdRequest) (*lsentity.ListSnapshots, lserr.ISdkError) {
url := listSnapshotsByBlockVolumeIdUrl(s.VServerClient, popts)
resp := new(ListSnapshotByBlockVolumeIdResponse)
resp := new(ListSnapshotsByBlockVolumeIdResponse)
errResp := lserr.NewErrorResponse(lserr.NormalErrorType)
req := lsclient.NewRequest().
WithOkCodes(200).
Expand All @@ -25,7 +25,7 @@ func (s *VolumeServiceV2) ListSnapshotByVolumeId(popts IListSnapshotsByBlockVolu
return resp.ToEntityListSnapshots(), nil
}

func (s *VolumeServiceV2) CreateSnapshotByVolumeId(popts ICreateSnapshotByVolumeIdRequest) (*lsentity.Snapshot, lserr.ISdkError) {
func (s *VolumeServiceV2) CreateSnapshotByBlockVolumeId(popts ICreateSnapshotByBlockVolumeIdRequest) (*lsentity.Snapshot, lserr.ISdkError) {
url := createSnapshotByBlockVolumeIdUrl(s.VServerClient, popts)
resp := new(CreateSnapshotByBlockVolumeIdResponse)
errResp := lserr.NewErrorResponse(lserr.NormalErrorType)
Expand Down
14 changes: 7 additions & 7 deletions vngcloud/services/volume/v2/snapshot_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func NewListSnapshotsByBlockVolumeIdRequest(ppage, psize int, pblockVolumeId str
return opt
}

func NewCreateSnapshotByVolumeIdRequest(pname, pblockVolumeId string) ICreateSnapshotByVolumeIdRequest {
opt := new(CreateSnapshotByVolumeIdRequest)
func NewCreateSnapshotByBlockVolumeIdRequest(pname, pblockVolumeId string) ICreateSnapshotByBlockVolumeIdRequest {
opt := new(CreateSnapshotByBlockVolumeIdRequest)
opt.Name = pname
opt.BlockVolumeId = pblockVolumeId

Expand All @@ -39,7 +39,7 @@ type ListSnapshotsByBlockVolumeIdRequest struct {
lscommon.BlockVolumeCommon
}

type CreateSnapshotByVolumeIdRequest struct {
type CreateSnapshotByBlockVolumeIdRequest struct {
Name string `json:"name"`
Description string `json:"description"`
Permanently bool `json:"isPermanently"`
Expand Down Expand Up @@ -68,21 +68,21 @@ func (s *ListSnapshotsByBlockVolumeIdRequest) ToQuery() (string, error) {
return url.String(), err
}

func (s *CreateSnapshotByVolumeIdRequest) ToRequestBody() interface{} {
func (s *CreateSnapshotByBlockVolumeIdRequest) ToRequestBody() interface{} {
return s
}

func (s *CreateSnapshotByVolumeIdRequest) WithDescription(pdesc string) ICreateSnapshotByVolumeIdRequest {
func (s *CreateSnapshotByBlockVolumeIdRequest) WithDescription(pdesc string) ICreateSnapshotByBlockVolumeIdRequest {
s.Description = pdesc
return s
}

func (s *CreateSnapshotByVolumeIdRequest) WithPermanently(pval bool) ICreateSnapshotByVolumeIdRequest {
func (s *CreateSnapshotByBlockVolumeIdRequest) WithPermanently(pval bool) ICreateSnapshotByBlockVolumeIdRequest {
s.Permanently = pval
return s
}

func (s *CreateSnapshotByVolumeIdRequest) WithRetainedDay(pval uint64) ICreateSnapshotByVolumeIdRequest {
func (s *CreateSnapshotByBlockVolumeIdRequest) WithRetainedDay(pval uint64) ICreateSnapshotByBlockVolumeIdRequest {
s.RetainedDay = pval
return s
}
4 changes: 2 additions & 2 deletions vngcloud/services/volume/v2/snapshot_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v2

import lsentity "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/entity"

type ListSnapshotByBlockVolumeIdResponse struct {
type ListSnapshotsByBlockVolumeIdResponse struct {
Items []Snapshot `json:"items"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
Expand Down Expand Up @@ -68,7 +68,7 @@ type (
}
)

func (s *ListSnapshotByBlockVolumeIdResponse) ToEntityListSnapshots() *lsentity.ListSnapshots {
func (s *ListSnapshotsByBlockVolumeIdResponse) ToEntityListSnapshots() *lsentity.ListSnapshots {
sl := new(lsentity.ListSnapshots)

for _, item := range s.Items {
Expand Down
2 changes: 1 addition & 1 deletion vngcloud/services/volume/v2/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func listSnapshotsByBlockVolumeIdUrl(psc lsclient.IServiceClient, popts IListSna
) + query
}

func createSnapshotByBlockVolumeIdUrl(psc lsclient.IServiceClient, popts ICreateSnapshotByVolumeIdRequest) string {
func createSnapshotByBlockVolumeIdUrl(psc lsclient.IServiceClient, popts ICreateSnapshotByBlockVolumeIdRequest) string {
return psc.ServiceURL(
psc.GetProjectId(),
"volumes",
Expand Down

0 comments on commit 3e5c676

Please sign in to comment.