Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCLOUD2-16691 Subnet is optional when creating a sfs #145

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions gcore/file_share/v1/file_shares/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
"github.com/G-Core/gcorelabscloud-go/pagination"
)


// List returns a Pager which allows you to iterate over a collection of
// file shares.
// file shares.
func List(c *gcorecloud.ServiceClient) pagination.Pager {
url := listURL(c)
return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
Expand All @@ -34,7 +33,7 @@ type CreateOptsBuilder interface {

type FileShareNetworkOpts struct {
NetworkID string `json:"network_id,omitempty" validate:"uuid4"`
SubnetID string `json:"subnet_id,omitempty" validate:"uuid4"`
SubnetID string `json:"subnet_id,omitempty" validate:"omitempty,uuid4"`
}

type CreateAccessRuleOpts struct {
Expand All @@ -60,7 +59,6 @@ func (opts CreateOpts) ToFileShareCreateMap() (map[string]interface{}, error) {
return gcorecloud.BuildRequestBody(opts, "")
}


// Validate
func (opts CreateOpts) Validate() error {
return gcorecloud.TranslateValidationError(gcorecloud.Validate.Struct(opts))
Expand Down Expand Up @@ -92,7 +90,6 @@ type ResizeOptsBuilder interface {
ToFileShareResizeMap() (map[string]interface{}, error)
}


// ToFileShareUpdateMap builds a request body from UpdateOpts.
func (opts UpdateOpts) ToFileShareUpdateMap() (map[string]interface{}, error) {
if err := opts.Validate(); err != nil {
Expand Down Expand Up @@ -173,9 +170,8 @@ func ListAll(client *gcorecloud.ServiceClient) ([]FileShare, error) {

}


// List returns a Pager which allows you to iterate over a collection of
// file shares.
// file shares.
func ListAccessRules(c *gcorecloud.ServiceClient, fileShareID string) pagination.Pager {
url := accessRuleURL(c, fileShareID)
return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
Expand Down
6 changes: 6 additions & 0 deletions gcore/file_share/v1/file_shares/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ const MetadataListResponse = `
}
`

var fileShareNetworkConfigWithoutSubnet = `
{
"network_id": "9b17dd07-1281-4fe0-8c13-d80c5725e297"
}
`

var createdTimeString = "2023-08-01T14:32:41.465031"
var createdTimeParsed, _ = time.Parse(gcorecloud.RFC3339MilliNoZ, createdTimeString)
var createdTime = gcorecloud.JSONRFC3339MilliNoZ{Time: createdTimeParsed}
Expand Down
31 changes: 31 additions & 0 deletions gcore/file_share/v1/file_shares/testing/network_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package testing

import (
"encoding/json"
"testing"

gcorecloud "github.com/G-Core/gcorelabscloud-go"
sfs "github.com/G-Core/gcorelabscloud-go/gcore/file_share/v1/file_shares"
"github.com/stretchr/testify/require"
)

func TestFileShareSubnetNotUUIDValidate(t *testing.T) {
opts := sfs.FileShareNetworkOpts{
NetworkID: "9b17dd07-1281-4fe0-8c13-d80c5725e297",
SubnetID: "0:0:0:0:0:ffff:192.1.56.10",
}
err := gcorecloud.Validate.Struct(opts)
require.Error(t, err)
require.Contains(t, err.Error(), "Field validation for 'SubnetID' failed on the 'uuid4'")
}

func TestFileShareSubnetOmittedOnEmptyValidate(t *testing.T) {
opts := sfs.FileShareNetworkOpts{
NetworkID: "9b17dd07-1281-4fe0-8c13-d80c5725e297",
}
err := gcorecloud.Validate.Struct(opts)
require.NoError(t, err)
s, err := json.Marshal(opts)
require.NoError(t, err)
require.JSONEq(t, fileShareNetworkConfigWithoutSubnet, string(s))
}
Loading