Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
)

require (
github.com/fastly/go-fastly/v9 v9.2.2
github.com/fastly/go-fastly/v9 v9.3.1
github.com/hashicorp/cap v0.6.0
github.com/kennygrant/sanitize v1.2.4
github.com/mholt/archiver v3.1.1+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj6
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/dustinkirkland/golang-petname v0.0.0-20231002161417-6a283f1aaaf2 h1:S6Dco8FtAhEI/qkg/00H6RdEGC+MCy5GPiQ+xweNRFE=
github.com/dustinkirkland/golang-petname v0.0.0-20231002161417-6a283f1aaaf2/go.mod h1:8AuBTZBRSFqEYBPYULd+NN474/zZBLP+6WeT5S9xlAc=
github.com/fastly/go-fastly/v9 v9.2.2 h1:YNoinvf9vlPmsIbR6weT6XQ0l8nNPjS5DjC7ILwwaE8=
github.com/fastly/go-fastly/v9 v9.2.2/go.mod h1:5w2jgJBZqQEebOwM/rRg7wutAcpDTziiMYWb/6qdM7U=
github.com/fastly/go-fastly/v9 v9.3.1 h1:2UZUe8Kkz60aPrkDV82dpHkEqsT/J2qxOZxFhWEJJ2k=
github.com/fastly/go-fastly/v9 v9.3.1/go.mod h1:5w2jgJBZqQEebOwM/rRg7wutAcpDTziiMYWb/6qdM7U=
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible h1:FhrXlfhgGCS+uc6YwyiFUt04alnjpoX7vgDKJxS6Qbk=
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible/go.mod h1:U8UynVoU1SQaqD2I4ZqgYd5lx3A1ipQYn4aSt2Y5h6c=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
Expand Down
8 changes: 7 additions & 1 deletion pkg/commands/kvstore/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ type CreateCommand struct {
Input fastly.CreateKVStoreInput
}

// locations is a list of supported regional location options.
var locations = []string{"US", "EU", "ASIA", "AUS"}

// NewCreateCommand returns a usable command registered under the parent.
func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateCommand {
c := CreateCommand{
Base: argparser.Base{
Globals: g,
},
}

c.CmdClause = parent.Command("create", "Create a KV Store")
c.CmdClause.Flag("name", "Name of KV Store").Short('n').Required().StringVar(&c.Input.Name)
c.RegisterFlagBool(c.JSONFlag()) // --json
c.CmdClause.Flag("location", "Regional location of KV Store").Short('l').HintOptions(locations...).EnumVar(&c.Input.Location, locations...)
c.CmdClause.Flag("name", "Name of KV Store").Short('n').Required().StringVar(&c.Input.Name)

return &c
}

Expand Down
40 changes: 38 additions & 2 deletions pkg/commands/kvstore/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import (

func TestCreateStoreCommand(t *testing.T) {
const (
storeName = "test123"
storeID = "store-id-123"
storeName = "test123"
storeLocation = "EU"
storeID = "store-id-123"
)
now := time.Now()

Expand Down Expand Up @@ -71,6 +72,41 @@ func TestCreateStoreCommand(t *testing.T) {
UpdatedAt: &now,
}),
},
{
// NOTE: The following tests only validate support for the --location flag.
// Location/region indicators are not exposed for us to validate.
Args: testutil.Args(fmt.Sprintf("%s create --name %s --location %s", kvstore.RootName, storeName, storeLocation)),
API: mock.API{
CreateKVStoreFn: func(i *fastly.CreateKVStoreInput) (*fastly.KVStore, error) {
return &fastly.KVStore{
StoreID: storeID,
Name: i.Name,
}, nil
},
},
WantOutput: fstfmt.Success("Created KV Store '%s' (%s)", storeName, storeID),
},
{
// NOTE: The following tests only validate support for the --location flag.
// Location/region indicators are not exposed for us to validate.
Args: testutil.Args(fmt.Sprintf("%s create --name %s --location %s --json", kvstore.RootName, storeName, storeLocation)),
API: mock.API{
CreateKVStoreFn: func(i *fastly.CreateKVStoreInput) (*fastly.KVStore, error) {
return &fastly.KVStore{
StoreID: storeID,
Name: i.Name,
CreatedAt: &now,
UpdatedAt: &now,
}, nil
},
},
WantOutput: fstfmt.EncodeJSON(&fastly.KVStore{
StoreID: storeID,
Name: storeName,
CreatedAt: &now,
UpdatedAt: &now,
}),
},
}

for _, testcase := range scenarios {
Expand Down