Skip to content

Commit

Permalink
fix(objsto): omit empty labels when creating managed object storage
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta committed Dec 11, 2023
1 parent b23b343 commit 2950bed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion upcloud/request/managed_object_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (r *GetManagedObjectStorageRegionRequest) RequestURL() string {
// CreateManagedObjectStorageRequest represents a request for creating a new Managed Object Storage service
type CreateManagedObjectStorageRequest struct {
ConfiguredStatus upcloud.ManagedObjectStorageConfiguredStatus `json:"configured_status"`
Labels []upcloud.Label `json:"labels"`
Labels []upcloud.Label `json:"labels,omitempty"`
Networks []upcloud.ManagedObjectStorageNetwork `json:"networks"`
Region string `json:"region"`
Users []ManagedObjectStorageUser `json:"users"`
Expand Down
19 changes: 19 additions & 0 deletions upcloud/request/managed_object_storage_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package request

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -23,6 +24,24 @@ func TestCreateManagedObjectStorageRequest_RequestURL(t *testing.T) {
assert.Equal(t, "/object-storage-2", req.RequestURL())
}

func TestCreateManagedObjectStorageRequest_MarshalJSON(t *testing.T) {
t.Run("TestMinimal", func(t *testing.T) {
req := CreateManagedObjectStorageRequest{
Region: "europe-1",
}
d, err := json.Marshal(&req)
assert.NoError(t, err)

const expected = `{
"configured_status":"",
"networks":null,
"region":"europe-1",
"users":null
}`
assert.JSONEq(t, expected, string(d))
})
}

func TestGetManagedObjectStoragesRequest_RequestURL(t *testing.T) {
req := &GetManagedObjectStoragesRequest{}
assert.Equal(t, "/object-storage-2", req.RequestURL())
Expand Down

0 comments on commit 2950bed

Please sign in to comment.