Skip to content

Commit

Permalink
fix: remove expand parameter from get vpc (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
publi0 authored Feb 26, 2025
1 parent 7ac03a0 commit 501e2ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cmd/examples/network/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func ExampleManageVPC(id string) {
ctx := context.Background()

// Get VPC details
vpc, err := networkClient.VPCs().Get(ctx, id, []string{network.SubnetsExpand})
vpc, err := networkClient.VPCs().Get(ctx, id)
if err != nil {
log.Fatal(err)
}
Expand Down
9 changes: 2 additions & 7 deletions network/vpcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"net/url"
"strconv"
"strings"

mgc_http "github.com/MagaluCloud/mgc-sdk-go/internal/http"
"github.com/MagaluCloud/mgc-sdk-go/internal/utils"
Expand Down Expand Up @@ -183,7 +182,7 @@ type VPCService interface {
List(ctx context.Context) ([]VPC, error)

// Get retrieves detailed information about a specific VPC
Get(ctx context.Context, id string, expand []string) (*VPC, error)
Get(ctx context.Context, id string) (*VPC, error)

// Create provisions a new VPC
Create(ctx context.Context, req CreateVPCRequest) (string, error)
Expand Down Expand Up @@ -235,12 +234,8 @@ func (s *vpcService) List(ctx context.Context) ([]VPC, error) {
}

// Get retrieves detailed information about a specific VPC
func (s *vpcService) Get(ctx context.Context, id string, expand []string) (*VPC, error) {
func (s *vpcService) Get(ctx context.Context, id string) (*VPC, error) {
path := fmt.Sprintf("/v0/vpcs/%s", id)
if len(expand) > 0 {
path = fmt.Sprintf("%s?expand=%s", path, strings.Join(expand, ","))
}

return mgc_http.ExecuteSimpleRequestWithRespBody[VPC](
ctx,
s.client.newRequest,
Expand Down
18 changes: 3 additions & 15 deletions network/vpcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"net/http/httptest"
"strconv"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -693,16 +692,14 @@ func TestVPCService_Get(t *testing.T) {
tests := []struct {
name string
id string
expand []string
response string
statusCode int
want *VPC
wantErr bool
}{
{
name: "successful get with expansion",
id: "vpc1",
expand: []string{SecurityGroupsExpand, SubnetsExpand},
name: "successful get with expansion",
id: "vpc1",
response: `{
"id": "vpc1",
"name": "prod-vpc",
Expand Down Expand Up @@ -756,18 +753,14 @@ func TestVPCService_Get(t *testing.T) {
assertEqual(t, fmt.Sprintf("/network/v0/vpcs/%s", tt.id), r.URL.Path)
assertEqual(t, http.MethodGet, r.Method)

if len(tt.expand) > 0 {
assertEqual(t, strings.Join(tt.expand, ","), r.URL.Query().Get("expand"))
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(tt.statusCode)
w.Write([]byte(tt.response))
}))
defer server.Close()

client := testVPCClient(server.URL)
vpc, err := client.Get(context.Background(), tt.id, tt.expand)
vpc, err := client.Get(context.Background(), tt.id)

if tt.wantErr {
assertError(t, err)
Expand All @@ -779,11 +772,6 @@ func TestVPCService_Get(t *testing.T) {
assertEqual(t, *tt.want.Name, *vpc.Name)
assertEqual(t, tt.want.Status, vpc.Status)

if len(tt.expand) > 0 {
assertEqual(t, len(*tt.want.SecurityGroups), len(*vpc.SecurityGroups))
assertEqual(t, len(*tt.want.Subnets), len(*vpc.Subnets))
}

if *tt.want.IsDefault {
assertEqual(t, *tt.want.IsDefault, *vpc.IsDefault)
}
Expand Down

0 comments on commit 501e2ca

Please sign in to comment.