Skip to content

Commit 13657b8

Browse files
committed
Review feedback... removing unnecessary source files.
1 parent 7b32797 commit 13657b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+969
-1285
lines changed

internal/productcore/disable.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
// Disable is a base type for all 'disable' commands.
1414
type Disable[O any] struct {
1515
Base
16+
// hooks is a pointer to an EnablementHookFuncs structure so
17+
// that tests can modify the contents of the structure after
18+
// this structure has been initialized
1619
hooks *EnablementHookFuncs[O]
1720
}
1821

internal/productcore/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Package productcore contains a group of generic structures and
2+
// functions which are used to implement common behaviors in product
3+
// enablement/configuration commands
4+
package productcore

internal/productcore/enable.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import (
1212
// Enable is a base type for all 'enable' commands.
1313
type Enable[O any] struct {
1414
Base
15+
// hooks is a pointer to an EnablementHookFuncs structure so
16+
// that tests can modify the contents of the structure after
17+
// this structure has been initialized
1518
hooks *EnablementHookFuncs[O]
1619
}
1720

internal/productcore/status.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414
// Status is a base type for all 'status' commands.
1515
type Status[O any] struct {
1616
Base
17+
// hooks is a pointer to an EnablementHookFuncs structure so
18+
// that tests can modify the contents of the structure after
19+
// this structure has been initialized
1720
hooks *EnablementHookFuncs[O]
1821
}
1922

internal/productcore_test/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Package productcore_test contains a group of generic structures and
2+
// functions which are used to implement common behaviors in product
3+
// enablement/configuration tests
4+
package productcore_test
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package botmanagement
2+
3+
import (
4+
"io"
5+
6+
"github.com/fastly/cli/pkg/argparser"
7+
"github.com/fastly/cli/pkg/global"
8+
"github.com/fastly/go-fastly/v9/fastly"
9+
product "github.com/fastly/go-fastly/v9/fastly/products/botmanagement"
10+
11+
"github.com/fastly/cli/internal/productcore"
12+
"github.com/fastly/cli/pkg/api"
13+
)
14+
15+
// EnablementHooks is a structure of dependency-injection points used
16+
// by unit tests to provide mock behaviors
17+
var EnablementHooks = productcore.EnablementHookFuncs[*product.EnableOutput]{
18+
DisableFunc: func(client api.Interface, serviceID string) error {
19+
return product.Disable(client.(*fastly.Client), serviceID)
20+
},
21+
EnableFunc: func(client api.Interface, serviceID string) (*product.EnableOutput, error) {
22+
return product.Enable(client.(*fastly.Client), serviceID)
23+
},
24+
GetFunc: func(client api.Interface, serviceID string) (*product.EnableOutput, error) {
25+
return product.Get(client.(*fastly.Client), serviceID)
26+
},
27+
}
28+
29+
// RootCommand is the parent command for all subcommands in this package.
30+
// It should be installed under the primary root command.
31+
type RootCommand struct {
32+
argparser.Base
33+
// no flags
34+
}
35+
36+
// CommandName is the string to be used to invoke this command
37+
const CommandName = "bot_management"
38+
39+
// NewRootCommand returns a new command registered in the parent.
40+
func NewRootCommand(parent argparser.Registerer, g *global.Data) *RootCommand {
41+
var c RootCommand
42+
c.Globals = g
43+
c.CmdClause = parent.Command(CommandName, "Enable and disable the Bot Management product")
44+
return &c
45+
}
46+
47+
// Exec implements the command interface.
48+
func (c *RootCommand) Exec(_ io.Reader, _ io.Writer) error {
49+
panic("unreachable")
50+
}
51+
52+
// EnableCommand calls the Fastly API to disable the product.
53+
type EnableCommand struct {
54+
productcore.Enable[*product.EnableOutput]
55+
}
56+
57+
// NewEnableCommand returns a usable command registered under the parent.
58+
func NewEnableCommand(parent argparser.Registerer, g *global.Data) *EnableCommand {
59+
c := EnableCommand{}
60+
c.Init(parent, g, product.ProductID, product.ProductName, &EnablementHooks)
61+
return &c
62+
}
63+
64+
// Exec invokes the application logic for the command.
65+
func (cmd *EnableCommand) Exec(_ io.Reader, out io.Writer) error {
66+
return cmd.Enable.Exec(out)
67+
}
68+
69+
// DisableCommand calls the Fastly API to disable the product.
70+
type DisableCommand struct {
71+
productcore.Disable[*product.EnableOutput]
72+
}
73+
74+
// NewDisableCommand returns a usable command registered under the parent.
75+
func NewDisableCommand(parent argparser.Registerer, g *global.Data) *DisableCommand {
76+
c := DisableCommand{}
77+
c.Init(parent, g, product.ProductID, product.ProductName, &EnablementHooks)
78+
return &c
79+
}
80+
81+
// Exec invokes the application logic for the command.
82+
func (cmd *DisableCommand) Exec(_ io.Reader, out io.Writer) error {
83+
return cmd.Disable.Exec(out)
84+
}
85+
86+
// StatusCommand calls the Fastly API to get the enablement status of the product.
87+
type StatusCommand struct {
88+
productcore.Status[*product.EnableOutput]
89+
}
90+
91+
// NewStatusCommand returns a usable command registered under the parent.
92+
func NewStatusCommand(parent argparser.Registerer, g *global.Data) *StatusCommand {
93+
c := StatusCommand{}
94+
c.Init(parent, g, product.ProductID, product.ProductName, &EnablementHooks)
95+
return &c
96+
}
97+
98+
// Exec invokes the application logic for the command.
99+
func (cmd *StatusCommand) Exec(_ io.Reader, out io.Writer) error {
100+
return cmd.Status.Exec(out)
101+
}

pkg/commands/product/botmanagement/product_test.go renamed to pkg/commands/product/botmanagement/commands_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import (
66
"github.com/fastly/cli/internal/productcore_test"
77
root "github.com/fastly/cli/pkg/commands/product"
88
sub "github.com/fastly/cli/pkg/commands/product/botmanagement"
9-
"github.com/fastly/go-fastly/v9/fastly/products/botmanagement"
9+
product "github.com/fastly/go-fastly/v9/fastly/products/botmanagement"
1010
)
1111

1212
func TestBotManagementEnablement(t *testing.T) {
13-
productcore_test.TestEnablement(productcore_test.TestEnablementInput[*botmanagement.EnableOutput]{
13+
productcore_test.TestEnablement(productcore_test.TestEnablementInput[*product.EnableOutput]{
1414
T: t,
1515
Commands: []string{root.CommandName, sub.CommandName},
16-
ProductID: botmanagement.ProductID,
17-
ProductName: botmanagement.ProductName,
16+
ProductID: product.ProductID,
17+
ProductName: product.ProductName,
1818
Hooks: &sub.EnablementHooks,
1919
})
2020
}

pkg/commands/product/botmanagement/common.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

pkg/commands/product/botmanagement/disable.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

pkg/commands/product/botmanagement/enable.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

pkg/commands/product/botmanagement/root.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

pkg/commands/product/botmanagement/status.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)