Skip to content

Commit

Permalink
Apply some review feedback: use ProductOutput constraint everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpfleming committed Dec 12, 2024
1 parent de962ad commit 154d5de
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions fastly/products/api_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type enableOutputNested struct {
// This method is required, even though the field in the structure is
// exported, because there is an interface in an internal package
// which expects 'output' types to provide this method.
func (o *EnableOutput) ProductID() *string {
func (o EnableOutput) ProductID() *string {
return o.Product.ID
}

Expand All @@ -27,7 +27,7 @@ func (o *EnableOutput) ProductID() *string {
// This method is required, even though the field in the structure is
// exported, because there is an interface in an internal package
// which expects 'output' types to provide this method.
func (o *EnableOutput) ServiceID() *string {
func (o EnableOutput) ServiceID() *string {
return o.Service.ID
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/mitchellh/mapstructure v1.4.3
github.com/peterhellberg/link v1.1.0
golang.org/x/crypto v0.31.0
github.com/stretchr/testify v1.10.0
golang.org/x/crypto v0.31.0
golang.org/x/tools v0.15.0
honnef.co/go/tools v0.3.3
)
Expand Down
4 changes: 2 additions & 2 deletions internal/products/api_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "github.com/fastly/go-fastly/v9/fastly"
// not used within this structure, but specifying it at this level
// makes type inference simpler when the caller invokes the Get()
// function.
type GetInput[O any] struct {
type GetInput[O ProductOutput] struct {
Client *fastly.Client
ProductID string
ServiceID string
Expand All @@ -22,7 +22,7 @@ type GetInput[O any] struct {
// This function requires the same type parameter as the GetInput
// struct, and that type is used to construct, populate, and return
// the output present in the response body.
func Get[O any](i *GetInput[O]) (*O, error) {
func Get[O ProductOutput](i *GetInput[O]) (*O, error) {
var err error
if i.ServiceID == "" {
return nil, fastly.ErrMissingServiceID
Expand Down
4 changes: 2 additions & 2 deletions internal/products/api_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "github.com/fastly/go-fastly/v9/fastly"
// output; the output parameter is not used within this structure, but
// specifying it at this level makes type inference simpler when the
// caller invokes the Patch() function.
type PatchInput[I, O any] struct {
type PatchInput[I any, O ProductOutput] struct {
Client *fastly.Client
ProductID string
ServiceID string
Expand All @@ -25,7 +25,7 @@ type PatchInput[I, O any] struct {
// into the request body (encoded as JSON), and the output type
// parameter is used to construct, populate, and return the output
// present in the response body.
func Patch[I, O any](i *PatchInput[I, O]) (*O, error) {
func Patch[I any, O ProductOutput](i *PatchInput[I, O]) (*O, error) {
var err error
if i.ServiceID == "" {
return nil, fastly.ErrMissingServiceID
Expand Down
4 changes: 2 additions & 2 deletions internal/products/api_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "github.com/fastly/go-fastly/v9/fastly"
// output; the output parameter is not used within this structure, but
// specifying it at this level makes type inference simpler when the
// caller invokes the Put() function.
type PutInput[I, O any] struct {
type PutInput[I any, O ProductOutput] struct {
Client *fastly.Client
ProductID string
ServiceID string
Expand All @@ -25,7 +25,7 @@ type PutInput[I, O any] struct {
// into the request body (encoded as JSON), and the output type
// parameter is used to construct, populate, and return the output
// present in the response body.
func Put[I, O any](i *PutInput[I, O]) (*O, error) {
func Put[I any, O ProductOutput](i *PutInput[I, O]) (*O, error) {
var err error
if i.ServiceID == "" {
return nil, fastly.ErrMissingServiceID
Expand Down
6 changes: 3 additions & 3 deletions internal/products/products_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestDeleteMissingServiceID(t *testing.T) {
func TestGetMissingServiceID(t *testing.T) {
t.Parallel()

_, err := p.Get(&p.GetInput[fastly.ProductEnablement]{
_, err := p.Get(&p.GetInput[p.NullOutput]{
ServiceID: "",
})

Expand All @@ -31,7 +31,7 @@ func TestGetMissingServiceID(t *testing.T) {
func TestPatchMissingServiceID(t *testing.T) {
t.Parallel()

_, err := p.Patch(&p.PatchInput[p.NullInput, fastly.ProductEnablement]{
_, err := p.Patch(&p.PatchInput[p.NullInput, p.NullOutput]{
ServiceID: "",
})

Expand All @@ -41,7 +41,7 @@ func TestPatchMissingServiceID(t *testing.T) {
func TestPutMissingServiceID(t *testing.T) {
t.Parallel()

_, err := p.Put(&p.PutInput[p.NullInput, fastly.ProductEnablement]{
_, err := p.Put(&p.PutInput[p.NullInput, p.NullOutput]{
ServiceID: "",
})

Expand Down
13 changes: 13 additions & 0 deletions internal/products/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ type ProductOutput interface {
// constructors that the operation being tested does not accept an
// Input struct
type NullInput struct{}

// NullOutput is used to indicate to the generic FunctionalTest
// constructors that the operation being tested does not produce an
// Output struct
type NullOutput struct{}

func (o NullOutput) ProductID() *string {
return nil
}

func (o NullOutput) ServiceID() *string {
return nil
}

0 comments on commit 154d5de

Please sign in to comment.