From 518aa4f166345d9b3d3d4ad20575f04bda432250 Mon Sep 17 00:00:00 2001 From: Eka Putra Date: Fri, 8 Nov 2024 23:44:06 +0800 Subject: [PATCH] added client for blockstorage --- README.md | 4 +- blockstorage/blockstorage.go | 97 ++++++++++++++++++++++ blockstorage/blockstorage_test.go | 114 ++++++++++++++++++++++++++ blockstorage/types.go | 25 ++++++ go.mod | 5 +- go.sum | 2 + location/location.go | 20 ++--- location/location_test.go | 2 +- objectstorage/objectstorage.go | 122 +++++++++++++--------------- objectstorage/objectstorage_test.go | 62 +++++++------- 10 files changed, 342 insertions(+), 111 deletions(-) create mode 100644 blockstorage/blockstorage_test.go create mode 100644 blockstorage/types.go diff --git a/README.md b/README.md index 84829fb..7f355fe 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Progress: - [x] Locations - [x] Object storage -- [ ] Block storage +- [x] Block storage - [ ] Floating IP - [ ] Load balancer - [ ] Managed services @@ -14,4 +14,4 @@ Progress: - [ ] Virtual Private Cloud (VPC) -> Disclaimer: This library is created solely based on information that are available on IDCloudHost API documentation website https://api.idcloudhost.com. I/We (the authors) ONLY maintains/fixing-bugs/responsible for issues that are in the scope of this library, any platform issues should be addressed directly to the IDCloudHost official support. +> Disclaimer: This library is created solely based on information that are available on IDCloudHost API documentation website https://api.idcloudhost.com. The author(s) ONLY maintains/fixing-bugs/responsible for issues that are in the scope of this library, any platform issues should be addressed directly to the IDCloudHost official support. diff --git a/blockstorage/blockstorage.go b/blockstorage/blockstorage.go index 5ee1af4..20cb64a 100644 --- a/blockstorage/blockstorage.go +++ b/blockstorage/blockstorage.go @@ -1 +1,98 @@ package blockstorage + +import ( + "context" + "fmt" + "net/url" + "strconv" + + "github.com/ekaputra07/idcloudhost-go/http" + "github.com/gorilla/schema" +) + +func NewClient() *Client { + return &Client{ + H: http.DefaultClient, + } +} + +// ListDisks https://api.idcloudhost.com/#list-disks +func (c *Client) LisDisks(ctx context.Context) *http.ClientResponse { + rc := http.RequestConfig{ + Method: "GET", + Path: "/v1/storage/disks", + } + return c.H.FormRequest(ctx, rc) +} + +// CreateDisk https://api.idcloudhost.com/#create-disk +func (c *Client) CreateDisk(ctx context.Context, cfg CreateDiskConfig) *http.ClientResponse { + enc := schema.NewEncoder() + d := url.Values{} + if err := enc.Encode(cfg, d); err != nil { + return &http.ClientResponse{Error: err} + } + + rc := http.RequestConfig{ + Method: "POST", + Path: "/v1/storage/disks", + Data: d, + } + return c.H.FormRequest(ctx, rc) +} + +// GetDisk https://api.idcloudhost.com/#get-disk +func (c *Client) GetDisk(ctx context.Context, diskId string) *http.ClientResponse { + rc := http.RequestConfig{ + Method: "GET", + Path: fmt.Sprintf("/v1/storage/disks/%s", diskId), + } + return c.H.FormRequest(ctx, rc) +} + +// DeleteDisk https://api.idcloudhost.com/#delete-disk +func (c *Client) DeleteDisk(ctx context.Context, diskId string) *http.ClientResponse { + rc := http.RequestConfig{ + Method: "DELETE", + Path: fmt.Sprintf("/v1/storage/disks/%s", diskId), + } + return c.H.FormRequest(ctx, rc) +} + +// AttachDiskToVM https://api.idcloudhost.com/#attach-disk +func (c *Client) AttachDiskToVM(ctx context.Context, diskId, vmId string) *http.ClientResponse { + d := url.Values{ + "uuid": []string{vmId}, + "storage_uuid": []string{diskId}, + } + rc := http.RequestConfig{ + Method: "POST", + Path: "/v1/user-resource/vm/storage/attach", + Data: d, + } + return c.H.FormRequest(ctx, rc) +} + +// DetachDiskFromVM https://api.idcloudhost.com/#detach-disk +func (c *Client) DetachDiskFromVM(ctx context.Context, diskId, vmId string) *http.ClientResponse { + d := url.Values{ + "uuid": []string{vmId}, + "storage_uuid": []string{diskId}, + } + rc := http.RequestConfig{ + Method: "POST", + Path: "/v1/user-resource/vm/storage/detach", + Data: d, + } + return c.H.FormRequest(ctx, rc) +} + +// UpdateDiskBillingAccount https://api.idcloudhost.com/#modify-disk-info +func (c *Client) UpdateDiskBillingAccount(ctx context.Context, diskId string, billingAccountId int) *http.ClientResponse { + rc := http.RequestConfig{ + Method: "PATCH", + Path: fmt.Sprintf("/v1/storage/disks/%s", diskId), + Data: url.Values{"billing_account_id": []string{strconv.Itoa(billingAccountId)}}, + } + return c.H.FormRequest(ctx, rc) +} diff --git a/blockstorage/blockstorage_test.go b/blockstorage/blockstorage_test.go new file mode 100644 index 0000000..d97c9c4 --- /dev/null +++ b/blockstorage/blockstorage_test.go @@ -0,0 +1,114 @@ +package blockstorage + +import ( + "context" + "net/http" + "strconv" + "testing" + + h "github.com/ekaputra07/idcloudhost-go/http" + "github.com/stretchr/testify/assert" +) + +func TestListDisks(t *testing.T) { + c, s := h.MockClientServer(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "GET", r.Method) + assert.Equal(t, "/v1/storage/disks", r.RequestURI) + }) + defer s.Close() + + bs := Client{H: c} + bs.LisDisks(context.Background()) +} + +func TestCreateDisk(t *testing.T) { + config := CreateDiskConfig{ + SizeGb: 10, + BillingAccountId: 123, + SourceImageType: ImageTypeOSBase, + SourceImage: "ubuntu_20.04", + } + c, s := h.MockClientServer(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "POST", r.Method) + assert.Equal(t, "/v1/storage/disks", r.RequestURI) + + _ = r.ParseForm() + + assert.Equal(t, strconv.Itoa(config.SizeGb), r.Form.Get("size_gb")) + assert.Equal(t, strconv.Itoa(config.BillingAccountId), r.Form.Get("billing_account_id")) + assert.Equal(t, string(ImageTypeOSBase), r.Form.Get("source_image_type")) + assert.Equal(t, config.SourceImage, r.Form.Get("source_image")) + }) + defer s.Close() + + bs := Client{H: c} + bs.CreateDisk(context.Background(), config) +} + +func TestGetDisk(t *testing.T) { + id := "testId" + c, s := h.MockClientServer(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "GET", r.Method) + assert.Equal(t, "/v1/storage/disks/testId", r.RequestURI) + }) + defer s.Close() + + bs := Client{H: c} + bs.GetDisk(context.Background(), id) +} + +func TestDeleteDisk(t *testing.T) { + id := "testId" + c, s := h.MockClientServer(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "DELETE", r.Method) + assert.Equal(t, "/v1/storage/disks/testId", r.RequestURI) + }) + defer s.Close() + + bs := Client{H: c} + bs.DeleteDisk(context.Background(), id) +} + +func TestAttachDiskToVM(t *testing.T) { + c, s := h.MockClientServer(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "POST", r.Method) + assert.Equal(t, "/v1/user-resource/vm/storage/attach", r.RequestURI) + + _ = r.ParseForm() + assert.Equal(t, "vmId", r.Form.Get("uuid")) + assert.Equal(t, "diskId", r.Form.Get("storage_uuid")) + }) + defer s.Close() + + bs := Client{H: c} + bs.AttachDiskToVM(context.Background(), "diskId", "vmId") +} + +func TestDetachDiskFromVM(t *testing.T) { + c, s := h.MockClientServer(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "POST", r.Method) + assert.Equal(t, "/v1/user-resource/vm/storage/detach", r.RequestURI) + + _ = r.ParseForm() + assert.Equal(t, "vmId", r.Form.Get("uuid")) + assert.Equal(t, "diskId", r.Form.Get("storage_uuid")) + }) + defer s.Close() + + bs := Client{H: c} + bs.DetachDiskFromVM(context.Background(), "diskId", "vmId") +} + +func TestUpdateBucketBillingAccount(t *testing.T) { + c, s := h.MockClientServer(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "PATCH", r.Method) + assert.Equal(t, "/v1/storage/disks/testId", r.RequestURI) + + _ = r.ParseForm() + assert.Equal(t, "123", r.Form.Get("billing_account_id")) + }) + defer s.Close() + + bs := Client{H: c} + bs.UpdateDiskBillingAccount(context.Background(), "testId", 123) +} diff --git a/blockstorage/types.go b/blockstorage/types.go new file mode 100644 index 0000000..bedabcb --- /dev/null +++ b/blockstorage/types.go @@ -0,0 +1,25 @@ +package blockstorage + +import ( + "github.com/ekaputra07/idcloudhost-go/http" +) + +type Client struct { + H *http.Client +} + +type SourceImageType string + +const ( + ImageTypeOSBase SourceImageType = "OS_BASE" + ImageTypeDisk SourceImageType = "DISK" + ImageTypeSnapshot SourceImageType = "SNAPSHOT" + ImageTypeEmpty SourceImageType = "EMPTY" +) + +type CreateDiskConfig struct { + SizeGb int `schema:"size_gb"` + BillingAccountId int `schema:"billing_account_id"` + SourceImageType SourceImageType `schema:"source_image_type,default:EMPTY"` + SourceImage string `schema:"source_image"` +} diff --git a/go.mod b/go.mod index 26de91c..efc547b 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,10 @@ module github.com/ekaputra07/idcloudhost-go go 1.20 -require github.com/stretchr/testify v1.9.0 +require ( + github.com/gorilla/schema v1.4.1 + github.com/stretchr/testify v1.9.0 +) require ( github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index 60ce688..fa68a8f 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E= +github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= diff --git a/location/location.go b/location/location.go index f127cf0..b49adf3 100644 --- a/location/location.go +++ b/location/location.go @@ -6,20 +6,20 @@ import ( "github.com/ekaputra07/idcloudhost-go/http" ) -type LocationClient struct { +func NewClient() *Client { + return &Client{ + H: http.DefaultClient, + } +} + +type Client struct { H *http.Client } -func (c *LocationClient) ListLocations(ctx context.Context) *http.ClientResponse { - cfg := http.RequestConfig{ +func (c *Client) ListLocations(ctx context.Context) *http.ClientResponse { + rc := http.RequestConfig{ Method: "GET", Path: "/v1/config/locations", } - return c.H.FormRequest(ctx, cfg) -} - -func NewClient() *LocationClient { - return &LocationClient{ - H: http.DefaultClient, - } + return c.H.FormRequest(ctx, rc) } diff --git a/location/location_test.go b/location/location_test.go index 42b3fbc..fba06e1 100644 --- a/location/location_test.go +++ b/location/location_test.go @@ -16,6 +16,6 @@ func TestListLocations(t *testing.T) { }) defer s.Close() - lc := LocationClient{H: c} + lc := Client{H: c} lc.ListLocations(context.Background()) } diff --git a/objectstorage/objectstorage.go b/objectstorage/objectstorage.go index 79f7f72..34c5612 100644 --- a/objectstorage/objectstorage.go +++ b/objectstorage/objectstorage.go @@ -3,148 +3,138 @@ package objectstorage import ( "context" "net/url" + "strconv" "github.com/ekaputra07/idcloudhost-go/http" ) -type ObjectStorageClient struct { - BillingAccountID string +func NewClient() *Client { + return &Client{ + H: http.DefaultClient, + } +} + +type Client struct { + BillingAccountId int H *http.Client } -// ForBillingAccount set the value of BillingAccountID -func (c *ObjectStorageClient) ForBillingAccount(id string) *ObjectStorageClient { - c.BillingAccountID = id +// ForBillingAccount set the value of BillingAccountId +func (c *Client) ForBillingAccount(id int) *Client { + c.BillingAccountId = id return c } // GetS3ApiURL https://api.idcloudhost.com/#s3-api-info -func (c *ObjectStorageClient) GetS3ApiURL(ctx context.Context) *http.ClientResponse { - cfg := http.RequestConfig{ +func (c *Client) GetS3ApiURL(ctx context.Context) *http.ClientResponse { + rc := http.RequestConfig{ Method: "GET", Path: "/v1/storage/api/s3", } - return c.H.FormRequest(ctx, cfg) + return c.H.FormRequest(ctx, rc) } // GetS3UserInfo https://api.idcloudhost.com/#get-s3-user -func (c *ObjectStorageClient) GetS3UserInfo(ctx context.Context) *http.ClientResponse { - cfg := http.RequestConfig{ +func (c *Client) GetS3UserInfo(ctx context.Context) *http.ClientResponse { + rc := http.RequestConfig{ Method: "GET", Path: "/v1/storage/user", } - return c.H.FormRequest(ctx, cfg) + return c.H.FormRequest(ctx, rc) } // GetS3UserKeys https://api.idcloudhost.com/#get-keys -func (c *ObjectStorageClient) GetS3UserKeys(ctx context.Context) *http.ClientResponse { - cfg := http.RequestConfig{ +func (c *Client) GetS3UserKeys(ctx context.Context) *http.ClientResponse { + rc := http.RequestConfig{ Method: "GET", Path: "/v1/storage/user/keys", } - return c.H.FormRequest(ctx, cfg) + return c.H.FormRequest(ctx, rc) } // GenerateS3UserKey https://api.idcloudhost.com/#generate-key -func (c *ObjectStorageClient) GenerateS3UserKey(ctx context.Context) *http.ClientResponse { - cfg := http.RequestConfig{ +func (c *Client) GenerateS3UserKey(ctx context.Context) *http.ClientResponse { + rc := http.RequestConfig{ Method: "POST", Path: "/v1/storage/user/keys", } - return c.H.FormRequest(ctx, cfg) + return c.H.FormRequest(ctx, rc) } // DeleteS3UserKey https://api.idcloudhost.com/#generate-key -func (c *ObjectStorageClient) DeleteS3UserKey(ctx context.Context, accessKey string) *http.ClientResponse { - q := url.Values{} - q.Add("access_key", accessKey) - - cfg := http.RequestConfig{ +func (c *Client) DeleteS3UserKey(ctx context.Context, accessKey string) *http.ClientResponse { + rc := http.RequestConfig{ Method: "DELETE", Path: "/v1/storage/user/keys", - Query: q, + Query: url.Values{"access_key": []string{accessKey}}, } - return c.H.FormRequest(ctx, cfg) + return c.H.FormRequest(ctx, rc) } // ListBuckets https://api.idcloudhost.com/#list-buckets -func (c *ObjectStorageClient) ListBuckets(ctx context.Context) *http.ClientResponse { - if c.BillingAccountID == "" { - cfg := http.RequestConfig{ +func (c *Client) ListBuckets(ctx context.Context) *http.ClientResponse { + if c.BillingAccountId == 0 { + rc := http.RequestConfig{ Method: "GET", Path: "/v1/storage/bucket/list", } - return c.H.FormRequest(ctx, cfg) + return c.H.FormRequest(ctx, rc) } - q := url.Values{} - q.Add("billing_account_id", c.BillingAccountID) - cfg := http.RequestConfig{ + rc := http.RequestConfig{ Method: "GET", Path: "/v1/storage/bucket/list", - Query: q, + Query: url.Values{"billing_account_id": []string{strconv.Itoa(c.BillingAccountId)}}, } - return c.H.FormRequest(ctx, cfg) + return c.H.FormRequest(ctx, rc) } // GetBucket https://api.idcloudhost.com/#get-bucket -func (c *ObjectStorageClient) GetBucket(ctx context.Context, name string) *http.ClientResponse { - q := url.Values{} - q.Add("name", name) - - cfg := http.RequestConfig{ +func (c *Client) GetBucket(ctx context.Context, bucketName string) *http.ClientResponse { + rc := http.RequestConfig{ Method: "GET", Path: "/v1/storage/bucket", - Query: q, + Query: url.Values{"name": []string{bucketName}}, } - return c.H.FormRequest(ctx, cfg) + return c.H.FormRequest(ctx, rc) } // CreateBucket https://api.idcloudhost.com/#create-bucket -func (c *ObjectStorageClient) CreateBucket(ctx context.Context, bucketName string) *http.ClientResponse { - d := url.Values{} - d.Add("name", bucketName) - if c.BillingAccountID != "" { - d.Add("billing_account_id", c.BillingAccountID) +func (c *Client) CreateBucket(ctx context.Context, bucketName string) *http.ClientResponse { + d := url.Values{"name": []string{bucketName}} + if c.BillingAccountId != 0 { + d.Add("billing_account_id", strconv.Itoa(c.BillingAccountId)) } - cfg := http.RequestConfig{ + rc := http.RequestConfig{ Method: "PUT", Path: "/v1/storage/bucket", Data: d, } - return c.H.FormRequest(ctx, cfg) + return c.H.FormRequest(ctx, rc) } // DeleteBucket https://api.idcloudhost.com/#delete-bucket -func (c *ObjectStorageClient) DeleteBucket(ctx context.Context, bucketName string) *http.ClientResponse { - q := url.Values{} - q.Add("name", bucketName) - - cfg := http.RequestConfig{ +func (c *Client) DeleteBucket(ctx context.Context, bucketName string) *http.ClientResponse { + rc := http.RequestConfig{ Method: "DELETE", Path: "/v1/storage/bucket", - Query: q, + Query: url.Values{"name": []string{bucketName}}, } - return c.H.FormRequest(ctx, cfg) + return c.H.FormRequest(ctx, rc) } // UpdateBucketBillingAccount https://api.idcloudhost.com/#modify-bucket -func (c *ObjectStorageClient) UpdateBucketBillingAccount(ctx context.Context, bucketName, billingAccountId string) *http.ClientResponse { - d := url.Values{} - d.Add("name", bucketName) - d.Add("billing_account_id", billingAccountId) +func (c *Client) UpdateBucketBillingAccount(ctx context.Context, bucketName string, billingAccountId int) *http.ClientResponse { + d := url.Values{ + "name": []string{bucketName}, + "billing_account_id": []string{strconv.Itoa(billingAccountId)}, + } - cfg := http.RequestConfig{ + rc := http.RequestConfig{ Method: "PATCH", Path: "/v1/storage/bucket", Data: d, } - return c.H.FormRequest(ctx, cfg) -} - -func NewClient() *ObjectStorageClient { - return &ObjectStorageClient{ - H: http.DefaultClient, - } + return c.H.FormRequest(ctx, rc) } diff --git a/objectstorage/objectstorage_test.go b/objectstorage/objectstorage_test.go index 36206b9..1012a64 100644 --- a/objectstorage/objectstorage_test.go +++ b/objectstorage/objectstorage_test.go @@ -10,8 +10,8 @@ import ( ) func ForBillingAccount(t *testing.T) { - c := NewClient().ForBillingAccount("test") - assert.Equal(t, "test", c.BillingAccountID) + c := NewClient().ForBillingAccount(123) + assert.Equal(t, 123, c.BillingAccountId) } func TestGetS3ApiURL(t *testing.T) { @@ -21,8 +21,8 @@ func TestGetS3ApiURL(t *testing.T) { }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.GetS3ApiURL(context.Background()) + os := Client{H: c} + os.GetS3ApiURL(context.Background()) } func TestGetS3UserInfo(t *testing.T) { @@ -32,8 +32,8 @@ func TestGetS3UserInfo(t *testing.T) { }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.GetS3UserInfo(context.Background()) + os := Client{H: c} + os.GetS3UserInfo(context.Background()) } func TestGetS3UserKeys(t *testing.T) { @@ -43,8 +43,8 @@ func TestGetS3UserKeys(t *testing.T) { }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.GetS3UserKeys(context.Background()) + os := Client{H: c} + os.GetS3UserKeys(context.Background()) } func TestGenerateS3UserKey(t *testing.T) { @@ -54,8 +54,8 @@ func TestGenerateS3UserKey(t *testing.T) { }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.GenerateS3UserKey(context.Background()) + os := Client{H: c} + os.GenerateS3UserKey(context.Background()) } func TestDeleteS3UserKey(t *testing.T) { @@ -65,8 +65,8 @@ func TestDeleteS3UserKey(t *testing.T) { }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.DeleteS3UserKey(context.Background(), "testKey") + os := Client{H: c} + os.DeleteS3UserKey(context.Background(), "testKey") } func TestListBuckets(t *testing.T) { @@ -76,20 +76,20 @@ func TestListBuckets(t *testing.T) { }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.ListBuckets(context.Background()) + os := Client{H: c} + os.ListBuckets(context.Background()) } func TestListBucketsWithBillingAccount(t *testing.T) { c, s := h.MockClientServer(func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, "GET", r.Method) - assert.Equal(t, "/v1/storage/bucket/list?billing_account_id=testId", r.RequestURI) + assert.Equal(t, "/v1/storage/bucket/list?billing_account_id=123", r.RequestURI) }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.BillingAccountID = "testId" - osc.ListBuckets(context.Background()) + os := Client{H: c} + os.BillingAccountId = 123 + os.ListBuckets(context.Background()) } func TestGetBucket(t *testing.T) { @@ -99,8 +99,8 @@ func TestGetBucket(t *testing.T) { }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.GetBucket(context.Background(), "testBucket") + os := Client{H: c} + os.GetBucket(context.Background(), "testBucket") } func TestCreateBucket(t *testing.T) { @@ -113,8 +113,8 @@ func TestCreateBucket(t *testing.T) { }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.CreateBucket(context.Background(), "testBucket") + os := Client{H: c} + os.CreateBucket(context.Background(), "testBucket") } func TestCreateBucketWithBillingAccount(t *testing.T) { @@ -124,13 +124,13 @@ func TestCreateBucketWithBillingAccount(t *testing.T) { _ = r.ParseForm() assert.Equal(t, "testBucket", r.Form.Get("name")) - assert.Equal(t, "testId", r.Form.Get("billing_account_id")) + assert.Equal(t, "123", r.Form.Get("billing_account_id")) }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.BillingAccountID = "testId" - osc.CreateBucket(context.Background(), "testBucket") + os := Client{H: c} + os.BillingAccountId = 123 + os.CreateBucket(context.Background(), "testBucket") } func TestDeleteBucket(t *testing.T) { @@ -140,8 +140,8 @@ func TestDeleteBucket(t *testing.T) { }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.DeleteBucket(context.Background(), "testBucket") + os := Client{H: c} + os.DeleteBucket(context.Background(), "testBucket") } func TestUpdateBucketBillingAccount(t *testing.T) { @@ -151,10 +151,10 @@ func TestUpdateBucketBillingAccount(t *testing.T) { _ = r.ParseForm() assert.Equal(t, "testBucket", r.Form.Get("name")) - assert.Equal(t, "testId", r.Form.Get("billing_account_id")) + assert.Equal(t, "123", r.Form.Get("billing_account_id")) }) defer s.Close() - osc := ObjectStorageClient{H: c} - osc.UpdateBucketBillingAccount(context.Background(), "testBucket", "testId") + os := Client{H: c} + os.UpdateBucketBillingAccount(context.Background(), "testBucket", 123) }