From 35b3a27f4b4d667f1b942cc7f14b1214c94baba7 Mon Sep 17 00:00:00 2001 From: Ashwani Date: Wed, 27 Nov 2024 22:12:54 +0530 Subject: [PATCH] updated create/get response --- reserved_ipv6.go | 15 +++++++++------ reserved_ipv6_test.go | 14 +++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/reserved_ipv6.go b/reserved_ipv6.go index 3d016ce0..6981d13c 100644 --- a/reserved_ipv6.go +++ b/reserved_ipv6.go @@ -14,8 +14,8 @@ const reservedIPV6sBasePath = "v2/reserved_ipv6" // endpoints of the Digital Ocean API. type ReservedIPV6sService interface { List(context.Context, *ListOptions) (*ReservedIPV6List, *Response, error) - Get(context.Context, string) (*ReservedIPV6, *Response, error) - Create(context.Context, *ReservedIPV6CreateRequest) (*ReservedIPV6, *Response, error) + Get(context.Context, string) (*ReservedIPV6Resp, *Response, error) + Create(context.Context, *ReservedIPV6CreateRequest) (*ReservedIPV6Resp, *Response, error) Delete(context.Context, string) (*Response, error) } @@ -34,6 +34,9 @@ type ReservedIPV6 struct { ReservedAt time.Time `json:"reserved_at"` Droplet *Droplet `json:"droplet,omitempty"` } +type ReservedIPV6Resp struct { + ReservedIPV6 *ReservedIPV6 `json:"reserved_ipv6"` +} type ReservedIPV6List struct { ReservedIPV6s []ReservedIPV6 `json:"reserved_ipv6s"` @@ -84,7 +87,7 @@ func (r *ReservedIPV6sServiceOp) List(ctx context.Context, opt *ListOptions) (*R } // Get an individual reserved IPv6. -func (r *ReservedIPV6sServiceOp) Get(ctx context.Context, ip string) (*ReservedIPV6, *Response, error) { +func (r *ReservedIPV6sServiceOp) Get(ctx context.Context, ip string) (*ReservedIPV6Resp, *Response, error) { path := fmt.Sprintf("%s/%s", reservedIPV6sBasePath, ip) req, err := r.client.NewRequest(ctx, http.MethodGet, path, nil) @@ -92,7 +95,7 @@ func (r *ReservedIPV6sServiceOp) Get(ctx context.Context, ip string) (*ReservedI return nil, nil, err } - root := new(ReservedIPV6) + root := new(ReservedIPV6Resp) resp, err := r.client.Do(ctx, req, root) if err != nil { return nil, resp, err @@ -102,7 +105,7 @@ func (r *ReservedIPV6sServiceOp) Get(ctx context.Context, ip string) (*ReservedI } // Create a new IPv6 -func (r *ReservedIPV6sServiceOp) Create(ctx context.Context, reserveRequest *ReservedIPV6CreateRequest) (*ReservedIPV6, *Response, error) { +func (r *ReservedIPV6sServiceOp) Create(ctx context.Context, reserveRequest *ReservedIPV6CreateRequest) (*ReservedIPV6Resp, *Response, error) { path := reservedIPV6sBasePath req, err := r.client.NewRequest(ctx, http.MethodPost, path, reserveRequest) @@ -110,7 +113,7 @@ func (r *ReservedIPV6sServiceOp) Create(ctx context.Context, reserveRequest *Res return nil, nil, err } - root := new(ReservedIPV6) + root := new(ReservedIPV6Resp) resp, err := r.client.Do(ctx, req, root) if err != nil { return nil, resp, err diff --git a/reserved_ipv6_test.go b/reserved_ipv6_test.go index 73410bbf..a06f960b 100644 --- a/reserved_ipv6_test.go +++ b/reserved_ipv6_test.go @@ -30,7 +30,7 @@ func TestReservedIPV6s_Create(t *testing.T) { t.Errorf("Request body = %+v, expected %+v", v, reserveRequest) } - fmt.Fprint(w, `{"ip":"2604:a880:800:14::42c3:d000","region_slug":"nyc3","reserved_at":"`+nowTime.Format(time.RFC3339Nano)+`"}`) + fmt.Fprint(w, `{"reserved_ipv6":{"ip":"2604:a880:800:14::42c3:d000","region_slug":"nyc3","reserved_at":"`+nowTime.Format(time.RFC3339Nano)+`"}}`) }) reservedIP, _, err := client.ReservedIPV6s.Create(ctx, reserveRequest) @@ -38,10 +38,10 @@ func TestReservedIPV6s_Create(t *testing.T) { t.Errorf("ReservedIPV6s.Create returned error: %v", err) } - expected := &ReservedIPV6{RegionSlug: "nyc3", IP: "2604:a880:800:14::42c3:d000", ReservedAt: nowTime} + expected := &ReservedIPV6Resp{ReservedIPV6: &ReservedIPV6{RegionSlug: "nyc3", IP: "2604:a880:800:14::42c3:d000", ReservedAt: nowTime}} - if !equalReserveIPv6Objects(reservedIP, expected) { - t.Errorf("ReservedIPs.Create returned %+v, expected %+v", reservedIP, expected) + if !equalReserveIPv6Objects(reservedIP.ReservedIPV6, expected.ReservedIPV6) { + t.Errorf("ReservedIPV6s.Create returned %+v, expected %+v", reservedIP, expected) } } @@ -116,7 +116,7 @@ func TestReservedIPV6s_Get(t *testing.T) { nowTime := time.Now() mux.HandleFunc("/v2/reserved_ipv6/2604:a880:800:14::42c3:d001", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodGet) - fmt.Fprint(w, `{"region_slug":"nyc3","droplet":{"id":1},"ip":"2604:a880:800:14::42c3:d001", "reserved_at":"`+nowTime.Format(time.RFC3339Nano)+`"}`) + fmt.Fprint(w, `{"reserved_ipv6":{"region_slug":"nyc3","droplet":{"id":1},"ip":"2604:a880:800:14::42c3:d001", "reserved_at":"`+nowTime.Format(time.RFC3339Nano)+`"}}`) }) reservedIP, _, err := client.ReservedIPV6s.Get(ctx, "2604:a880:800:14::42c3:d001") @@ -124,8 +124,8 @@ func TestReservedIPV6s_Get(t *testing.T) { t.Errorf("ReservedIPV6s.Get returned error: %v", err) } - expected := &ReservedIPV6{RegionSlug: "nyc3", Droplet: &Droplet{ID: 1}, IP: "2604:a880:800:14::42c3:d001", ReservedAt: nowTime} - if !equalReserveIPv6Objects(reservedIP, expected) { + expected := &ReservedIPV6Resp{ReservedIPV6: &ReservedIPV6{RegionSlug: "nyc3", Droplet: &Droplet{ID: 1}, IP: "2604:a880:800:14::42c3:d001", ReservedAt: nowTime}} + if !equalReserveIPv6Objects(reservedIP.ReservedIPV6, expected.ReservedIPV6) { t.Errorf("ReservedIPV6s.Get returned %+v, expected %+v", reservedIP, expected) } }