-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(product_enablement): add products command (#1036)
* build: bump go version to 1.21 * doc(vcl/condition): fix typo * feat(product_enablement): add products command * test(product_enablement): add tests for products command * feat(product_enablement): support json output * Update pkg/commands/products/root.go Co-authored-by: Adam Williams <awilliams@fastly.com> * fix(product_enablement): reference correct variables * fix(product_enablement): check for ProductUndefined * refactor(product_enablement): define new type for inline struct --------- Co-authored-by: Adam Williams <awilliams@fastly.com>
- Loading branch information
1 parent
beed704
commit 8ef3ca7
Showing
11 changed files
with
379 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/fastly/cli | ||
|
||
go 1.20 | ||
go 1.21 | ||
|
||
require ( | ||
github.com/Masterminds/semver/v3 v3.2.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ kv-store-entry | |
log-tail | ||
logging | ||
pops | ||
products | ||
profile | ||
purge | ||
rate-limit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package products contains commands to inspect and manipulate Fastly products. | ||
package products |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package products_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/fastly/go-fastly/v8/fastly" | ||
|
||
"github.com/fastly/cli/pkg/app" | ||
"github.com/fastly/cli/pkg/mock" | ||
"github.com/fastly/cli/pkg/testutil" | ||
) | ||
|
||
func TestProductEnablement(t *testing.T) { | ||
args := testutil.Args | ||
scenarios := []testutil.TestScenario{ | ||
{ | ||
Name: "validate missing Service ID", | ||
Args: args("products"), | ||
WantError: "failed to identify Service ID: error reading service: no service ID found", | ||
}, | ||
{ | ||
Name: "validate invalid enable/disable flag combo", | ||
Args: args("products --enable fanout --disable fanout"), | ||
WantError: "invalid flag combination: --enable and --disable", | ||
}, | ||
{ | ||
Name: "validate API error for product status", | ||
API: mock.API{ | ||
GetProductFn: func(i *fastly.ProductEnablementInput) (*fastly.ProductEnablement, error) { | ||
return nil, testutil.Err | ||
}, | ||
}, | ||
Args: args("products --service-id 123"), | ||
WantOutput: `PRODUCT ENABLED | ||
Brotli Compression false | ||
Domain Inspector false | ||
Fanout false | ||
Image Optimizer false | ||
Origin Inspector false | ||
Web Sockets false | ||
`, | ||
}, | ||
{ | ||
Name: "validate API success for product status", | ||
API: mock.API{ | ||
GetProductFn: func(i *fastly.ProductEnablementInput) (*fastly.ProductEnablement, error) { | ||
return nil, nil | ||
}, | ||
}, | ||
Args: args("products --service-id 123"), | ||
WantOutput: `PRODUCT ENABLED | ||
Brotli Compression true | ||
Domain Inspector true | ||
Fanout true | ||
Image Optimizer true | ||
Origin Inspector true | ||
Web Sockets true | ||
`, | ||
}, | ||
{ | ||
Name: "validate flag parsing error for enabling product", | ||
Args: args("products --service-id 123 --enable foo"), | ||
WantError: "error parsing arguments: enum value must be one of brotli_compression,domain_inspector,fanout,image_optimizer,origin_inspector,websockets, got 'foo'", | ||
}, | ||
{ | ||
Name: "validate flag parsing error for disabling product", | ||
Args: args("products --service-id 123 --disable foo"), | ||
WantError: "error parsing arguments: enum value must be one of brotli_compression,domain_inspector,fanout,image_optimizer,origin_inspector,websockets, got 'foo'", | ||
}, | ||
{ | ||
Name: "validate success for enabling product", | ||
API: mock.API{ | ||
EnableProductFn: func(i *fastly.ProductEnablementInput) (*fastly.ProductEnablement, error) { | ||
return nil, nil | ||
}, | ||
}, | ||
Args: args("products --service-id 123 --enable brotli_compression"), | ||
WantOutput: "SUCCESS: Successfully enabled product 'brotli_compression'", | ||
}, | ||
{ | ||
Name: "validate success for disabling product", | ||
API: mock.API{ | ||
DisableProductFn: func(i *fastly.ProductEnablementInput) error { | ||
return nil | ||
}, | ||
}, | ||
Args: args("products --service-id 123 --disable brotli_compression"), | ||
WantOutput: "SUCCESS: Successfully disabled product 'brotli_compression'", | ||
}, | ||
{ | ||
Name: "validate invalid json/verbose flag combo", | ||
Args: args("products --service-id 123 --json --verbose"), | ||
WantError: "invalid flag combination, --verbose and --json", | ||
}, | ||
{ | ||
Name: "validate API error for product status with --json output", | ||
API: mock.API{ | ||
GetProductFn: func(i *fastly.ProductEnablementInput) (*fastly.ProductEnablement, error) { | ||
return nil, testutil.Err | ||
}, | ||
}, | ||
Args: args("products --service-id 123 --json"), | ||
WantOutput: `{ | ||
"brotli_compression": false, | ||
"domain_inspector": false, | ||
"fanout": false, | ||
"image_optimizer": false, | ||
"origin_inspector": false, | ||
"websockets": false | ||
}`, | ||
}, | ||
{ | ||
Name: "validate API success for product status with --json output", | ||
API: mock.API{ | ||
GetProductFn: func(i *fastly.ProductEnablementInput) (*fastly.ProductEnablement, error) { | ||
return nil, nil | ||
}, | ||
}, | ||
Args: args("products --service-id 123 --json"), | ||
WantOutput: `{ | ||
"brotli_compression": true, | ||
"domain_inspector": true, | ||
"fanout": true, | ||
"image_optimizer": true, | ||
"origin_inspector": true, | ||
"websockets": true | ||
}`, | ||
}, | ||
} | ||
|
||
for testcaseIdx := range scenarios { | ||
testcase := &scenarios[testcaseIdx] | ||
t.Run(testcase.Name, func(t *testing.T) { | ||
var stdout bytes.Buffer | ||
opts := testutil.NewRunOpts(testcase.Args, &stdout) | ||
opts.APIClient = mock.APIClient(testcase.API) | ||
err := app.Run(opts) | ||
testutil.AssertErrorContains(t, err, testcase.WantError) | ||
testutil.AssertStringContains(t, stdout.String(), testcase.WantOutput) | ||
}) | ||
} | ||
} |
Oops, something went wrong.