From b657a3f32d1ffddf26544c288f478efc4e0d793e Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Fri, 24 Jan 2025 12:24:36 -0500 Subject: [PATCH] fix(products): Improve API usability. (#572) * Add 'EnableOutput' type aliases in each product, so that users of the API don't need to know whether that product has its own EnableOutput or not. Add 'NewEnableOutput' function so that users of the API can easily construct mock output instances. * Add 'ProductName' constant in each product, so that users of the API will have access to the canonical name of the product along with its product_id. * Change package names to conform to Go guidelines (remove underscores). * Change APIs to accept and return by-value instead of by-pointer, as using by-pointer structures can be difficult in generic parameter contexts and the structures involved are small (so there is no real benefit to avoiding by-value passing). --- .../fixtures/disable_product.yaml | 0 .../fixtures/enable_product.yaml | 0 .../fixtures/final_reset.yaml | 0 .../fixtures/incorrect_fetch.yaml | 0 .../fixtures/original_fetch.yaml | 0 .../fixtures/set_full.yaml | 0 .../fixtures/set_jpeg_type/auto.yaml | 0 .../fixtures/set_jpeg_type/baseline.yaml | 0 .../fixtures/set_jpeg_type/progressive.yaml | 0 .../fixtures/set_resize_filter/bicubic.yaml | 0 .../fixtures/set_resize_filter/bilinear.yaml | 0 .../fixtures/set_resize_filter/lanczos2.yaml | 0 .../fixtures/set_resize_filter/lanczos3.yaml | 0 .../fixtures/set_resize_filter/nearest.yaml | 0 .../fixtures/update_1_get.yaml | 0 .../fixtures/update_1_patch.yaml | 0 .../fixtures/update_2_get.yaml | 0 .../fixtures/update_2_patch.yaml | 0 .../fixtures/version.yaml | 0 .../image_optimizer_default_settings_test.go | 8 +- fastly/products/api_output.go | 38 --------- fastly/products/bot_management/api.go | 36 -------- fastly/products/bot_management/doc.go | 3 - fastly/products/botmanagement/api.go | 50 +++++++++++ .../api_test.go | 32 ++++---- fastly/products/botmanagement/doc.go | 3 + ...isable-ensure-disabled-before-testing.yaml | 0 .../fixtures/disable.yaml | 0 .../fixtures/enable.yaml | 0 .../fixtures/get-after-disablement.yaml | 0 .../fixtures/get-after-enablement.yaml | 0 .../fixtures/get-before-enablement.yaml | 0 fastly/products/brotli_compression/api.go | 36 -------- fastly/products/brotli_compression/doc.go | 3 - fastly/products/brotlicompression/api.go | 50 +++++++++++ .../api_test.go | 32 ++++---- fastly/products/brotlicompression/doc.go | 3 + ...isable-ensure-disabled-before-testing.yaml | 0 .../fixtures/disable.yaml | 0 .../fixtures/enable.yaml | 0 .../fixtures/get-after-disablement.yaml | 0 .../fixtures/get-after-enablement.yaml | 0 .../fixtures/get-before-enablement.yaml | 0 fastly/products/ddos_protection/doc.go | 3 - .../api.go | 40 ++++++--- .../api_test.go | 62 +++++++------- fastly/products/ddosprotection/doc.go | 3 + ...isable-ensure-disabled-before-testing.yaml | 0 .../fixtures/disable.yaml | 0 .../fixtures/enable.yaml | 0 .../fixtures/get-after-disablement.yaml | 0 .../fixtures/get-after-enablement.yaml | 0 .../fixtures/get-before-enablement.yaml | 0 .../get-configuration-after-update.yaml | 0 .../fixtures/get-configuration-default.yaml | 0 .../fixtures/update-configuration.yaml | 0 fastly/products/domain_inspector/api.go | 36 -------- fastly/products/domain_inspector/doc.go | 3 - fastly/products/domaininspector/api.go | 50 +++++++++++ .../api_test.go | 32 ++++---- fastly/products/domaininspector/doc.go | 3 + ...isable-ensure-disabled-before-testing.yaml | 0 .../fixtures/disable.yaml | 0 .../fixtures/enable.yaml | 0 .../fixtures/get-after-disablement.yaml | 0 .../fixtures/get-after-enablement.yaml | 0 .../fixtures/get-before-enablement.yaml | 0 fastly/products/fanout/api.go | 24 ++++-- fastly/products/fanout/api_test.go | 8 +- fastly/products/image_optimizer/api.go | 36 -------- fastly/products/image_optimizer/doc.go | 3 - fastly/products/imageoptimizer/api.go | 50 +++++++++++ .../api_test.go | 32 ++++---- fastly/products/imageoptimizer/doc.go | 3 + ...isable-ensure-disabled-before-testing.yaml | 0 .../fixtures/disable.yaml | 0 .../fixtures/enable.yaml | 0 .../fixtures/get-after-disablement.yaml | 0 .../fixtures/get-after-enablement.yaml | 0 .../fixtures/get-before-enablement.yaml | 0 fastly/products/log_explorer_insights/api.go | 36 -------- .../log_explorer_insights/api_test.go | 55 ------------- fastly/products/log_explorer_insights/doc.go | 3 - fastly/products/logexplorerinsights/api.go | 50 +++++++++++ .../products/logexplorerinsights/api_test.go | 55 +++++++++++++ fastly/products/logexplorerinsights/doc.go | 3 + ...isable-ensure-disabled-before-testing.yaml | 0 .../fixtures/disable.yaml | 0 .../fixtures/enable.yaml | 0 .../fixtures/get-after-disablement.yaml | 0 .../fixtures/get-after-enablement.yaml | 0 .../fixtures/get-before-enablement.yaml | 0 fastly/products/ngwaf/api.go | 42 ++++++---- fastly/products/ngwaf/api_test.go | 27 +++--- fastly/products/origin_inspector/api.go | 36 -------- fastly/products/origin_inspector/doc.go | 3 - fastly/products/origininspector/api.go | 50 +++++++++++ .../api_test.go | 32 ++++---- fastly/products/origininspector/doc.go | 3 + ...isable-ensure-disabled-before-testing.yaml | 0 .../fixtures/disable.yaml | 0 .../fixtures/enable.yaml | 0 .../fixtures/get-after-disablement.yaml | 0 .../fixtures/get-after-enablement.yaml | 0 .../fixtures/get-before-enablement.yaml | 0 fastly/products/types.go | 82 +++++++++++++++++++ fastly/products/websockets/api.go | 24 ++++-- fastly/products/websockets/api_test.go | 8 +- internal/productcore/api_get.go | 7 +- internal/productcore/api_patch.go | 7 +- internal/productcore/api_put.go | 7 +- .../productcore/functional_test_enable.go | 11 +-- internal/productcore/functional_test_get.go | 10 +-- .../functional_test_get_configuration.go | 10 +-- .../functional_test_update_configuration.go | 10 +-- internal/productcore/functional_test_utils.go | 9 +- internal/productcore/productcore_test.go | 7 +- internal/productcore/types.go | 34 -------- 118 files changed, 733 insertions(+), 570 deletions(-) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/disable_product.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/enable_product.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/final_reset.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/incorrect_fetch.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/original_fetch.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/set_full.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/set_jpeg_type/auto.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/set_jpeg_type/baseline.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/set_jpeg_type/progressive.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/set_resize_filter/bicubic.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/set_resize_filter/bilinear.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/set_resize_filter/lanczos2.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/set_resize_filter/lanczos3.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/set_resize_filter/nearest.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/update_1_get.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/update_1_patch.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/update_2_get.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/update_2_patch.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/fixtures/version.yaml (100%) rename fastly/{image_optimizer_default_settings => imageoptimizerdefaultsettings}/image_optimizer_default_settings_test.go (97%) delete mode 100644 fastly/products/api_output.go delete mode 100644 fastly/products/bot_management/api.go delete mode 100644 fastly/products/bot_management/doc.go create mode 100644 fastly/products/botmanagement/api.go rename fastly/products/{bot_management => botmanagement}/api_test.go (54%) create mode 100644 fastly/products/botmanagement/doc.go rename fastly/products/{bot_management => botmanagement}/fixtures/disable-ensure-disabled-before-testing.yaml (100%) rename fastly/products/{bot_management => botmanagement}/fixtures/disable.yaml (100%) rename fastly/products/{bot_management => botmanagement}/fixtures/enable.yaml (100%) rename fastly/products/{bot_management => botmanagement}/fixtures/get-after-disablement.yaml (100%) rename fastly/products/{bot_management => botmanagement}/fixtures/get-after-enablement.yaml (100%) rename fastly/products/{bot_management => botmanagement}/fixtures/get-before-enablement.yaml (100%) delete mode 100644 fastly/products/brotli_compression/api.go delete mode 100644 fastly/products/brotli_compression/doc.go create mode 100644 fastly/products/brotlicompression/api.go rename fastly/products/{brotli_compression => brotlicompression}/api_test.go (52%) create mode 100644 fastly/products/brotlicompression/doc.go rename fastly/products/{brotli_compression => brotlicompression}/fixtures/disable-ensure-disabled-before-testing.yaml (100%) rename fastly/products/{brotli_compression => brotlicompression}/fixtures/disable.yaml (100%) rename fastly/products/{brotli_compression => brotlicompression}/fixtures/enable.yaml (100%) rename fastly/products/{brotli_compression => brotlicompression}/fixtures/get-after-disablement.yaml (100%) rename fastly/products/{brotli_compression => brotlicompression}/fixtures/get-after-enablement.yaml (100%) rename fastly/products/{brotli_compression => brotlicompression}/fixtures/get-before-enablement.yaml (100%) delete mode 100644 fastly/products/ddos_protection/doc.go rename fastly/products/{ddos_protection => ddosprotection}/api.go (54%) rename fastly/products/{ddos_protection => ddosprotection}/api_test.go (55%) create mode 100644 fastly/products/ddosprotection/doc.go rename fastly/products/{ddos_protection => ddosprotection}/fixtures/disable-ensure-disabled-before-testing.yaml (100%) rename fastly/products/{ddos_protection => ddosprotection}/fixtures/disable.yaml (100%) rename fastly/products/{ddos_protection => ddosprotection}/fixtures/enable.yaml (100%) rename fastly/products/{ddos_protection => ddosprotection}/fixtures/get-after-disablement.yaml (100%) rename fastly/products/{ddos_protection => ddosprotection}/fixtures/get-after-enablement.yaml (100%) rename fastly/products/{ddos_protection => ddosprotection}/fixtures/get-before-enablement.yaml (100%) rename fastly/products/{ddos_protection => ddosprotection}/fixtures/get-configuration-after-update.yaml (100%) rename fastly/products/{ddos_protection => ddosprotection}/fixtures/get-configuration-default.yaml (100%) rename fastly/products/{ddos_protection => ddosprotection}/fixtures/update-configuration.yaml (100%) delete mode 100644 fastly/products/domain_inspector/api.go delete mode 100644 fastly/products/domain_inspector/doc.go create mode 100644 fastly/products/domaininspector/api.go rename fastly/products/{origin_inspector => domaininspector}/api_test.go (53%) create mode 100644 fastly/products/domaininspector/doc.go rename fastly/products/{domain_inspector => domaininspector}/fixtures/disable-ensure-disabled-before-testing.yaml (100%) rename fastly/products/{domain_inspector => domaininspector}/fixtures/disable.yaml (100%) rename fastly/products/{domain_inspector => domaininspector}/fixtures/enable.yaml (100%) rename fastly/products/{domain_inspector => domaininspector}/fixtures/get-after-disablement.yaml (100%) rename fastly/products/{domain_inspector => domaininspector}/fixtures/get-after-enablement.yaml (100%) rename fastly/products/{domain_inspector => domaininspector}/fixtures/get-before-enablement.yaml (100%) delete mode 100644 fastly/products/image_optimizer/api.go delete mode 100644 fastly/products/image_optimizer/doc.go create mode 100644 fastly/products/imageoptimizer/api.go rename fastly/products/{image_optimizer => imageoptimizer}/api_test.go (53%) create mode 100644 fastly/products/imageoptimizer/doc.go rename fastly/products/{image_optimizer => imageoptimizer}/fixtures/disable-ensure-disabled-before-testing.yaml (100%) rename fastly/products/{image_optimizer => imageoptimizer}/fixtures/disable.yaml (100%) rename fastly/products/{image_optimizer => imageoptimizer}/fixtures/enable.yaml (100%) rename fastly/products/{image_optimizer => imageoptimizer}/fixtures/get-after-disablement.yaml (100%) rename fastly/products/{image_optimizer => imageoptimizer}/fixtures/get-after-enablement.yaml (100%) rename fastly/products/{image_optimizer => imageoptimizer}/fixtures/get-before-enablement.yaml (100%) delete mode 100644 fastly/products/log_explorer_insights/api.go delete mode 100644 fastly/products/log_explorer_insights/api_test.go delete mode 100644 fastly/products/log_explorer_insights/doc.go create mode 100644 fastly/products/logexplorerinsights/api.go create mode 100644 fastly/products/logexplorerinsights/api_test.go create mode 100644 fastly/products/logexplorerinsights/doc.go rename fastly/products/{log_explorer_insights => logexplorerinsights}/fixtures/disable-ensure-disabled-before-testing.yaml (100%) rename fastly/products/{log_explorer_insights => logexplorerinsights}/fixtures/disable.yaml (100%) rename fastly/products/{log_explorer_insights => logexplorerinsights}/fixtures/enable.yaml (100%) rename fastly/products/{log_explorer_insights => logexplorerinsights}/fixtures/get-after-disablement.yaml (100%) rename fastly/products/{log_explorer_insights => logexplorerinsights}/fixtures/get-after-enablement.yaml (100%) rename fastly/products/{log_explorer_insights => logexplorerinsights}/fixtures/get-before-enablement.yaml (100%) delete mode 100644 fastly/products/origin_inspector/api.go delete mode 100644 fastly/products/origin_inspector/doc.go create mode 100644 fastly/products/origininspector/api.go rename fastly/products/{domain_inspector => origininspector}/api_test.go (53%) create mode 100644 fastly/products/origininspector/doc.go rename fastly/products/{origin_inspector => origininspector}/fixtures/disable-ensure-disabled-before-testing.yaml (100%) rename fastly/products/{origin_inspector => origininspector}/fixtures/disable.yaml (100%) rename fastly/products/{origin_inspector => origininspector}/fixtures/enable.yaml (100%) rename fastly/products/{origin_inspector => origininspector}/fixtures/get-after-disablement.yaml (100%) rename fastly/products/{origin_inspector => origininspector}/fixtures/get-after-enablement.yaml (100%) rename fastly/products/{origin_inspector => origininspector}/fixtures/get-before-enablement.yaml (100%) create mode 100644 fastly/products/types.go delete mode 100644 internal/productcore/types.go diff --git a/fastly/image_optimizer_default_settings/fixtures/disable_product.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/disable_product.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/disable_product.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/disable_product.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/enable_product.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/enable_product.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/enable_product.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/enable_product.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/final_reset.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/final_reset.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/final_reset.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/final_reset.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/incorrect_fetch.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/incorrect_fetch.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/incorrect_fetch.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/incorrect_fetch.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/original_fetch.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/original_fetch.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/original_fetch.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/original_fetch.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/set_full.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/set_full.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/set_full.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/set_full.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/set_jpeg_type/auto.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/set_jpeg_type/auto.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/set_jpeg_type/auto.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/set_jpeg_type/auto.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/set_jpeg_type/baseline.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/set_jpeg_type/baseline.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/set_jpeg_type/baseline.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/set_jpeg_type/baseline.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/set_jpeg_type/progressive.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/set_jpeg_type/progressive.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/set_jpeg_type/progressive.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/set_jpeg_type/progressive.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/set_resize_filter/bicubic.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/set_resize_filter/bicubic.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/set_resize_filter/bicubic.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/set_resize_filter/bicubic.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/set_resize_filter/bilinear.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/set_resize_filter/bilinear.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/set_resize_filter/bilinear.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/set_resize_filter/bilinear.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/set_resize_filter/lanczos2.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/set_resize_filter/lanczos2.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/set_resize_filter/lanczos2.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/set_resize_filter/lanczos2.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/set_resize_filter/lanczos3.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/set_resize_filter/lanczos3.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/set_resize_filter/lanczos3.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/set_resize_filter/lanczos3.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/set_resize_filter/nearest.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/set_resize_filter/nearest.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/set_resize_filter/nearest.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/set_resize_filter/nearest.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/update_1_get.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/update_1_get.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/update_1_get.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/update_1_get.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/update_1_patch.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/update_1_patch.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/update_1_patch.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/update_1_patch.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/update_2_get.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/update_2_get.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/update_2_get.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/update_2_get.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/update_2_patch.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/update_2_patch.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/update_2_patch.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/update_2_patch.yaml diff --git a/fastly/image_optimizer_default_settings/fixtures/version.yaml b/fastly/imageoptimizerdefaultsettings/fixtures/version.yaml similarity index 100% rename from fastly/image_optimizer_default_settings/fixtures/version.yaml rename to fastly/imageoptimizerdefaultsettings/fixtures/version.yaml diff --git a/fastly/image_optimizer_default_settings/image_optimizer_default_settings_test.go b/fastly/imageoptimizerdefaultsettings/image_optimizer_default_settings_test.go similarity index 97% rename from fastly/image_optimizer_default_settings/image_optimizer_default_settings_test.go rename to fastly/imageoptimizerdefaultsettings/image_optimizer_default_settings_test.go index 68185e91..de1c035d 100644 --- a/fastly/image_optimizer_default_settings/image_optimizer_default_settings_test.go +++ b/fastly/imageoptimizerdefaultsettings/image_optimizer_default_settings_test.go @@ -1,11 +1,11 @@ -package image_optimizer_default_settings_test +package imageoptimizerdefaultsettings_test import ( "strings" "testing" "github.com/fastly/go-fastly/v9/fastly" - "github.com/fastly/go-fastly/v9/fastly/products/image_optimizer" + "github.com/fastly/go-fastly/v9/fastly/products/imageoptimizer" ) // TestClient_ImageOptimizerDefaultSettings tests the Image Optimizer Default Settings API @@ -23,7 +23,7 @@ func TestClient_ImageOptimizerDefaultSettings(t *testing.T) { // Enable IO fastly.Record(t, fixtureBase+"enable_product", func(c *fastly.Client) { - _, err = image_optimizer.Enable(c, fastly.TestDeliveryServiceID) + _, err = imageoptimizer.Enable(c, fastly.TestDeliveryServiceID) }) if err != nil { t.Fatal(err) @@ -32,7 +32,7 @@ func TestClient_ImageOptimizerDefaultSettings(t *testing.T) { // Ensure we disable IO on the service after the test defer func() { fastly.Record(t, fixtureBase+"disable_product", func(c *fastly.Client) { - _, err = image_optimizer.Enable(c, fastly.TestDeliveryServiceID) + _, err = imageoptimizer.Enable(c, fastly.TestDeliveryServiceID) if err != nil { t.Fatal(err) diff --git a/fastly/products/api_output.go b/fastly/products/api_output.go deleted file mode 100644 index d8c46266..00000000 --- a/fastly/products/api_output.go +++ /dev/null @@ -1,38 +0,0 @@ -package products - -// EnableOutput represents an enablement response from the Fastly -// API. Some products will use this structure directly, others will -// embed it into their own structure. -type EnableOutput struct { - Product *enableOutputNested `mapstructure:"product"` - Service *enableOutputNested `mapstructure:"service"` -} - -type enableOutputNested struct { - Object *string `mapstructure:"object,omitempty"` - ID *string `mapstructure:"id,omitempty"` -} - -// GetProductID return the ProductID inside an EnableOutput structure. -// -// 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 { - return o.Product.ID -} - -// GetServiceID return the ServiceID inside an EnableOutput structure. -// -// 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 { - return o.Service.ID -} - -// ConfigureOutput represents a configuration response from the Fastly -// API. Products will embed this into their own structure. -type ConfigureOutput struct { - EnableOutput `mapstructure:",squash"` -} diff --git a/fastly/products/bot_management/api.go b/fastly/products/bot_management/api.go deleted file mode 100644 index d4b4e260..00000000 --- a/fastly/products/bot_management/api.go +++ /dev/null @@ -1,36 +0,0 @@ -package bot_management - -import ( - "github.com/fastly/go-fastly/v9/fastly" - "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/internal/productcore" -) - -const ProductID = "bot_management" - -// Get gets the status of the Bot Management product on the service. -func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Get[*products.EnableOutput](&productcore.GetInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Enable enables the Bot Management product on the service. -func Enable(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Put[*products.EnableOutput](&productcore.PutInput[*productcore.NullInput]{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Disable disables the Bot Management product on the service. -func Disable(c *fastly.Client, serviceID string) error { - return productcore.Delete(&productcore.DeleteInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} diff --git a/fastly/products/bot_management/doc.go b/fastly/products/bot_management/doc.go deleted file mode 100644 index a371577f..00000000 --- a/fastly/products/bot_management/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package bot_management contains API operations to enable and -// disable the Bot Management product on a service -package bot_management diff --git a/fastly/products/botmanagement/api.go b/fastly/products/botmanagement/api.go new file mode 100644 index 00000000..1a9d31da --- /dev/null +++ b/fastly/products/botmanagement/api.go @@ -0,0 +1,50 @@ +package botmanagement + +import ( + "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" + "github.com/fastly/go-fastly/v9/internal/productcore" +) + +const ( + ProductID = "bot_management" + ProductName = "Bot Management" +) + +// EnableOutput holds the details returned by the API from 'Get' and +// 'Enable' operations; this alias exists to ensure that users of this +// package will have a stable name to reference. +type EnableOutput = products.EnableOutput + +// Get gets the status of the Bot Management product on the service. +func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Get[EnableOutput](&productcore.GetInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Enable enables the Bot Management product on the service. +func Enable(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Put[EnableOutput](&productcore.PutInput[products.NullInput]{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Disable disables the Bot Management product on the service. +func Disable(c *fastly.Client, serviceID string) error { + return productcore.Delete(&productcore.DeleteInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// NewEnableOutput is used to construct mock API output structures for +// use in tests. +func NewEnableOutput(serviceID string) EnableOutput { + return products.NewEnableOutput(ProductID, serviceID) +} diff --git a/fastly/products/bot_management/api_test.go b/fastly/products/botmanagement/api_test.go similarity index 54% rename from fastly/products/bot_management/api_test.go rename to fastly/products/botmanagement/api_test.go index 2222f22e..640015c8 100644 --- a/fastly/products/bot_management/api_test.go +++ b/fastly/products/botmanagement/api_test.go @@ -1,11 +1,11 @@ -package bot_management_test +package botmanagement_test import ( "testing" "github.com/fastly/go-fastly/v9/fastly" "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/fastly/products/bot_management" + "github.com/fastly/go-fastly/v9/fastly/products/botmanagement" "github.com/fastly/go-fastly/v9/internal/productcore" "github.com/fastly/go-fastly/v9/internal/test_utils" ) @@ -15,36 +15,36 @@ var serviceID = fastly.TestDeliveryServiceID var functionalTests = []*test_utils.FunctionalTest{ productcore.NewDisableTest(&productcore.DisableTestInput{ Phase: "ensure disabled before testing", - OpFn: bot_management.Disable, + OpFn: botmanagement.Disable, ServiceID: serviceID, IgnoreFailure: true, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[botmanagement.EnableOutput]{ Phase: "before enablement", - OpFn: bot_management.Get, - ProductID: bot_management.ProductID, + OpFn: botmanagement.Get, + ProductID: botmanagement.ProductID, ServiceID: serviceID, ExpectFailure: true, }), - productcore.NewEnableTest(&productcore.EnableTestInput[*products.EnableOutput, *productcore.NullInput]{ - OpNoInputFn: bot_management.Enable, - ProductID: bot_management.ProductID, + productcore.NewEnableTest(&productcore.EnableTestInput[botmanagement.EnableOutput, products.NullInput]{ + OpNoInputFn: botmanagement.Enable, + ProductID: botmanagement.ProductID, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[botmanagement.EnableOutput]{ Phase: "after enablement", - OpFn: bot_management.Get, - ProductID: bot_management.ProductID, + OpFn: botmanagement.Get, + ProductID: botmanagement.ProductID, ServiceID: serviceID, }), productcore.NewDisableTest(&productcore.DisableTestInput{ - OpFn: bot_management.Disable, + OpFn: botmanagement.Disable, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[botmanagement.EnableOutput]{ Phase: "after disablement", - OpFn: bot_management.Get, - ProductID: bot_management.ProductID, + OpFn: botmanagement.Get, + ProductID: botmanagement.ProductID, ServiceID: serviceID, ExpectFailure: true, }), diff --git a/fastly/products/botmanagement/doc.go b/fastly/products/botmanagement/doc.go new file mode 100644 index 00000000..45e2f35d --- /dev/null +++ b/fastly/products/botmanagement/doc.go @@ -0,0 +1,3 @@ +// Package botmanagement contains API operations to enable and +// disable the Bot Management product on a service +package botmanagement diff --git a/fastly/products/bot_management/fixtures/disable-ensure-disabled-before-testing.yaml b/fastly/products/botmanagement/fixtures/disable-ensure-disabled-before-testing.yaml similarity index 100% rename from fastly/products/bot_management/fixtures/disable-ensure-disabled-before-testing.yaml rename to fastly/products/botmanagement/fixtures/disable-ensure-disabled-before-testing.yaml diff --git a/fastly/products/bot_management/fixtures/disable.yaml b/fastly/products/botmanagement/fixtures/disable.yaml similarity index 100% rename from fastly/products/bot_management/fixtures/disable.yaml rename to fastly/products/botmanagement/fixtures/disable.yaml diff --git a/fastly/products/bot_management/fixtures/enable.yaml b/fastly/products/botmanagement/fixtures/enable.yaml similarity index 100% rename from fastly/products/bot_management/fixtures/enable.yaml rename to fastly/products/botmanagement/fixtures/enable.yaml diff --git a/fastly/products/bot_management/fixtures/get-after-disablement.yaml b/fastly/products/botmanagement/fixtures/get-after-disablement.yaml similarity index 100% rename from fastly/products/bot_management/fixtures/get-after-disablement.yaml rename to fastly/products/botmanagement/fixtures/get-after-disablement.yaml diff --git a/fastly/products/bot_management/fixtures/get-after-enablement.yaml b/fastly/products/botmanagement/fixtures/get-after-enablement.yaml similarity index 100% rename from fastly/products/bot_management/fixtures/get-after-enablement.yaml rename to fastly/products/botmanagement/fixtures/get-after-enablement.yaml diff --git a/fastly/products/bot_management/fixtures/get-before-enablement.yaml b/fastly/products/botmanagement/fixtures/get-before-enablement.yaml similarity index 100% rename from fastly/products/bot_management/fixtures/get-before-enablement.yaml rename to fastly/products/botmanagement/fixtures/get-before-enablement.yaml diff --git a/fastly/products/brotli_compression/api.go b/fastly/products/brotli_compression/api.go deleted file mode 100644 index e0f3be96..00000000 --- a/fastly/products/brotli_compression/api.go +++ /dev/null @@ -1,36 +0,0 @@ -package brotli_compression - -import ( - "github.com/fastly/go-fastly/v9/fastly" - "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/internal/productcore" -) - -const ProductID = "brotli_compression" - -// Get gets the status of the Brotli Compression product on the service. -func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Get[*products.EnableOutput](&productcore.GetInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Enable enables the Brotli Compression product on the service. -func Enable(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Put[*products.EnableOutput](&productcore.PutInput[*productcore.NullInput]{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Disable disables the Brotli Compression product on the service. -func Disable(c *fastly.Client, serviceID string) error { - return productcore.Delete(&productcore.DeleteInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} diff --git a/fastly/products/brotli_compression/doc.go b/fastly/products/brotli_compression/doc.go deleted file mode 100644 index b25d7d1f..00000000 --- a/fastly/products/brotli_compression/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package brotli_compression contains API operations to enable and -// disable the Brotli Compression product on a service -package brotli_compression diff --git a/fastly/products/brotlicompression/api.go b/fastly/products/brotlicompression/api.go new file mode 100644 index 00000000..d147115e --- /dev/null +++ b/fastly/products/brotlicompression/api.go @@ -0,0 +1,50 @@ +package brotlicompression + +import ( + "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" + "github.com/fastly/go-fastly/v9/internal/productcore" +) + +const ( + ProductID = "brotli_compression" + ProductName = "Brotli Compression" +) + +// EnableOutput holds the details returned by the API from 'Get' and +// 'Enable' operations; this alias exists to ensure that users of this +// package will have a stable name to reference. +type EnableOutput = products.EnableOutput + +// Get gets the status of the Brotli Compression product on the service. +func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Get[EnableOutput](&productcore.GetInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Enable enables the Brotli Compression product on the service. +func Enable(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Put[EnableOutput](&productcore.PutInput[products.NullInput]{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Disable disables the Brotli Compression product on the service. +func Disable(c *fastly.Client, serviceID string) error { + return productcore.Delete(&productcore.DeleteInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// NewEnableOutput is used to construct mock API output structures for +// use in tests. +func NewEnableOutput(serviceID string) EnableOutput { + return products.NewEnableOutput(ProductID, serviceID) +} diff --git a/fastly/products/brotli_compression/api_test.go b/fastly/products/brotlicompression/api_test.go similarity index 52% rename from fastly/products/brotli_compression/api_test.go rename to fastly/products/brotlicompression/api_test.go index 1b7925bd..90f618eb 100644 --- a/fastly/products/brotli_compression/api_test.go +++ b/fastly/products/brotlicompression/api_test.go @@ -1,11 +1,11 @@ -package brotli_compression_test +package brotlicompression_test import ( "testing" "github.com/fastly/go-fastly/v9/fastly" "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/fastly/products/brotli_compression" + "github.com/fastly/go-fastly/v9/fastly/products/brotlicompression" "github.com/fastly/go-fastly/v9/internal/productcore" "github.com/fastly/go-fastly/v9/internal/test_utils" ) @@ -15,36 +15,36 @@ var serviceID = fastly.TestDeliveryServiceID var functionalTests = []*test_utils.FunctionalTest{ productcore.NewDisableTest(&productcore.DisableTestInput{ Phase: "ensure disabled before testing", - OpFn: brotli_compression.Disable, + OpFn: brotlicompression.Disable, ServiceID: serviceID, IgnoreFailure: true, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[brotlicompression.EnableOutput]{ Phase: "before enablement", - OpFn: brotli_compression.Get, - ProductID: brotli_compression.ProductID, + OpFn: brotlicompression.Get, + ProductID: brotlicompression.ProductID, ServiceID: serviceID, ExpectFailure: true, }), - productcore.NewEnableTest(&productcore.EnableTestInput[*products.EnableOutput, *productcore.NullInput]{ - OpNoInputFn: brotli_compression.Enable, - ProductID: brotli_compression.ProductID, + productcore.NewEnableTest(&productcore.EnableTestInput[brotlicompression.EnableOutput, products.NullInput]{ + OpNoInputFn: brotlicompression.Enable, + ProductID: brotlicompression.ProductID, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[brotlicompression.EnableOutput]{ Phase: "after enablement", - OpFn: brotli_compression.Get, - ProductID: brotli_compression.ProductID, + OpFn: brotlicompression.Get, + ProductID: brotlicompression.ProductID, ServiceID: serviceID, }), productcore.NewDisableTest(&productcore.DisableTestInput{ - OpFn: brotli_compression.Disable, + OpFn: brotlicompression.Disable, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[brotlicompression.EnableOutput]{ Phase: "after disablement", - OpFn: brotli_compression.Get, - ProductID: brotli_compression.ProductID, + OpFn: brotlicompression.Get, + ProductID: brotlicompression.ProductID, ServiceID: serviceID, ExpectFailure: true, }), diff --git a/fastly/products/brotlicompression/doc.go b/fastly/products/brotlicompression/doc.go new file mode 100644 index 00000000..dba00639 --- /dev/null +++ b/fastly/products/brotlicompression/doc.go @@ -0,0 +1,3 @@ +// Package brotlicompression contains API operations to enable and +// disable the Brotli Compression product on a service +package brotlicompression diff --git a/fastly/products/brotli_compression/fixtures/disable-ensure-disabled-before-testing.yaml b/fastly/products/brotlicompression/fixtures/disable-ensure-disabled-before-testing.yaml similarity index 100% rename from fastly/products/brotli_compression/fixtures/disable-ensure-disabled-before-testing.yaml rename to fastly/products/brotlicompression/fixtures/disable-ensure-disabled-before-testing.yaml diff --git a/fastly/products/brotli_compression/fixtures/disable.yaml b/fastly/products/brotlicompression/fixtures/disable.yaml similarity index 100% rename from fastly/products/brotli_compression/fixtures/disable.yaml rename to fastly/products/brotlicompression/fixtures/disable.yaml diff --git a/fastly/products/brotli_compression/fixtures/enable.yaml b/fastly/products/brotlicompression/fixtures/enable.yaml similarity index 100% rename from fastly/products/brotli_compression/fixtures/enable.yaml rename to fastly/products/brotlicompression/fixtures/enable.yaml diff --git a/fastly/products/brotli_compression/fixtures/get-after-disablement.yaml b/fastly/products/brotlicompression/fixtures/get-after-disablement.yaml similarity index 100% rename from fastly/products/brotli_compression/fixtures/get-after-disablement.yaml rename to fastly/products/brotlicompression/fixtures/get-after-disablement.yaml diff --git a/fastly/products/brotli_compression/fixtures/get-after-enablement.yaml b/fastly/products/brotlicompression/fixtures/get-after-enablement.yaml similarity index 100% rename from fastly/products/brotli_compression/fixtures/get-after-enablement.yaml rename to fastly/products/brotlicompression/fixtures/get-after-enablement.yaml diff --git a/fastly/products/brotli_compression/fixtures/get-before-enablement.yaml b/fastly/products/brotlicompression/fixtures/get-before-enablement.yaml similarity index 100% rename from fastly/products/brotli_compression/fixtures/get-before-enablement.yaml rename to fastly/products/brotlicompression/fixtures/get-before-enablement.yaml diff --git a/fastly/products/ddos_protection/doc.go b/fastly/products/ddos_protection/doc.go deleted file mode 100644 index e5335082..00000000 --- a/fastly/products/ddos_protection/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package ddos_protection contains API operations to enable, disable, -// and configure the DDoS Protection product on a service -package ddos_protection diff --git a/fastly/products/ddos_protection/api.go b/fastly/products/ddosprotection/api.go similarity index 54% rename from fastly/products/ddos_protection/api.go rename to fastly/products/ddosprotection/api.go index b4ddb8a7..9cfad775 100644 --- a/fastly/products/ddos_protection/api.go +++ b/fastly/products/ddosprotection/api.go @@ -1,4 +1,4 @@ -package ddos_protection +package ddosprotection import ( "github.com/fastly/go-fastly/v9/fastly" @@ -6,17 +6,29 @@ import ( "github.com/fastly/go-fastly/v9/internal/productcore" ) -const ProductID = "ddos_protection" +const ( + ProductID = "ddos_protection" + ProductName = "DDoS Protection" +) + +// EnableOutput holds the details returned by the API from 'Get' and +// 'Enable' operations; this alias exists to ensure that users of this +// package will have a stable name to reference. +type EnableOutput = products.EnableOutput // ErrMissingMode is the error returned by the UpdateConfiguration // function when it is passed a ConfigureInput struct with a mode // field that is empty. var ErrMissingMode = fastly.NewFieldError("Mode") +// ConfigureInput holds the details required by the API's +// 'UpdateConfiguration' operation. type ConfigureInput struct { Mode string `json:"mode"` } +// ConfigureOutput holds the details returned by the API from +// 'GetConfiguration' and 'UpdateConfiguration' operations. type ConfigureOutput struct { products.ConfigureOutput `mapstructure:",squash"` Configuration *configureOutputNested `mapstructure:"configuration"` @@ -27,8 +39,8 @@ type configureOutputNested struct { } // Get gets the status of the DDoS Protection product on the service. -func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Get[*products.EnableOutput](&productcore.GetInput{ +func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Get[EnableOutput](&productcore.GetInput{ Client: c, ProductID: ProductID, ServiceID: serviceID, @@ -36,8 +48,8 @@ func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { } // Enable enables the DDoS Protection product on the service. -func Enable(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Put[*products.EnableOutput](&productcore.PutInput[*productcore.NullInput]{ +func Enable(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Put[EnableOutput](&productcore.PutInput[products.NullInput]{ Client: c, ProductID: ProductID, ServiceID: serviceID, @@ -54,8 +66,8 @@ func Disable(c *fastly.Client, serviceID string) error { } // GetConfiguration gets the configuration of the DDoS Protection product on the service. -func GetConfiguration(c *fastly.Client, serviceID string) (*ConfigureOutput, error) { - return productcore.Get[*ConfigureOutput](&productcore.GetInput{ +func GetConfiguration(c *fastly.Client, serviceID string) (ConfigureOutput, error) { + return productcore.Get[ConfigureOutput](&productcore.GetInput{ Client: c, ProductID: ProductID, ServiceID: serviceID, @@ -64,12 +76,12 @@ func GetConfiguration(c *fastly.Client, serviceID string) (*ConfigureOutput, err } // UpdateConfiguration updates the configuration of the DDoS Protection product on the service. -func UpdateConfiguration(c *fastly.Client, serviceID string, i *ConfigureInput) (*ConfigureOutput, error) { +func UpdateConfiguration(c *fastly.Client, serviceID string, i ConfigureInput) (ConfigureOutput, error) { if i.Mode == "" { - return nil, ErrMissingMode + return ConfigureOutput{}, ErrMissingMode } - return productcore.Patch[*ConfigureOutput](&productcore.PatchInput[*ConfigureInput]{ + return productcore.Patch[ConfigureOutput](&productcore.PatchInput[ConfigureInput]{ Client: c, ProductID: ProductID, ServiceID: serviceID, @@ -77,3 +89,9 @@ func UpdateConfiguration(c *fastly.Client, serviceID string, i *ConfigureInput) Input: i, }) } + +// NewEnableOutput is used to construct mock API output structures for +// use in tests. +func NewEnableOutput(serviceID string) EnableOutput { + return products.NewEnableOutput(ProductID, serviceID) +} diff --git a/fastly/products/ddos_protection/api_test.go b/fastly/products/ddosprotection/api_test.go similarity index 55% rename from fastly/products/ddos_protection/api_test.go rename to fastly/products/ddosprotection/api_test.go index 0cc433db..414c5c72 100644 --- a/fastly/products/ddos_protection/api_test.go +++ b/fastly/products/ddosprotection/api_test.go @@ -1,11 +1,11 @@ -package ddos_protection_test +package ddosprotection_test import ( "testing" "github.com/fastly/go-fastly/v9/fastly" "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/fastly/products/ddos_protection" + "github.com/fastly/go-fastly/v9/fastly/products/ddosprotection" "github.com/fastly/go-fastly/v9/internal/productcore" "github.com/fastly/go-fastly/v9/internal/test_utils" @@ -17,74 +17,74 @@ var serviceID = fastly.TestDeliveryServiceID func TestUpdateConfigurationMissingMode(t *testing.T) { t.Parallel() - _, err := ddos_protection.UpdateConfiguration(nil, serviceID, &ddos_protection.ConfigureInput{Mode: ""}) + _, err := ddosprotection.UpdateConfiguration(nil, serviceID, ddosprotection.ConfigureInput{Mode: ""}) - require.ErrorIs(t, err, ddos_protection.ErrMissingMode) + require.ErrorIs(t, err, ddosprotection.ErrMissingMode) } var functionalTests = []*test_utils.FunctionalTest{ productcore.NewDisableTest(&productcore.DisableTestInput{ Phase: "ensure disabled before testing", - OpFn: ddos_protection.Disable, + OpFn: ddosprotection.Disable, ServiceID: serviceID, IgnoreFailure: true, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[ddosprotection.EnableOutput]{ Phase: "before enablement", - OpFn: ddos_protection.Get, - ProductID: ddos_protection.ProductID, + OpFn: ddosprotection.Get, + ProductID: ddosprotection.ProductID, ServiceID: serviceID, ExpectFailure: true, }), - productcore.NewEnableTest(&productcore.EnableTestInput[*products.EnableOutput, *productcore.NullInput]{ - OpNoInputFn: ddos_protection.Enable, - ProductID: ddos_protection.ProductID, + productcore.NewEnableTest(&productcore.EnableTestInput[ddosprotection.EnableOutput, products.NullInput]{ + OpNoInputFn: ddosprotection.Enable, + ProductID: ddosprotection.ProductID, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[ddosprotection.EnableOutput]{ Phase: "after enablement", - OpFn: ddos_protection.Get, - ProductID: ddos_protection.ProductID, + OpFn: ddosprotection.Get, + ProductID: ddosprotection.ProductID, ServiceID: serviceID, }), - productcore.NewGetConfigurationTest(&productcore.GetConfigurationTestInput[*ddos_protection.ConfigureOutput]{ + productcore.NewGetConfigurationTest(&productcore.GetConfigurationTestInput[ddosprotection.ConfigureOutput]{ Phase: "default", - OpFn: ddos_protection.GetConfiguration, - ProductID: ddos_protection.ProductID, + OpFn: ddosprotection.GetConfiguration, + ProductID: ddosprotection.ProductID, ServiceID: serviceID, - CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, o *ddos_protection.ConfigureOutput) { + CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, o ddosprotection.ConfigureOutput) { require.NotNilf(t, o.Configuration.Mode, "test '%s'", tc.Name) require.Equalf(t, "log", *o.Configuration.Mode, "test '%s'", tc.Name) }, }), - productcore.NewUpdateConfigurationTest(&productcore.UpdateConfigurationTestInput[*ddos_protection.ConfigureOutput, *ddos_protection.ConfigureInput]{ - OpFn: ddos_protection.UpdateConfiguration, - Input: &ddos_protection.ConfigureInput{Mode: "block"}, - ProductID: ddos_protection.ProductID, + productcore.NewUpdateConfigurationTest(&productcore.UpdateConfigurationTestInput[ddosprotection.ConfigureOutput, ddosprotection.ConfigureInput]{ + OpFn: ddosprotection.UpdateConfiguration, + Input: ddosprotection.ConfigureInput{Mode: "block"}, + ProductID: ddosprotection.ProductID, ServiceID: serviceID, - CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, o *ddos_protection.ConfigureOutput) { + CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, o ddosprotection.ConfigureOutput) { require.NotNilf(t, o.Configuration.Mode, "test '%s'", tc.Name) require.Equalf(t, "block", *o.Configuration.Mode, "test '%s'", tc.Name) }, }), - productcore.NewGetConfigurationTest(&productcore.GetConfigurationTestInput[*ddos_protection.ConfigureOutput]{ + productcore.NewGetConfigurationTest(&productcore.GetConfigurationTestInput[ddosprotection.ConfigureOutput]{ Phase: "after update", - OpFn: ddos_protection.GetConfiguration, - ProductID: ddos_protection.ProductID, + OpFn: ddosprotection.GetConfiguration, + ProductID: ddosprotection.ProductID, ServiceID: serviceID, - CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, o *ddos_protection.ConfigureOutput) { + CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, o ddosprotection.ConfigureOutput) { require.NotNilf(t, o.Configuration.Mode, "test '%s'", tc.Name) require.Equalf(t, "block", *o.Configuration.Mode, "test '%s'", tc.Name) }, }), productcore.NewDisableTest(&productcore.DisableTestInput{ - OpFn: ddos_protection.Disable, + OpFn: ddosprotection.Disable, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[ddosprotection.EnableOutput]{ Phase: "after disablement", - OpFn: ddos_protection.Get, - ProductID: ddos_protection.ProductID, + OpFn: ddosprotection.Get, + ProductID: ddosprotection.ProductID, ServiceID: serviceID, ExpectFailure: true, }), diff --git a/fastly/products/ddosprotection/doc.go b/fastly/products/ddosprotection/doc.go new file mode 100644 index 00000000..ec75eaa7 --- /dev/null +++ b/fastly/products/ddosprotection/doc.go @@ -0,0 +1,3 @@ +// Package ddosprotection contains API operations to enable, disable, +// and configure the DDoS Protection product on a service +package ddosprotection diff --git a/fastly/products/ddos_protection/fixtures/disable-ensure-disabled-before-testing.yaml b/fastly/products/ddosprotection/fixtures/disable-ensure-disabled-before-testing.yaml similarity index 100% rename from fastly/products/ddos_protection/fixtures/disable-ensure-disabled-before-testing.yaml rename to fastly/products/ddosprotection/fixtures/disable-ensure-disabled-before-testing.yaml diff --git a/fastly/products/ddos_protection/fixtures/disable.yaml b/fastly/products/ddosprotection/fixtures/disable.yaml similarity index 100% rename from fastly/products/ddos_protection/fixtures/disable.yaml rename to fastly/products/ddosprotection/fixtures/disable.yaml diff --git a/fastly/products/ddos_protection/fixtures/enable.yaml b/fastly/products/ddosprotection/fixtures/enable.yaml similarity index 100% rename from fastly/products/ddos_protection/fixtures/enable.yaml rename to fastly/products/ddosprotection/fixtures/enable.yaml diff --git a/fastly/products/ddos_protection/fixtures/get-after-disablement.yaml b/fastly/products/ddosprotection/fixtures/get-after-disablement.yaml similarity index 100% rename from fastly/products/ddos_protection/fixtures/get-after-disablement.yaml rename to fastly/products/ddosprotection/fixtures/get-after-disablement.yaml diff --git a/fastly/products/ddos_protection/fixtures/get-after-enablement.yaml b/fastly/products/ddosprotection/fixtures/get-after-enablement.yaml similarity index 100% rename from fastly/products/ddos_protection/fixtures/get-after-enablement.yaml rename to fastly/products/ddosprotection/fixtures/get-after-enablement.yaml diff --git a/fastly/products/ddos_protection/fixtures/get-before-enablement.yaml b/fastly/products/ddosprotection/fixtures/get-before-enablement.yaml similarity index 100% rename from fastly/products/ddos_protection/fixtures/get-before-enablement.yaml rename to fastly/products/ddosprotection/fixtures/get-before-enablement.yaml diff --git a/fastly/products/ddos_protection/fixtures/get-configuration-after-update.yaml b/fastly/products/ddosprotection/fixtures/get-configuration-after-update.yaml similarity index 100% rename from fastly/products/ddos_protection/fixtures/get-configuration-after-update.yaml rename to fastly/products/ddosprotection/fixtures/get-configuration-after-update.yaml diff --git a/fastly/products/ddos_protection/fixtures/get-configuration-default.yaml b/fastly/products/ddosprotection/fixtures/get-configuration-default.yaml similarity index 100% rename from fastly/products/ddos_protection/fixtures/get-configuration-default.yaml rename to fastly/products/ddosprotection/fixtures/get-configuration-default.yaml diff --git a/fastly/products/ddos_protection/fixtures/update-configuration.yaml b/fastly/products/ddosprotection/fixtures/update-configuration.yaml similarity index 100% rename from fastly/products/ddos_protection/fixtures/update-configuration.yaml rename to fastly/products/ddosprotection/fixtures/update-configuration.yaml diff --git a/fastly/products/domain_inspector/api.go b/fastly/products/domain_inspector/api.go deleted file mode 100644 index cbe9659e..00000000 --- a/fastly/products/domain_inspector/api.go +++ /dev/null @@ -1,36 +0,0 @@ -package domain_inspector - -import ( - "github.com/fastly/go-fastly/v9/fastly" - "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/internal/productcore" -) - -const ProductID = "domain_inspector" - -// Get gets the status of the Domain Inspector product on the service. -func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Get[*products.EnableOutput](&productcore.GetInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Enable enables the Domain Inspector product on the service. -func Enable(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Put[*products.EnableOutput](&productcore.PutInput[*productcore.NullInput]{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Disable disables the Domain Inspector product on the service. -func Disable(c *fastly.Client, serviceID string) error { - return productcore.Delete(&productcore.DeleteInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} diff --git a/fastly/products/domain_inspector/doc.go b/fastly/products/domain_inspector/doc.go deleted file mode 100644 index 6e5a20d4..00000000 --- a/fastly/products/domain_inspector/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package domain_inspector contains API operations to enable and -// disable the Domain Inspector product on a service -package domain_inspector diff --git a/fastly/products/domaininspector/api.go b/fastly/products/domaininspector/api.go new file mode 100644 index 00000000..02dacb64 --- /dev/null +++ b/fastly/products/domaininspector/api.go @@ -0,0 +1,50 @@ +package domaininspector + +import ( + "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" + "github.com/fastly/go-fastly/v9/internal/productcore" +) + +const ( + ProductID = "domain_inspector" + ProductName = "Domain Inspector" +) + +// EnableOutput holds the details returned by the API from 'Get' and +// 'Enable' operations; this alias exists to ensure that users of this +// package will have a stable name to reference. +type EnableOutput = products.EnableOutput + +// Get gets the status of the Domain Inspector product on the service. +func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Get[EnableOutput](&productcore.GetInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Enable enables the Domain Inspector product on the service. +func Enable(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Put[EnableOutput](&productcore.PutInput[products.NullInput]{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Disable disables the Domain Inspector product on the service. +func Disable(c *fastly.Client, serviceID string) error { + return productcore.Delete(&productcore.DeleteInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// NewEnableOutput is used to construct mock API output structures for +// use in tests. +func NewEnableOutput(serviceID string) EnableOutput { + return products.NewEnableOutput(ProductID, serviceID) +} diff --git a/fastly/products/origin_inspector/api_test.go b/fastly/products/domaininspector/api_test.go similarity index 53% rename from fastly/products/origin_inspector/api_test.go rename to fastly/products/domaininspector/api_test.go index 0c8b839e..ebfad433 100644 --- a/fastly/products/origin_inspector/api_test.go +++ b/fastly/products/domaininspector/api_test.go @@ -1,11 +1,11 @@ -package origin_inspector_test +package domaininspector_test import ( "testing" "github.com/fastly/go-fastly/v9/fastly" "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/fastly/products/origin_inspector" + "github.com/fastly/go-fastly/v9/fastly/products/domaininspector" "github.com/fastly/go-fastly/v9/internal/productcore" "github.com/fastly/go-fastly/v9/internal/test_utils" ) @@ -15,36 +15,36 @@ var serviceID = fastly.TestDeliveryServiceID var functionalTests = []*test_utils.FunctionalTest{ productcore.NewDisableTest(&productcore.DisableTestInput{ Phase: "ensure disabled before testing", - OpFn: origin_inspector.Disable, + OpFn: domaininspector.Disable, ServiceID: serviceID, IgnoreFailure: true, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[domaininspector.EnableOutput]{ Phase: "before enablement", - OpFn: origin_inspector.Get, - ProductID: origin_inspector.ProductID, + OpFn: domaininspector.Get, + ProductID: domaininspector.ProductID, ServiceID: serviceID, ExpectFailure: true, }), - productcore.NewEnableTest(&productcore.EnableTestInput[*products.EnableOutput, *productcore.NullInput]{ - OpNoInputFn: origin_inspector.Enable, - ProductID: origin_inspector.ProductID, + productcore.NewEnableTest(&productcore.EnableTestInput[domaininspector.EnableOutput, products.NullInput]{ + OpNoInputFn: domaininspector.Enable, + ProductID: domaininspector.ProductID, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[domaininspector.EnableOutput]{ Phase: "after enablement", - OpFn: origin_inspector.Get, - ProductID: origin_inspector.ProductID, + OpFn: domaininspector.Get, + ProductID: domaininspector.ProductID, ServiceID: serviceID, }), productcore.NewDisableTest(&productcore.DisableTestInput{ - OpFn: origin_inspector.Disable, + OpFn: domaininspector.Disable, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[domaininspector.EnableOutput]{ Phase: "after disablement", - OpFn: origin_inspector.Get, - ProductID: origin_inspector.ProductID, + OpFn: domaininspector.Get, + ProductID: domaininspector.ProductID, ServiceID: serviceID, ExpectFailure: true, }), diff --git a/fastly/products/domaininspector/doc.go b/fastly/products/domaininspector/doc.go new file mode 100644 index 00000000..4ce81e23 --- /dev/null +++ b/fastly/products/domaininspector/doc.go @@ -0,0 +1,3 @@ +// Package domaininspector contains API operations to enable and +// disable the Domain Inspector product on a service +package domaininspector diff --git a/fastly/products/domain_inspector/fixtures/disable-ensure-disabled-before-testing.yaml b/fastly/products/domaininspector/fixtures/disable-ensure-disabled-before-testing.yaml similarity index 100% rename from fastly/products/domain_inspector/fixtures/disable-ensure-disabled-before-testing.yaml rename to fastly/products/domaininspector/fixtures/disable-ensure-disabled-before-testing.yaml diff --git a/fastly/products/domain_inspector/fixtures/disable.yaml b/fastly/products/domaininspector/fixtures/disable.yaml similarity index 100% rename from fastly/products/domain_inspector/fixtures/disable.yaml rename to fastly/products/domaininspector/fixtures/disable.yaml diff --git a/fastly/products/domain_inspector/fixtures/enable.yaml b/fastly/products/domaininspector/fixtures/enable.yaml similarity index 100% rename from fastly/products/domain_inspector/fixtures/enable.yaml rename to fastly/products/domaininspector/fixtures/enable.yaml diff --git a/fastly/products/domain_inspector/fixtures/get-after-disablement.yaml b/fastly/products/domaininspector/fixtures/get-after-disablement.yaml similarity index 100% rename from fastly/products/domain_inspector/fixtures/get-after-disablement.yaml rename to fastly/products/domaininspector/fixtures/get-after-disablement.yaml diff --git a/fastly/products/domain_inspector/fixtures/get-after-enablement.yaml b/fastly/products/domaininspector/fixtures/get-after-enablement.yaml similarity index 100% rename from fastly/products/domain_inspector/fixtures/get-after-enablement.yaml rename to fastly/products/domaininspector/fixtures/get-after-enablement.yaml diff --git a/fastly/products/domain_inspector/fixtures/get-before-enablement.yaml b/fastly/products/domaininspector/fixtures/get-before-enablement.yaml similarity index 100% rename from fastly/products/domain_inspector/fixtures/get-before-enablement.yaml rename to fastly/products/domaininspector/fixtures/get-before-enablement.yaml diff --git a/fastly/products/fanout/api.go b/fastly/products/fanout/api.go index 39548ec9..e02e85c1 100644 --- a/fastly/products/fanout/api.go +++ b/fastly/products/fanout/api.go @@ -6,11 +6,19 @@ import ( "github.com/fastly/go-fastly/v9/internal/productcore" ) -const ProductID = "fanout" +const ( + ProductID = "fanout" + ProductName = "Fanout" +) + +// EnableOutput holds the details returned by the API from 'Get' and +// 'Enable' operations; this alias exists to ensure that users of this +// package will have a stable name to reference. +type EnableOutput = products.EnableOutput // Get gets the status of the Fanout product on the service. -func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Get[*products.EnableOutput](&productcore.GetInput{ +func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Get[EnableOutput](&productcore.GetInput{ Client: c, ProductID: ProductID, ServiceID: serviceID, @@ -18,8 +26,8 @@ func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { } // Enable enables the Fanout product on the service. -func Enable(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Put[*products.EnableOutput](&productcore.PutInput[*productcore.NullInput]{ +func Enable(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Put[EnableOutput](&productcore.PutInput[products.NullInput]{ Client: c, ProductID: ProductID, ServiceID: serviceID, @@ -34,3 +42,9 @@ func Disable(c *fastly.Client, serviceID string) error { ServiceID: serviceID, }) } + +// NewEnableOutput is used to construct mock API output structures for +// use in tests. +func NewEnableOutput(serviceID string) EnableOutput { + return products.NewEnableOutput(ProductID, serviceID) +} diff --git a/fastly/products/fanout/api_test.go b/fastly/products/fanout/api_test.go index 177c7b27..2e435bd6 100644 --- a/fastly/products/fanout/api_test.go +++ b/fastly/products/fanout/api_test.go @@ -19,19 +19,19 @@ var functionalTests = []*test_utils.FunctionalTest{ ServiceID: serviceID, IgnoreFailure: true, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[fanout.EnableOutput]{ Phase: "before enablement", OpFn: fanout.Get, ProductID: fanout.ProductID, ServiceID: serviceID, ExpectFailure: true, }), - productcore.NewEnableTest(&productcore.EnableTestInput[*products.EnableOutput, *productcore.NullInput]{ + productcore.NewEnableTest(&productcore.EnableTestInput[fanout.EnableOutput, products.NullInput]{ OpNoInputFn: fanout.Enable, ProductID: fanout.ProductID, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[fanout.EnableOutput]{ Phase: "after enablement", OpFn: fanout.Get, ProductID: fanout.ProductID, @@ -41,7 +41,7 @@ var functionalTests = []*test_utils.FunctionalTest{ OpFn: fanout.Disable, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[fanout.EnableOutput]{ Phase: "after disablement", OpFn: fanout.Get, ProductID: fanout.ProductID, diff --git a/fastly/products/image_optimizer/api.go b/fastly/products/image_optimizer/api.go deleted file mode 100644 index d808c8af..00000000 --- a/fastly/products/image_optimizer/api.go +++ /dev/null @@ -1,36 +0,0 @@ -package image_optimizer - -import ( - "github.com/fastly/go-fastly/v9/fastly" - "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/internal/productcore" -) - -const ProductID = "image_optimizer" - -// Get gets the status of the Image Optimizer product on the service. -func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Get[*products.EnableOutput](&productcore.GetInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Enable enables the Image Optimizer product on the service. -func Enable(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Put[*products.EnableOutput](&productcore.PutInput[*productcore.NullInput]{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Disable disables the Image Optimizer product on the service. -func Disable(c *fastly.Client, serviceID string) error { - return productcore.Delete(&productcore.DeleteInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} diff --git a/fastly/products/image_optimizer/doc.go b/fastly/products/image_optimizer/doc.go deleted file mode 100644 index bad0f4a7..00000000 --- a/fastly/products/image_optimizer/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package image_optimizer contains API operations to enable and -// disable the Image Optimizer product on a service -package image_optimizer diff --git a/fastly/products/imageoptimizer/api.go b/fastly/products/imageoptimizer/api.go new file mode 100644 index 00000000..fbd6aa57 --- /dev/null +++ b/fastly/products/imageoptimizer/api.go @@ -0,0 +1,50 @@ +package imageoptimizer + +import ( + "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" + "github.com/fastly/go-fastly/v9/internal/productcore" +) + +const ( + ProductID = "image_optimizer" + ProductName = "Image Optimizer" +) + +// EnableOutput holds the details returned by the API from 'Get' and +// 'Enable' operations; this alias exists to ensure that users of this +// package will have a stable name to reference. +type EnableOutput = products.EnableOutput + +// Get gets the status of the Image Optimizer product on the service. +func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Get[EnableOutput](&productcore.GetInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Enable enables the Image Optimizer product on the service. +func Enable(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Put[EnableOutput](&productcore.PutInput[products.NullInput]{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Disable disables the Image Optimizer product on the service. +func Disable(c *fastly.Client, serviceID string) error { + return productcore.Delete(&productcore.DeleteInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// NewEnableOutput is used to construct mock API output structures for +// use in tests. +func NewEnableOutput(serviceID string) EnableOutput { + return products.NewEnableOutput(ProductID, serviceID) +} diff --git a/fastly/products/image_optimizer/api_test.go b/fastly/products/imageoptimizer/api_test.go similarity index 53% rename from fastly/products/image_optimizer/api_test.go rename to fastly/products/imageoptimizer/api_test.go index 20535913..1f773ffd 100644 --- a/fastly/products/image_optimizer/api_test.go +++ b/fastly/products/imageoptimizer/api_test.go @@ -1,11 +1,11 @@ -package image_optimizer_test +package imageoptimizer_test import ( "testing" "github.com/fastly/go-fastly/v9/fastly" "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/fastly/products/image_optimizer" + "github.com/fastly/go-fastly/v9/fastly/products/imageoptimizer" "github.com/fastly/go-fastly/v9/internal/productcore" "github.com/fastly/go-fastly/v9/internal/test_utils" ) @@ -15,36 +15,36 @@ var serviceID = fastly.TestDeliveryServiceID var functionalTests = []*test_utils.FunctionalTest{ productcore.NewDisableTest(&productcore.DisableTestInput{ Phase: "ensure disabled before testing", - OpFn: image_optimizer.Disable, + OpFn: imageoptimizer.Disable, ServiceID: serviceID, IgnoreFailure: true, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[imageoptimizer.EnableOutput]{ Phase: "before enablement", - OpFn: image_optimizer.Get, - ProductID: image_optimizer.ProductID, + OpFn: imageoptimizer.Get, + ProductID: imageoptimizer.ProductID, ServiceID: serviceID, ExpectFailure: true, }), - productcore.NewEnableTest(&productcore.EnableTestInput[*products.EnableOutput, *productcore.NullInput]{ - OpNoInputFn: image_optimizer.Enable, - ProductID: image_optimizer.ProductID, + productcore.NewEnableTest(&productcore.EnableTestInput[imageoptimizer.EnableOutput, products.NullInput]{ + OpNoInputFn: imageoptimizer.Enable, + ProductID: imageoptimizer.ProductID, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[imageoptimizer.EnableOutput]{ Phase: "after enablement", - OpFn: image_optimizer.Get, - ProductID: image_optimizer.ProductID, + OpFn: imageoptimizer.Get, + ProductID: imageoptimizer.ProductID, ServiceID: serviceID, }), productcore.NewDisableTest(&productcore.DisableTestInput{ - OpFn: image_optimizer.Disable, + OpFn: imageoptimizer.Disable, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[imageoptimizer.EnableOutput]{ Phase: "after disablement", - OpFn: image_optimizer.Get, - ProductID: image_optimizer.ProductID, + OpFn: imageoptimizer.Get, + ProductID: imageoptimizer.ProductID, ServiceID: serviceID, ExpectFailure: true, }), diff --git a/fastly/products/imageoptimizer/doc.go b/fastly/products/imageoptimizer/doc.go new file mode 100644 index 00000000..170c0f2e --- /dev/null +++ b/fastly/products/imageoptimizer/doc.go @@ -0,0 +1,3 @@ +// Package imageoptimizer contains API operations to enable and +// disable the Image Optimizer product on a service +package imageoptimizer diff --git a/fastly/products/image_optimizer/fixtures/disable-ensure-disabled-before-testing.yaml b/fastly/products/imageoptimizer/fixtures/disable-ensure-disabled-before-testing.yaml similarity index 100% rename from fastly/products/image_optimizer/fixtures/disable-ensure-disabled-before-testing.yaml rename to fastly/products/imageoptimizer/fixtures/disable-ensure-disabled-before-testing.yaml diff --git a/fastly/products/image_optimizer/fixtures/disable.yaml b/fastly/products/imageoptimizer/fixtures/disable.yaml similarity index 100% rename from fastly/products/image_optimizer/fixtures/disable.yaml rename to fastly/products/imageoptimizer/fixtures/disable.yaml diff --git a/fastly/products/image_optimizer/fixtures/enable.yaml b/fastly/products/imageoptimizer/fixtures/enable.yaml similarity index 100% rename from fastly/products/image_optimizer/fixtures/enable.yaml rename to fastly/products/imageoptimizer/fixtures/enable.yaml diff --git a/fastly/products/image_optimizer/fixtures/get-after-disablement.yaml b/fastly/products/imageoptimizer/fixtures/get-after-disablement.yaml similarity index 100% rename from fastly/products/image_optimizer/fixtures/get-after-disablement.yaml rename to fastly/products/imageoptimizer/fixtures/get-after-disablement.yaml diff --git a/fastly/products/image_optimizer/fixtures/get-after-enablement.yaml b/fastly/products/imageoptimizer/fixtures/get-after-enablement.yaml similarity index 100% rename from fastly/products/image_optimizer/fixtures/get-after-enablement.yaml rename to fastly/products/imageoptimizer/fixtures/get-after-enablement.yaml diff --git a/fastly/products/image_optimizer/fixtures/get-before-enablement.yaml b/fastly/products/imageoptimizer/fixtures/get-before-enablement.yaml similarity index 100% rename from fastly/products/image_optimizer/fixtures/get-before-enablement.yaml rename to fastly/products/imageoptimizer/fixtures/get-before-enablement.yaml diff --git a/fastly/products/log_explorer_insights/api.go b/fastly/products/log_explorer_insights/api.go deleted file mode 100644 index 82b1dfba..00000000 --- a/fastly/products/log_explorer_insights/api.go +++ /dev/null @@ -1,36 +0,0 @@ -package log_explorer_insights - -import ( - "github.com/fastly/go-fastly/v9/fastly" - "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/internal/productcore" -) - -const ProductID = "log_explorer_insights" - -// Get gets the status of the Log Explorer Bot Management Insights product on the service. -func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Get[*products.EnableOutput](&productcore.GetInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Enable enables the Log Explorer Bot Management Insights product on the service. -func Enable(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Put[*products.EnableOutput](&productcore.PutInput[*productcore.NullInput]{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Disable disables the Log Explorer Bot Management Insights product on the service. -func Disable(c *fastly.Client, serviceID string) error { - return productcore.Delete(&productcore.DeleteInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} diff --git a/fastly/products/log_explorer_insights/api_test.go b/fastly/products/log_explorer_insights/api_test.go deleted file mode 100644 index 2657faef..00000000 --- a/fastly/products/log_explorer_insights/api_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package log_explorer_insights_test - -import ( - "testing" - - "github.com/fastly/go-fastly/v9/fastly" - "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/fastly/products/log_explorer_insights" - "github.com/fastly/go-fastly/v9/internal/productcore" - "github.com/fastly/go-fastly/v9/internal/test_utils" -) - -var serviceID = fastly.TestDeliveryServiceID - -var functionalTests = []*test_utils.FunctionalTest{ - productcore.NewDisableTest(&productcore.DisableTestInput{ - Phase: "ensure disabled before testing", - OpFn: log_explorer_insights.Disable, - ServiceID: serviceID, - IgnoreFailure: true, - }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ - Phase: "before enablement", - OpFn: log_explorer_insights.Get, - ProductID: log_explorer_insights.ProductID, - ServiceID: serviceID, - ExpectFailure: true, - }), - productcore.NewEnableTest(&productcore.EnableTestInput[*products.EnableOutput, *productcore.NullInput]{ - OpNoInputFn: log_explorer_insights.Enable, - ProductID: log_explorer_insights.ProductID, - ServiceID: serviceID, - }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ - Phase: "after enablement", - OpFn: log_explorer_insights.Get, - ProductID: log_explorer_insights.ProductID, - ServiceID: serviceID, - }), - productcore.NewDisableTest(&productcore.DisableTestInput{ - OpFn: log_explorer_insights.Disable, - ServiceID: serviceID, - }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ - Phase: "after disablement", - OpFn: log_explorer_insights.Get, - ProductID: log_explorer_insights.ProductID, - ServiceID: serviceID, - ExpectFailure: true, - }), -} - -func TestEnablement(t *testing.T) { - test_utils.ExecuteFunctionalTests(t, functionalTests) -} diff --git a/fastly/products/log_explorer_insights/doc.go b/fastly/products/log_explorer_insights/doc.go deleted file mode 100644 index 714d19bb..00000000 --- a/fastly/products/log_explorer_insights/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package log_explorer_insights contains API operations to enable and -// disable the Log Explorer & Insights product on a service -package log_explorer_insights diff --git a/fastly/products/logexplorerinsights/api.go b/fastly/products/logexplorerinsights/api.go new file mode 100644 index 00000000..422b703b --- /dev/null +++ b/fastly/products/logexplorerinsights/api.go @@ -0,0 +1,50 @@ +package logexplorerinsights + +import ( + "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" + "github.com/fastly/go-fastly/v9/internal/productcore" +) + +const ( + ProductID = "log_explorer_insights" + ProductName = "Log Explorer & Insights" +) + +// EnableOutput holds the details returned by the API from 'Get' and +// 'Enable' operations; this alias exists to ensure that users of this +// package will have a stable name to reference. +type EnableOutput = products.EnableOutput + +// Get gets the status of the Log Explorer Bot Management Insights product on the service. +func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Get[EnableOutput](&productcore.GetInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Enable enables the Log Explorer Bot Management Insights product on the service. +func Enable(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Put[EnableOutput](&productcore.PutInput[products.NullInput]{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Disable disables the Log Explorer Bot Management Insights product on the service. +func Disable(c *fastly.Client, serviceID string) error { + return productcore.Delete(&productcore.DeleteInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// NewEnableOutput is used to construct mock API output structures for +// use in tests. +func NewEnableOutput(serviceID string) EnableOutput { + return products.NewEnableOutput(ProductID, serviceID) +} diff --git a/fastly/products/logexplorerinsights/api_test.go b/fastly/products/logexplorerinsights/api_test.go new file mode 100644 index 00000000..839e7850 --- /dev/null +++ b/fastly/products/logexplorerinsights/api_test.go @@ -0,0 +1,55 @@ +package logexplorerinsights_test + +import ( + "testing" + + "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" + "github.com/fastly/go-fastly/v9/fastly/products/logexplorerinsights" + "github.com/fastly/go-fastly/v9/internal/productcore" + "github.com/fastly/go-fastly/v9/internal/test_utils" +) + +var serviceID = fastly.TestDeliveryServiceID + +var functionalTests = []*test_utils.FunctionalTest{ + productcore.NewDisableTest(&productcore.DisableTestInput{ + Phase: "ensure disabled before testing", + OpFn: logexplorerinsights.Disable, + ServiceID: serviceID, + IgnoreFailure: true, + }), + productcore.NewGetTest(&productcore.GetTestInput[logexplorerinsights.EnableOutput]{ + Phase: "before enablement", + OpFn: logexplorerinsights.Get, + ProductID: logexplorerinsights.ProductID, + ServiceID: serviceID, + ExpectFailure: true, + }), + productcore.NewEnableTest(&productcore.EnableTestInput[logexplorerinsights.EnableOutput, products.NullInput]{ + OpNoInputFn: logexplorerinsights.Enable, + ProductID: logexplorerinsights.ProductID, + ServiceID: serviceID, + }), + productcore.NewGetTest(&productcore.GetTestInput[logexplorerinsights.EnableOutput]{ + Phase: "after enablement", + OpFn: logexplorerinsights.Get, + ProductID: logexplorerinsights.ProductID, + ServiceID: serviceID, + }), + productcore.NewDisableTest(&productcore.DisableTestInput{ + OpFn: logexplorerinsights.Disable, + ServiceID: serviceID, + }), + productcore.NewGetTest(&productcore.GetTestInput[logexplorerinsights.EnableOutput]{ + Phase: "after disablement", + OpFn: logexplorerinsights.Get, + ProductID: logexplorerinsights.ProductID, + ServiceID: serviceID, + ExpectFailure: true, + }), +} + +func TestEnablement(t *testing.T) { + test_utils.ExecuteFunctionalTests(t, functionalTests) +} diff --git a/fastly/products/logexplorerinsights/doc.go b/fastly/products/logexplorerinsights/doc.go new file mode 100644 index 00000000..4703d0f4 --- /dev/null +++ b/fastly/products/logexplorerinsights/doc.go @@ -0,0 +1,3 @@ +// Package logexplorerinsights contains API operations to enable and +// disable the Log Explorer & Insights product on a service +package logexplorerinsights diff --git a/fastly/products/log_explorer_insights/fixtures/disable-ensure-disabled-before-testing.yaml b/fastly/products/logexplorerinsights/fixtures/disable-ensure-disabled-before-testing.yaml similarity index 100% rename from fastly/products/log_explorer_insights/fixtures/disable-ensure-disabled-before-testing.yaml rename to fastly/products/logexplorerinsights/fixtures/disable-ensure-disabled-before-testing.yaml diff --git a/fastly/products/log_explorer_insights/fixtures/disable.yaml b/fastly/products/logexplorerinsights/fixtures/disable.yaml similarity index 100% rename from fastly/products/log_explorer_insights/fixtures/disable.yaml rename to fastly/products/logexplorerinsights/fixtures/disable.yaml diff --git a/fastly/products/log_explorer_insights/fixtures/enable.yaml b/fastly/products/logexplorerinsights/fixtures/enable.yaml similarity index 100% rename from fastly/products/log_explorer_insights/fixtures/enable.yaml rename to fastly/products/logexplorerinsights/fixtures/enable.yaml diff --git a/fastly/products/log_explorer_insights/fixtures/get-after-disablement.yaml b/fastly/products/logexplorerinsights/fixtures/get-after-disablement.yaml similarity index 100% rename from fastly/products/log_explorer_insights/fixtures/get-after-disablement.yaml rename to fastly/products/logexplorerinsights/fixtures/get-after-disablement.yaml diff --git a/fastly/products/log_explorer_insights/fixtures/get-after-enablement.yaml b/fastly/products/logexplorerinsights/fixtures/get-after-enablement.yaml similarity index 100% rename from fastly/products/log_explorer_insights/fixtures/get-after-enablement.yaml rename to fastly/products/logexplorerinsights/fixtures/get-after-enablement.yaml diff --git a/fastly/products/log_explorer_insights/fixtures/get-before-enablement.yaml b/fastly/products/logexplorerinsights/fixtures/get-before-enablement.yaml similarity index 100% rename from fastly/products/log_explorer_insights/fixtures/get-before-enablement.yaml rename to fastly/products/logexplorerinsights/fixtures/get-before-enablement.yaml diff --git a/fastly/products/ngwaf/api.go b/fastly/products/ngwaf/api.go index 092b70ff..4dadb04f 100644 --- a/fastly/products/ngwaf/api.go +++ b/fastly/products/ngwaf/api.go @@ -6,22 +6,36 @@ import ( "github.com/fastly/go-fastly/v9/internal/productcore" ) -const ProductID = "ngwaf" +const ( + ProductID = "ngwaf" + ProductName = "Next-Gen WAF" +) + +// EnableInput holds the details required by the API's 'Enable' +// operation. +type EnableInput struct { + WorkspaceID string `json:"workspace_id"` +} + +// EnableOutput holds the details returned by the API from 'Get' and +// 'Enable' operations; this alias exists to ensure that users of this +// package will have a stable name to reference. +type EnableOutput = products.EnableOutput // ErrMissingWorkspaceID is the error returned by the Enable function // when it is passed an EnableInput struct with a WorkspaceID field // that is empty. var ErrMissingWorkspaceID = fastly.NewFieldError("WorkspaceID") -type EnableInput struct { - WorkspaceID string `json:"workspace_id"` -} - +// ConfigureInput holds the details required by the API's +// 'UpdateConfiguration' operation. type ConfigureInput struct { WorkspaceID string `json:"workspace_id,omitempty"` TrafficRamp string `json:"traffic_ramp,omitempty"` } +// ConfigureOutput holds the details returned by the API from +// 'GetConfiguration' and 'UpdateConfiguration' operations. type ConfigureOutput struct { products.ConfigureOutput `mapstructure:",squash"` Configuration *configureOutputNested `mapstructure:"configuration"` @@ -33,8 +47,8 @@ type configureOutputNested struct { } // Get gets the status of the Next-Gen WAF product on the service. -func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Get[*products.EnableOutput](&productcore.GetInput{ +func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Get[EnableOutput](&productcore.GetInput{ Client: c, ProductID: ProductID, ServiceID: serviceID, @@ -42,12 +56,12 @@ func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { } // Enable enables the Next-Gen WAF product on the service. -func Enable(c *fastly.Client, serviceID string, i *EnableInput) (*products.EnableOutput, error) { +func Enable(c *fastly.Client, serviceID string, i EnableInput) (EnableOutput, error) { if i.WorkspaceID == "" { - return nil, ErrMissingWorkspaceID + return EnableOutput{}, ErrMissingWorkspaceID } - return productcore.Put[*products.EnableOutput](&productcore.PutInput[*EnableInput]{ + return productcore.Put[EnableOutput](&productcore.PutInput[EnableInput]{ Client: c, ProductID: ProductID, ServiceID: serviceID, @@ -65,8 +79,8 @@ func Disable(c *fastly.Client, serviceID string) error { } // GetConfiguration gets the configuration of the Next-Gen WAF product on the service. -func GetConfiguration(c *fastly.Client, serviceID string) (*ConfigureOutput, error) { - return productcore.Get[*ConfigureOutput](&productcore.GetInput{ +func GetConfiguration(c *fastly.Client, serviceID string) (ConfigureOutput, error) { + return productcore.Get[ConfigureOutput](&productcore.GetInput{ Client: c, ProductID: ProductID, ServiceID: serviceID, @@ -75,8 +89,8 @@ func GetConfiguration(c *fastly.Client, serviceID string) (*ConfigureOutput, err } // UpdateConfiguration updates the configuration of the Next-Gen WAF product on the service. -func UpdateConfiguration(c *fastly.Client, serviceID string, i *ConfigureInput) (*ConfigureOutput, error) { - return productcore.Patch[*ConfigureOutput](&productcore.PatchInput[*ConfigureInput]{ +func UpdateConfiguration(c *fastly.Client, serviceID string, i ConfigureInput) (ConfigureOutput, error) { + return productcore.Patch[ConfigureOutput](&productcore.PatchInput[ConfigureInput]{ Client: c, ProductID: ProductID, ServiceID: serviceID, diff --git a/fastly/products/ngwaf/api_test.go b/fastly/products/ngwaf/api_test.go index 1bae43fd..cbe29410 100644 --- a/fastly/products/ngwaf/api_test.go +++ b/fastly/products/ngwaf/api_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/fastly/go-fastly/v9/fastly" - "github.com/fastly/go-fastly/v9/fastly/products" "github.com/fastly/go-fastly/v9/fastly/products/ngwaf" "github.com/fastly/go-fastly/v9/internal/productcore" "github.com/fastly/go-fastly/v9/internal/test_utils" @@ -17,7 +16,7 @@ var serviceID = fastly.TestDeliveryServiceID func TestEnableMissingWorkspaceID(t *testing.T) { t.Parallel() - _, err := ngwaf.Enable(nil, serviceID, &ngwaf.EnableInput{WorkspaceID: ""}) + _, err := ngwaf.Enable(nil, serviceID, ngwaf.EnableInput{WorkspaceID: ""}) require.ErrorIs(t, err, ngwaf.ErrMissingWorkspaceID) } @@ -29,51 +28,51 @@ var functionalTests = []*test_utils.FunctionalTest{ ServiceID: serviceID, IgnoreFailure: true, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[ngwaf.EnableOutput]{ Phase: "before enablement", OpFn: ngwaf.Get, ProductID: ngwaf.ProductID, ServiceID: serviceID, ExpectFailure: true, }), - productcore.NewEnableTest(&productcore.EnableTestInput[*products.EnableOutput, *ngwaf.EnableInput]{ + productcore.NewEnableTest(&productcore.EnableTestInput[ngwaf.EnableOutput, ngwaf.EnableInput]{ OpWithInputFn: ngwaf.Enable, - Input: &ngwaf.EnableInput{WorkspaceID: fastly.TestNGWAFWorkspaceID}, + Input: ngwaf.EnableInput{WorkspaceID: fastly.TestNGWAFWorkspaceID}, ProductID: ngwaf.ProductID, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[ngwaf.EnableOutput]{ Phase: "after enablement", OpFn: ngwaf.Get, ProductID: ngwaf.ProductID, ServiceID: serviceID, }), - productcore.NewGetConfigurationTest(&productcore.GetConfigurationTestInput[*ngwaf.ConfigureOutput]{ + productcore.NewGetConfigurationTest(&productcore.GetConfigurationTestInput[ngwaf.ConfigureOutput]{ Phase: "default", OpFn: ngwaf.GetConfiguration, ProductID: ngwaf.ProductID, ServiceID: serviceID, - CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, output *ngwaf.ConfigureOutput) { + CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, output ngwaf.ConfigureOutput) { require.NotNilf(t, output.Configuration.TrafficRamp, "test '%s'", tc.Name) require.Equalf(t, "100", *output.Configuration.TrafficRamp, "test '%s'", tc.Name) }, }), - productcore.NewUpdateConfigurationTest(&productcore.UpdateConfigurationTestInput[*ngwaf.ConfigureOutput, *ngwaf.ConfigureInput]{ + productcore.NewUpdateConfigurationTest(&productcore.UpdateConfigurationTestInput[ngwaf.ConfigureOutput, ngwaf.ConfigureInput]{ OpFn: ngwaf.UpdateConfiguration, - Input: &ngwaf.ConfigureInput{TrafficRamp: "45"}, + Input: ngwaf.ConfigureInput{TrafficRamp: "45"}, ProductID: ngwaf.ProductID, ServiceID: serviceID, - CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, output *ngwaf.ConfigureOutput) { + CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, output ngwaf.ConfigureOutput) { require.NotNilf(t, output.Configuration.TrafficRamp, "test '%s'", tc.Name) require.Equalf(t, "45", *output.Configuration.TrafficRamp, "test '%s'", tc.Name) }, }), - productcore.NewGetConfigurationTest(&productcore.GetConfigurationTestInput[*ngwaf.ConfigureOutput]{ + productcore.NewGetConfigurationTest(&productcore.GetConfigurationTestInput[ngwaf.ConfigureOutput]{ Phase: "after update", OpFn: ngwaf.GetConfiguration, ProductID: ngwaf.ProductID, ServiceID: serviceID, - CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, output *ngwaf.ConfigureOutput) { + CheckOutputFn: func(t *testing.T, tc *test_utils.FunctionalTest, output ngwaf.ConfigureOutput) { require.NotNilf(t, output.Configuration.TrafficRamp, "test '%s'", tc.Name) require.Equalf(t, "45", *output.Configuration.TrafficRamp, "test '%s'", tc.Name) }, @@ -82,7 +81,7 @@ var functionalTests = []*test_utils.FunctionalTest{ OpFn: ngwaf.Disable, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[ngwaf.EnableOutput]{ Phase: "after disablement", OpFn: ngwaf.Get, ProductID: ngwaf.ProductID, diff --git a/fastly/products/origin_inspector/api.go b/fastly/products/origin_inspector/api.go deleted file mode 100644 index 64429ef3..00000000 --- a/fastly/products/origin_inspector/api.go +++ /dev/null @@ -1,36 +0,0 @@ -package origin_inspector - -import ( - "github.com/fastly/go-fastly/v9/fastly" - "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/internal/productcore" -) - -const ProductID = "origin_inspector" - -// Get gets the status of the Origin Inspector product on the service. -func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Get[*products.EnableOutput](&productcore.GetInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Enable enables the Origin Inspector product on the service. -func Enable(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Put[*products.EnableOutput](&productcore.PutInput[*productcore.NullInput]{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} - -// Disable disables the Origin Inspector product on the service. -func Disable(c *fastly.Client, serviceID string) error { - return productcore.Delete(&productcore.DeleteInput{ - Client: c, - ProductID: ProductID, - ServiceID: serviceID, - }) -} diff --git a/fastly/products/origin_inspector/doc.go b/fastly/products/origin_inspector/doc.go deleted file mode 100644 index 6ae21cdb..00000000 --- a/fastly/products/origin_inspector/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package origin_inspector contains API operations to enable and -// disable the Origin Inspector product on a service -package origin_inspector diff --git a/fastly/products/origininspector/api.go b/fastly/products/origininspector/api.go new file mode 100644 index 00000000..8176e281 --- /dev/null +++ b/fastly/products/origininspector/api.go @@ -0,0 +1,50 @@ +package origininspector + +import ( + "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" + "github.com/fastly/go-fastly/v9/internal/productcore" +) + +const ( + ProductID = "origin_inspector" + ProductName = "Origin Inspector" +) + +// EnableOutput holds the details returned by the API from 'Get' and +// 'Enable' operations; this alias exists to ensure that users of this +// package will have a stable name to reference. +type EnableOutput = products.EnableOutput + +// Get gets the status of the Origin Inspector product on the service. +func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Get[EnableOutput](&productcore.GetInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Enable enables the Origin Inspector product on the service. +func Enable(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Put[EnableOutput](&productcore.PutInput[products.NullInput]{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// Disable disables the Origin Inspector product on the service. +func Disable(c *fastly.Client, serviceID string) error { + return productcore.Delete(&productcore.DeleteInput{ + Client: c, + ProductID: ProductID, + ServiceID: serviceID, + }) +} + +// NewEnableOutput is used to construct mock API output structures for +// use in tests. +func NewEnableOutput(serviceID string) EnableOutput { + return products.NewEnableOutput(ProductID, serviceID) +} diff --git a/fastly/products/domain_inspector/api_test.go b/fastly/products/origininspector/api_test.go similarity index 53% rename from fastly/products/domain_inspector/api_test.go rename to fastly/products/origininspector/api_test.go index fe426ae7..6cd77daa 100644 --- a/fastly/products/domain_inspector/api_test.go +++ b/fastly/products/origininspector/api_test.go @@ -1,11 +1,11 @@ -package domain_inspector_test +package origininspector_test import ( "testing" "github.com/fastly/go-fastly/v9/fastly" "github.com/fastly/go-fastly/v9/fastly/products" - "github.com/fastly/go-fastly/v9/fastly/products/domain_inspector" + "github.com/fastly/go-fastly/v9/fastly/products/origininspector" "github.com/fastly/go-fastly/v9/internal/productcore" "github.com/fastly/go-fastly/v9/internal/test_utils" ) @@ -15,36 +15,36 @@ var serviceID = fastly.TestDeliveryServiceID var functionalTests = []*test_utils.FunctionalTest{ productcore.NewDisableTest(&productcore.DisableTestInput{ Phase: "ensure disabled before testing", - OpFn: domain_inspector.Disable, + OpFn: origininspector.Disable, ServiceID: serviceID, IgnoreFailure: true, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[origininspector.EnableOutput]{ Phase: "before enablement", - OpFn: domain_inspector.Get, - ProductID: domain_inspector.ProductID, + OpFn: origininspector.Get, + ProductID: origininspector.ProductID, ServiceID: serviceID, ExpectFailure: true, }), - productcore.NewEnableTest(&productcore.EnableTestInput[*products.EnableOutput, *productcore.NullInput]{ - OpNoInputFn: domain_inspector.Enable, - ProductID: domain_inspector.ProductID, + productcore.NewEnableTest(&productcore.EnableTestInput[origininspector.EnableOutput, products.NullInput]{ + OpNoInputFn: origininspector.Enable, + ProductID: origininspector.ProductID, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[origininspector.EnableOutput]{ Phase: "after enablement", - OpFn: domain_inspector.Get, - ProductID: domain_inspector.ProductID, + OpFn: origininspector.Get, + ProductID: origininspector.ProductID, ServiceID: serviceID, }), productcore.NewDisableTest(&productcore.DisableTestInput{ - OpFn: domain_inspector.Disable, + OpFn: origininspector.Disable, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[origininspector.EnableOutput]{ Phase: "after disablement", - OpFn: domain_inspector.Get, - ProductID: domain_inspector.ProductID, + OpFn: origininspector.Get, + ProductID: origininspector.ProductID, ServiceID: serviceID, ExpectFailure: true, }), diff --git a/fastly/products/origininspector/doc.go b/fastly/products/origininspector/doc.go new file mode 100644 index 00000000..e5e56701 --- /dev/null +++ b/fastly/products/origininspector/doc.go @@ -0,0 +1,3 @@ +// Package origininspector contains API operations to enable and +// disable the Origin Inspector product on a service +package origininspector diff --git a/fastly/products/origin_inspector/fixtures/disable-ensure-disabled-before-testing.yaml b/fastly/products/origininspector/fixtures/disable-ensure-disabled-before-testing.yaml similarity index 100% rename from fastly/products/origin_inspector/fixtures/disable-ensure-disabled-before-testing.yaml rename to fastly/products/origininspector/fixtures/disable-ensure-disabled-before-testing.yaml diff --git a/fastly/products/origin_inspector/fixtures/disable.yaml b/fastly/products/origininspector/fixtures/disable.yaml similarity index 100% rename from fastly/products/origin_inspector/fixtures/disable.yaml rename to fastly/products/origininspector/fixtures/disable.yaml diff --git a/fastly/products/origin_inspector/fixtures/enable.yaml b/fastly/products/origininspector/fixtures/enable.yaml similarity index 100% rename from fastly/products/origin_inspector/fixtures/enable.yaml rename to fastly/products/origininspector/fixtures/enable.yaml diff --git a/fastly/products/origin_inspector/fixtures/get-after-disablement.yaml b/fastly/products/origininspector/fixtures/get-after-disablement.yaml similarity index 100% rename from fastly/products/origin_inspector/fixtures/get-after-disablement.yaml rename to fastly/products/origininspector/fixtures/get-after-disablement.yaml diff --git a/fastly/products/origin_inspector/fixtures/get-after-enablement.yaml b/fastly/products/origininspector/fixtures/get-after-enablement.yaml similarity index 100% rename from fastly/products/origin_inspector/fixtures/get-after-enablement.yaml rename to fastly/products/origininspector/fixtures/get-after-enablement.yaml diff --git a/fastly/products/origin_inspector/fixtures/get-before-enablement.yaml b/fastly/products/origininspector/fixtures/get-before-enablement.yaml similarity index 100% rename from fastly/products/origin_inspector/fixtures/get-before-enablement.yaml rename to fastly/products/origininspector/fixtures/get-before-enablement.yaml diff --git a/fastly/products/types.go b/fastly/products/types.go new file mode 100644 index 00000000..44bddff8 --- /dev/null +++ b/fastly/products/types.go @@ -0,0 +1,82 @@ +package products + +import "github.com/fastly/go-fastly/v9/fastly" + +// ProductOutput is an interface used to constrain the 'O' type +// parameters of API operation functions. Use of this interface allows +// the FunctionalTest constructors to apply common validation steps to +// the output received from an API operation, eliminating the need to +// duplicate that validation in every FunctionalTest case, and ensures +// that the API operation functions only accept types which would also +// be accepted by the FunctionalTest constructors. +// +// This interface matches the methods of the NullOutput, EnableOutput +// and ConfigureOutput structs below. +type ProductOutput interface { + ProductID() string + ServiceID() string +} + +// NullInput is used to indicate to the generic FunctionalTest +// 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 "" +} + +func (o NullOutput) ServiceID() string { + return "" +} + +// EnableOutput represents an enablement response from the Fastly +// API. Products will embed this structure into their own. +type EnableOutput struct { + Product *EnableOutputNested `mapstructure:"product"` + Service *EnableOutputNested `mapstructure:"service"` +} + +type EnableOutputNested struct { + Object *string `mapstructure:"object,omitempty"` + ID *string `mapstructure:"id,omitempty"` +} + +// ProductID returns the ProductID inside an EnableOutput structure. +// +// This method is required, even though the field in the structure is +// exported, because the ProductOutput interface specifies it. +func (o EnableOutput) ProductID() string { + if o.Product != nil && o.Product.ID != nil { + return *o.Product.ID + } + return "" +} + +// ServiceID returns the ServiceID inside an EnableOutput structure. +// +// This method is required, even though the field in the structure is +// exported, because the ProductOutput interface specifies it. +func (o EnableOutput) ServiceID() string { + if o.Service != nil && o.Service.ID != nil { + return *o.Service.ID + } + return "" +} + +func NewEnableOutput(productID, serviceID string) (result EnableOutput) { + result.Product = &EnableOutputNested{Object: fastly.ToPointer("product"), ID: &productID} + result.Service = &EnableOutputNested{Object: fastly.ToPointer("service"), ID: &serviceID} + return +} + +// ConfigureOutput represents a configuration response from the Fastly +// API. Products will embed this structure into their own. +type ConfigureOutput struct { + EnableOutput `mapstructure:",squash"` +} diff --git a/fastly/products/websockets/api.go b/fastly/products/websockets/api.go index 521b8221..9d410373 100644 --- a/fastly/products/websockets/api.go +++ b/fastly/products/websockets/api.go @@ -6,11 +6,19 @@ import ( "github.com/fastly/go-fastly/v9/internal/productcore" ) -const ProductID = "websockets" +const ( + ProductID = "websockets" + ProductName = "WebSockets" +) + +// EnableOutput holds the details returned by the API from 'Get' and +// 'Enable' operations; this alias exists to ensure that users of this +// package will have a stable name to reference. +type EnableOutput = products.EnableOutput // Get gets the status of the WebSockets product on the service. -func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Get[*products.EnableOutput](&productcore.GetInput{ +func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Get[EnableOutput](&productcore.GetInput{ Client: c, ProductID: ProductID, ServiceID: serviceID, @@ -18,8 +26,8 @@ func Get(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { } // Enable enables the WebSockets product on the service. -func Enable(c *fastly.Client, serviceID string) (*products.EnableOutput, error) { - return productcore.Put[*products.EnableOutput](&productcore.PutInput[*productcore.NullInput]{ +func Enable(c *fastly.Client, serviceID string) (EnableOutput, error) { + return productcore.Put[EnableOutput](&productcore.PutInput[products.NullInput]{ Client: c, ProductID: ProductID, ServiceID: serviceID, @@ -34,3 +42,9 @@ func Disable(c *fastly.Client, serviceID string) error { ServiceID: serviceID, }) } + +// NewEnableOutput is used to construct mock API output structures for +// use in tests. +func NewEnableOutput(serviceID string) EnableOutput { + return products.NewEnableOutput(ProductID, serviceID) +} diff --git a/fastly/products/websockets/api_test.go b/fastly/products/websockets/api_test.go index ee5f82f3..ad144e5c 100644 --- a/fastly/products/websockets/api_test.go +++ b/fastly/products/websockets/api_test.go @@ -19,19 +19,19 @@ var functionalTests = []*test_utils.FunctionalTest{ ServiceID: serviceID, IgnoreFailure: true, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[websockets.EnableOutput]{ Phase: "before enablement", OpFn: websockets.Get, ProductID: websockets.ProductID, ServiceID: serviceID, ExpectFailure: true, }), - productcore.NewEnableTest(&productcore.EnableTestInput[*products.EnableOutput, *productcore.NullInput]{ + productcore.NewEnableTest(&productcore.EnableTestInput[websockets.EnableOutput, products.NullInput]{ OpNoInputFn: websockets.Enable, ProductID: websockets.ProductID, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[websockets.EnableOutput]{ Phase: "after enablement", OpFn: websockets.Get, ProductID: websockets.ProductID, @@ -41,7 +41,7 @@ var functionalTests = []*test_utils.FunctionalTest{ OpFn: websockets.Disable, ServiceID: serviceID, }), - productcore.NewGetTest(&productcore.GetTestInput[*products.EnableOutput]{ + productcore.NewGetTest(&productcore.GetTestInput[websockets.EnableOutput]{ Phase: "after disablement", OpFn: websockets.Get, ProductID: websockets.ProductID, diff --git a/internal/productcore/api_get.go b/internal/productcore/api_get.go index 3c0258c1..edaa909a 100644 --- a/internal/productcore/api_get.go +++ b/internal/productcore/api_get.go @@ -1,6 +1,9 @@ package productcore -import "github.com/fastly/go-fastly/v9/fastly" +import ( + "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" +) // GetInput specifies the information needed for the Get() // function to perform the operation. @@ -17,7 +20,7 @@ type GetInput struct { // struct which matches the ProductOutput interface, and that type // is used to construct, populate, and return the output present in // the response body. -func Get[O ProductOutput](i *GetInput) (o O, err error) { +func Get[O products.ProductOutput](i *GetInput) (o O, err error) { if i.ServiceID == "" { err = fastly.ErrMissingServiceID return diff --git a/internal/productcore/api_patch.go b/internal/productcore/api_patch.go index b46c5d25..f128a8f4 100644 --- a/internal/productcore/api_patch.go +++ b/internal/productcore/api_patch.go @@ -1,6 +1,9 @@ package productcore -import "github.com/fastly/go-fastly/v9/fastly" +import ( + "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" +) // PatchInput specifies the information needed for the Patch() // function to perform the operation. @@ -25,7 +28,7 @@ type PatchInput[I any] struct { // struct which matches the ProductOutput interface, and that type // is used to construct, populate, and return the output present in // the response body. -func Patch[O ProductOutput, I any](i *PatchInput[I]) (o O, err error) { +func Patch[O products.ProductOutput, I any](i *PatchInput[I]) (o O, err error) { if i.ServiceID == "" { err = fastly.ErrMissingServiceID return diff --git a/internal/productcore/api_put.go b/internal/productcore/api_put.go index e3849ec2..f0094a99 100644 --- a/internal/productcore/api_put.go +++ b/internal/productcore/api_put.go @@ -1,6 +1,9 @@ package productcore -import "github.com/fastly/go-fastly/v9/fastly" +import ( + "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" +) // PutInput specifies the information needed for the Put() // function to perform the operation. @@ -25,7 +28,7 @@ type PutInput[I any] struct { // struct which matches the ProductOutput interface, and that type // is used to construct, populate, and return the output present in // the response body. -func Put[O ProductOutput, I any](i *PutInput[I]) (o O, err error) { +func Put[O products.ProductOutput, I any](i *PutInput[I]) (o O, err error) { if i.ServiceID == "" { err = fastly.ErrMissingServiceID return diff --git a/internal/productcore/functional_test_enable.go b/internal/productcore/functional_test_enable.go index f17572c2..dd17e8af 100644 --- a/internal/productcore/functional_test_enable.go +++ b/internal/productcore/functional_test_enable.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" "github.com/fastly/go-fastly/v9/internal/test_utils" ) @@ -14,9 +15,9 @@ import ( // Because Enable operations accept input and produce output, this // struct has two type parameters used to specify the types of the // input and output. The output type parameter is constrained to match -// the ProductOutput interface (in this package) so that the test case -// can validate the common portions of the output. -type EnableTestInput[O ProductOutput, I any] struct { +// the ProductOutput interface so that the test case can validate the +// common portions of the output. +type EnableTestInput[O products.ProductOutput, I any] struct { // Phase is used to distinguish between multiple Enable test // cases in a sequence of test cases; it is included in the // test case's Name and Operation fields @@ -59,7 +60,7 @@ type EnableTestInput[O ProductOutput, I any] struct { // This function requires the same output type parameter as the // EnableTestInput struct, and that type is used to construct, // populate, and validate the output present in the response body. -func NewEnableTest[O ProductOutput, I any](i *EnableTestInput[O, I]) *test_utils.FunctionalTest { +func NewEnableTest[O products.ProductOutput, I any](i *EnableTestInput[O, I]) *test_utils.FunctionalTest { r := test_utils.FunctionalTest{} if i.Phase != "" { @@ -71,7 +72,7 @@ func NewEnableTest[O ProductOutput, I any](i *EnableTestInput[O, I]) *test_utils } switch any(i.Input).(type) { - case *NullInput: + case products.NullInput: r.TestFn = func(t *testing.T, tc *test_utils.FunctionalTest, c *fastly.Client) error { result, err := i.OpNoInputFn(c, i.ServiceID) if err == nil { diff --git a/internal/productcore/functional_test_get.go b/internal/productcore/functional_test_get.go index 636f31cd..b9821d67 100644 --- a/internal/productcore/functional_test_get.go +++ b/internal/productcore/functional_test_get.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" "github.com/fastly/go-fastly/v9/internal/test_utils" "github.com/stretchr/testify/require" ) @@ -14,10 +15,9 @@ import ( // // Because Get operations produce output, this struct has a type // parameter used to specify the type of the output. The type -// parameter is constrained to match the ProductOutput interface (in -// this package) so that the test case can validate the common -// portions of the output. -type GetTestInput[O ProductOutput] struct { +// parameter is constrained to match the ProductOutput interface so +// that the test case can validate the common portions of the output. +type GetTestInput[O products.ProductOutput] struct { // Phase is used to distinguish between multiple Get test // cases in a sequence of test cases; it is included in the // test case's Name and Operation fields @@ -57,7 +57,7 @@ type GetTestInput[O ProductOutput] struct { // error returned when a product is not enabled on a service. If any // other error is returned by the API, the test case will report // failure. -func NewGetTest[O ProductOutput](i *GetTestInput[O]) *test_utils.FunctionalTest { +func NewGetTest[O products.ProductOutput](i *GetTestInput[O]) *test_utils.FunctionalTest { r := test_utils.FunctionalTest{} if i.Phase != "" { diff --git a/internal/productcore/functional_test_get_configuration.go b/internal/productcore/functional_test_get_configuration.go index f829c7b0..9eb7bb47 100644 --- a/internal/productcore/functional_test_get_configuration.go +++ b/internal/productcore/functional_test_get_configuration.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" "github.com/fastly/go-fastly/v9/internal/test_utils" ) @@ -14,10 +15,9 @@ import ( // // Because GetConfiguration operations produce output, this struct has // a type parameter used to specify the type of the output. The type -// parameter is constrained to match the ProductOutput interface (in -// this package) so that the test case can validate the common -// portions of the output. -type GetConfigurationTestInput[O ProductOutput] struct { +// parameter is constrained to match the ProductOutput interface so +// that the test case can validate the common portions of the output. +type GetConfigurationTestInput[O products.ProductOutput] struct { // Phase is used to distinguish between multiple // GetConfiguration test cases in a sequence of test cases; it // is included in the test case's Name and Operation fields @@ -47,7 +47,7 @@ type GetConfigurationTestInput[O ProductOutput] struct { // NewGetConfigurationTest constructs a FunctionalTest object as // specified by its input. -func NewGetConfigurationTest[O ProductOutput](i *GetConfigurationTestInput[O]) *test_utils.FunctionalTest { +func NewGetConfigurationTest[O products.ProductOutput](i *GetConfigurationTestInput[O]) *test_utils.FunctionalTest { r := test_utils.FunctionalTest{} if i.Phase != "" { diff --git a/internal/productcore/functional_test_update_configuration.go b/internal/productcore/functional_test_update_configuration.go index 1d226612..7de5ee0e 100644 --- a/internal/productcore/functional_test_update_configuration.go +++ b/internal/productcore/functional_test_update_configuration.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" "github.com/fastly/go-fastly/v9/internal/test_utils" ) @@ -15,10 +16,9 @@ import ( // Because UpdateConfiguration operations accept input and produce // output, this struct has two type parameters used to specify the // types of the input and output. The output type parameter is -// constrained to match the ProductOutput interface (in this package) -// so that the test case can validate the common portions of the -// output. -type UpdateConfigurationTestInput[O ProductOutput, I any] struct { +// constrained to match the ProductOutput interface so that the test +// case can validate the common portions of the output. +type UpdateConfigurationTestInput[O products.ProductOutput, I any] struct { // Phase is used to distinguish between multiple Enable test // cases in a sequence of test cases; it is included in the // test case's Name and Operation fields @@ -58,7 +58,7 @@ type UpdateConfigurationTestInput[O ProductOutput, I any] struct { // UpdateConfigurationTestInput struct, and that type is used to // construct, populate, and validate the output present in the // response body. -func NewUpdateConfigurationTest[O ProductOutput, I any](i *UpdateConfigurationTestInput[O, I]) *test_utils.FunctionalTest { +func NewUpdateConfigurationTest[O products.ProductOutput, I any](i *UpdateConfigurationTestInput[O, I]) *test_utils.FunctionalTest { r := test_utils.FunctionalTest{} if i.Phase != "" { diff --git a/internal/productcore/functional_test_utils.go b/internal/productcore/functional_test_utils.go index e758a344..47a36006 100644 --- a/internal/productcore/functional_test_utils.go +++ b/internal/productcore/functional_test_utils.go @@ -3,6 +3,7 @@ package productcore import ( "testing" + "github.com/fastly/go-fastly/v9/fastly/products" "github.com/fastly/go-fastly/v9/internal/test_utils" "github.com/stretchr/testify/require" ) @@ -14,10 +15,8 @@ import ( // and ServiceID on which the operation was invoked; this function // confirms that they were returned and that they have the expected // values. -func validateOutput(t *testing.T, tc *test_utils.FunctionalTest, o ProductOutput, productID, serviceID string) { +func validateOutput(t *testing.T, tc *test_utils.FunctionalTest, o products.ProductOutput, productID, serviceID string) { require.NotNilf(t, o, "test '%s'", tc.Name) - require.NotNilf(t, o.ProductID(), "test '%s'", tc.Name) - require.NotNilf(t, o.ServiceID(), "test '%s'", tc.Name) - require.Equalf(t, productID, *o.ProductID(), "test '%s'", tc.Name) - require.Equalf(t, serviceID, *o.ServiceID(), "test '%s'", tc.Name) + require.Equalf(t, productID, o.ProductID(), "test '%s'", tc.Name) + require.Equalf(t, serviceID, o.ServiceID(), "test '%s'", tc.Name) } diff --git a/internal/productcore/productcore_test.go b/internal/productcore/productcore_test.go index 272ce1d9..b6f729be 100644 --- a/internal/productcore/productcore_test.go +++ b/internal/productcore/productcore_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/fastly/go-fastly/v9/fastly" + "github.com/fastly/go-fastly/v9/fastly/products" "github.com/fastly/go-fastly/v9/internal/productcore" "github.com/stretchr/testify/require" ) @@ -21,7 +22,7 @@ func TestDeleteMissingServiceID(t *testing.T) { func TestGetMissingServiceID(t *testing.T) { t.Parallel() - _, err := productcore.Get[*productcore.NullOutput](&productcore.GetInput{ + _, err := productcore.Get[*products.NullOutput](&productcore.GetInput{ ServiceID: "", }) @@ -31,7 +32,7 @@ func TestGetMissingServiceID(t *testing.T) { func TestPatchMissingServiceID(t *testing.T) { t.Parallel() - _, err := productcore.Patch[*productcore.NullOutput](&productcore.PatchInput[*productcore.NullInput]{ + _, err := productcore.Patch[*products.NullOutput](&productcore.PatchInput[*products.NullInput]{ ServiceID: "", }) @@ -41,7 +42,7 @@ func TestPatchMissingServiceID(t *testing.T) { func TestPutMissingServiceID(t *testing.T) { t.Parallel() - _, err := productcore.Put[*productcore.NullOutput](&productcore.PutInput[*productcore.NullInput]{ + _, err := productcore.Put[*products.NullOutput](&productcore.PutInput[*products.NullInput]{ ServiceID: "", }) diff --git a/internal/productcore/types.go b/internal/productcore/types.go deleted file mode 100644 index 382b05ea..00000000 --- a/internal/productcore/types.go +++ /dev/null @@ -1,34 +0,0 @@ -package productcore - -// ProductOutput is an interface used to constrain the 'O' type -// parameter of the functions in this package. Use of this interface -// allows the FunctionalTest constructors to apply common validation -// steps to the output received from an API operation, eliminating the -// need to duplicate that validation in every FunctionalTest case, and -// ensures that the API operation functions only accept types which -// would also be accepted by the FunctionalTest constructors. -// -// This interface matches the methods of the EnableOutput and -// ConfigureOutput structs in the fastly/products package. -type ProductOutput interface { - ProductID() *string - ServiceID() *string -} - -// NullInput is used to indicate to the generic FunctionalTest -// 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 -}