Skip to content

Commit

Permalink
Review feedback... removing unnecessary source files.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpfleming committed Jan 13, 2025
1 parent 7b32797 commit 13657b8
Show file tree
Hide file tree
Showing 68 changed files with 969 additions and 1,285 deletions.
3 changes: 3 additions & 0 deletions internal/productcore/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
// Disable is a base type for all 'disable' commands.
type Disable[O any] struct {
Base
// hooks is a pointer to an EnablementHookFuncs structure so
// that tests can modify the contents of the structure after
// this structure has been initialized
hooks *EnablementHookFuncs[O]
}

Expand Down
4 changes: 4 additions & 0 deletions internal/productcore/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package productcore contains a group of generic structures and
// functions which are used to implement common behaviors in product
// enablement/configuration commands
package productcore
3 changes: 3 additions & 0 deletions internal/productcore/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
// Enable is a base type for all 'enable' commands.
type Enable[O any] struct {
Base
// hooks is a pointer to an EnablementHookFuncs structure so
// that tests can modify the contents of the structure after
// this structure has been initialized
hooks *EnablementHookFuncs[O]
}

Expand Down
3 changes: 3 additions & 0 deletions internal/productcore/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
// Status is a base type for all 'status' commands.
type Status[O any] struct {
Base
// hooks is a pointer to an EnablementHookFuncs structure so
// that tests can modify the contents of the structure after
// this structure has been initialized
hooks *EnablementHookFuncs[O]
}

Expand Down
4 changes: 4 additions & 0 deletions internal/productcore_test/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package productcore_test contains a group of generic structures and
// functions which are used to implement common behaviors in product
// enablement/configuration tests
package productcore_test
101 changes: 101 additions & 0 deletions pkg/commands/product/botmanagement/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package botmanagement

import (
"io"

"github.com/fastly/cli/pkg/argparser"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/go-fastly/v9/fastly"
product "github.com/fastly/go-fastly/v9/fastly/products/botmanagement"

"github.com/fastly/cli/internal/productcore"
"github.com/fastly/cli/pkg/api"
)

// EnablementHooks is a structure of dependency-injection points used
// by unit tests to provide mock behaviors
var EnablementHooks = productcore.EnablementHookFuncs[*product.EnableOutput]{
DisableFunc: func(client api.Interface, serviceID string) error {
return product.Disable(client.(*fastly.Client), serviceID)
},
EnableFunc: func(client api.Interface, serviceID string) (*product.EnableOutput, error) {
return product.Enable(client.(*fastly.Client), serviceID)
},
GetFunc: func(client api.Interface, serviceID string) (*product.EnableOutput, error) {
return product.Get(client.(*fastly.Client), serviceID)
},
}

// RootCommand is the parent command for all subcommands in this package.
// It should be installed under the primary root command.
type RootCommand struct {
argparser.Base
// no flags
}

// CommandName is the string to be used to invoke this command
const CommandName = "bot_management"

// NewRootCommand returns a new command registered in the parent.
func NewRootCommand(parent argparser.Registerer, g *global.Data) *RootCommand {
var c RootCommand
c.Globals = g
c.CmdClause = parent.Command(CommandName, "Enable and disable the Bot Management product")
return &c
}

// Exec implements the command interface.
func (c *RootCommand) Exec(_ io.Reader, _ io.Writer) error {
panic("unreachable")
}

// EnableCommand calls the Fastly API to disable the product.
type EnableCommand struct {
productcore.Enable[*product.EnableOutput]
}

// NewEnableCommand returns a usable command registered under the parent.
func NewEnableCommand(parent argparser.Registerer, g *global.Data) *EnableCommand {
c := EnableCommand{}
c.Init(parent, g, product.ProductID, product.ProductName, &EnablementHooks)
return &c
}

// Exec invokes the application logic for the command.
func (cmd *EnableCommand) Exec(_ io.Reader, out io.Writer) error {
return cmd.Enable.Exec(out)
}

// DisableCommand calls the Fastly API to disable the product.
type DisableCommand struct {
productcore.Disable[*product.EnableOutput]
}

// NewDisableCommand returns a usable command registered under the parent.
func NewDisableCommand(parent argparser.Registerer, g *global.Data) *DisableCommand {
c := DisableCommand{}
c.Init(parent, g, product.ProductID, product.ProductName, &EnablementHooks)
return &c
}

// Exec invokes the application logic for the command.
func (cmd *DisableCommand) Exec(_ io.Reader, out io.Writer) error {
return cmd.Disable.Exec(out)
}

// StatusCommand calls the Fastly API to get the enablement status of the product.
type StatusCommand struct {
productcore.Status[*product.EnableOutput]
}

// NewStatusCommand returns a usable command registered under the parent.
func NewStatusCommand(parent argparser.Registerer, g *global.Data) *StatusCommand {
c := StatusCommand{}
c.Init(parent, g, product.ProductID, product.ProductName, &EnablementHooks)
return &c
}

// Exec invokes the application logic for the command.
func (cmd *StatusCommand) Exec(_ io.Reader, out io.Writer) error {
return cmd.Status.Exec(out)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"github.com/fastly/cli/internal/productcore_test"
root "github.com/fastly/cli/pkg/commands/product"
sub "github.com/fastly/cli/pkg/commands/product/botmanagement"
"github.com/fastly/go-fastly/v9/fastly/products/botmanagement"
product "github.com/fastly/go-fastly/v9/fastly/products/botmanagement"
)

func TestBotManagementEnablement(t *testing.T) {
productcore_test.TestEnablement(productcore_test.TestEnablementInput[*botmanagement.EnableOutput]{
productcore_test.TestEnablement(productcore_test.TestEnablementInput[*product.EnableOutput]{
T: t,
Commands: []string{root.CommandName, sub.CommandName},
ProductID: botmanagement.ProductID,
ProductName: botmanagement.ProductName,
ProductID: product.ProductID,
ProductName: product.ProductName,
Hooks: &sub.EnablementHooks,
})
}
23 changes: 0 additions & 23 deletions pkg/commands/product/botmanagement/common.go

This file was deleted.

28 changes: 0 additions & 28 deletions pkg/commands/product/botmanagement/disable.go

This file was deleted.

28 changes: 0 additions & 28 deletions pkg/commands/product/botmanagement/enable.go

This file was deleted.

31 changes: 0 additions & 31 deletions pkg/commands/product/botmanagement/root.go

This file was deleted.

28 changes: 0 additions & 28 deletions pkg/commands/product/botmanagement/status.go

This file was deleted.

Loading

0 comments on commit 13657b8

Please sign in to comment.