-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5dd85f
commit 077efe1
Showing
12 changed files
with
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package test | ||
|
||
import ( | ||
lsnetworkSvcV2 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/network/v2" | ||
ltesting "testing" | ||
) | ||
|
||
func TestGetNetworkByIdFailure(t *ltesting.T) { | ||
vngcloud := validSdkConfig() | ||
opt := lsnetworkSvcV2.NewGetNetworkByIdRequest("net-4f35f173-e0fe-4202-9c2b-5121b558bcd2") | ||
network, err := vngcloud.VServerGateway().V2().NetworkService().GetNetworkById(opt) | ||
|
||
if err == nil { | ||
t.Errorf("Expect error not to be nil but got nil") | ||
} | ||
|
||
if network != nil { | ||
t.Errorf("Expect portal to be nil but got %+v", network) | ||
} | ||
|
||
t.Log("RESULT:", err) | ||
t.Log("PASS") | ||
} | ||
|
||
func TestGetNetworkByIdSuccess(t *ltesting.T) { | ||
vngcloud := validSdkConfig() | ||
opt := lsnetworkSvcV2.NewGetNetworkByIdRequest("net-4f35f173-e0fe-4202-9c2b-5121b558bcd3") | ||
network, err := vngcloud.VServerGateway().V2().NetworkService().GetNetworkById(opt) | ||
|
||
if err != nil { | ||
t.Fatalf("Expect error to be nil but got %+v", err) | ||
} | ||
|
||
if network == nil { | ||
t.Fatalf("Expect portal not to be nil but got nil") | ||
} | ||
|
||
t.Log("RESULT:", network) | ||
t.Log("PASS") | ||
} |
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,10 @@ | ||
package entity | ||
|
||
type Network struct { | ||
Status string | ||
ElasticIps []string | ||
Name string | ||
Id string | ||
CreatedAt string | ||
Cidr string | ||
} |
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,22 @@ | ||
package sdk_error | ||
|
||
import lstr "strings" | ||
|
||
const ( | ||
patternNetworkNotFound = "is not found" | ||
) | ||
|
||
func WithErrorNetworkNotFound(perrResp IErrorRespone) func(sdkError ISdkError) { | ||
return func(sdkError ISdkError) { | ||
if perrResp == nil { | ||
return | ||
} | ||
|
||
errMsg := perrResp.GetMessage() | ||
if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternNetworkNotFound) { | ||
sdkError.WithErrorCode(EcVServerNetworkNotFound). | ||
WithMessage(errMsg). | ||
WithErrors(perrResp.GetError()) | ||
} | ||
} | ||
} |
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
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,27 @@ | ||
package v2 | ||
|
||
import ( | ||
lsclient "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/client" | ||
lsentity "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/entity" | ||
lserr "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/sdk_error" | ||
) | ||
|
||
func (s *NetworkServiceV2) GetNetworkById(popts IGetNetworkByIdRequest) (*lsentity.Network, lserr.ISdkError) { | ||
url := getNetworkByIdUrl(s.VserverClient, popts) | ||
resp := new(GetNetworkByIdResponse) | ||
errResp := lserr.NewErrorResponse(lserr.NormalErrorType) | ||
req := lsclient.NewRequest(). | ||
WithOkCodes(200). | ||
WithJsonResponse(resp). | ||
WithJsonError(errResp) | ||
|
||
if _, sdkErr := s.VserverClient.Get(url, req); sdkErr != nil { | ||
return nil, lserr.SdkErrorHandler(sdkErr, errResp, | ||
lserr.WithErrorNetworkNotFound(errResp)). | ||
WithKVparameters( | ||
"networkId", popts.GetNetworkId(), | ||
"projectId", s.getProjectId()) | ||
} | ||
|
||
return resp.ToEntityNetwork(), nil | ||
} |
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,11 @@ | ||
package v2 | ||
|
||
func NewGetNetworkByIdRequest(pnetworkId string) IGetNetworkByIdRequest { | ||
opt := new(GetNetworkByIdRequest) | ||
opt.NetworkId = pnetworkId | ||
return opt | ||
} | ||
|
||
type GetNetworkByIdRequest struct { | ||
NetworkCommon | ||
} |
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,23 @@ | ||
package v2 | ||
|
||
import lsentity "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/entity" | ||
|
||
type GetNetworkByIdResponse struct { | ||
Status string `json:"status"` | ||
ElasticIps []string `json:"elasticIps"` | ||
DisplayName string `json:"displayName"` | ||
ID string `json:"id"` | ||
CreatedAt string `json:"createdAt"` | ||
Cidr string `json:"cidr"` | ||
} | ||
|
||
func (s *GetNetworkByIdResponse) ToEntityNetwork() *lsentity.Network { | ||
return &lsentity.Network{ | ||
Status: s.Status, | ||
ElasticIps: s.ElasticIps, | ||
Name: s.DisplayName, | ||
Id: s.ID, | ||
CreatedAt: s.CreatedAt, | ||
Cidr: s.Cidr, | ||
} | ||
} |
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