Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Bug Fixes:

- fix(service-version): use FASTLY_SERVICE_ID and fastly.toml fallbacks when validating a service version.
- fix(service-version): support autoclone when staging a service version. ([#1850](https://github.com/fastly/cli/pull/1850))
- fix(logging): the `placement` flag for all loggging commands can now be reset back to `null` by setting it's value to `""` when it was previously set to another value ([#1855](https://github.com/fastly/cli/pull/1855))
- fix(profile): profiles can now be created and updated with service-limited tokens, which cannot access `/current_user` ([#1856](https://github.com/fastly/cli/pull/1856))
Expand Down
52 changes: 50 additions & 2 deletions pkg/commands/service/version/serviceversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

root "github.com/fastly/cli/pkg/commands/service"
sub "github.com/fastly/cli/pkg/commands/service/version"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/mock"
"github.com/fastly/cli/pkg/testutil"
)
Expand Down Expand Up @@ -564,15 +565,49 @@ func lockVersionError(_ context.Context, _ *fastly.LockVersionInput) (*fastly.Ve
func TestVersionValidate(t *testing.T) {
scenarios := []testutil.CLIScenario{
{
Name: "validate missing --service-id flag",
Name: "validate missing service ID",
Args: "--version 1",
WantError: "error parsing arguments: required flag --service-id not provided",
EnvVars: map[string]string{"FASTLY_SERVICE_ID": ""},
WantError: "error reading service: no service ID found",
},
{
Name: "validate missing --version flag",
Args: "--service-id 123",
WantError: "error parsing arguments: required flag --version not provided",
},
{
Name: "validate service ID from environment",
Args: "--version latest",
EnvVars: map[string]string{"FASTLY_SERVICE_ID": "env-service"},
API: &mock.API{
ListVersionsFn: testutil.ListVersions,
ValidateVersionFn: validateVersionForService("env-service", 4),
},
WantOutput: "Service env-service version 4 is valid",
},
{
Name: "validate service ID from manifest",
Args: "--version 1",
EnvVars: map[string]string{"FASTLY_SERVICE_ID": ""},
Setup: func(_ *testing.T, _ *testutil.CLIScenario, opts *global.Data) {
opts.Manifest.File.ServiceID = "manifest-service"
},
API: &mock.API{
GetVersionFn: testutil.GetVersion,
ValidateVersionFn: validateVersionForService("manifest-service", 1),
},
WantOutput: "Service manifest-service version 1 is valid",
},
{
Name: "validate explicit service ID overrides environment",
Args: "--service-id flag-service --version 1",
EnvVars: map[string]string{"FASTLY_SERVICE_ID": "env-service"},
API: &mock.API{
GetVersionFn: testutil.GetVersion,
ValidateVersionFn: validateVersionForService("flag-service", 1),
},
WantOutput: "Service flag-service version 1 is valid",
},
{
Name: "validate successful - valid version without message",
Args: "--service-id 123 --version 1",
Expand Down Expand Up @@ -647,6 +682,19 @@ func validateVersionValid(message string) func(context.Context, *fastly.Validate
}
}

func validateVersionForService(serviceID string, serviceVersion int) func(context.Context, *fastly.ValidateVersionInput) (bool, string, error) {
return func(_ context.Context, input *fastly.ValidateVersionInput) (bool, string, error) {
if input.ServiceID != serviceID || input.ServiceVersion != serviceVersion {
return false, "", fmt.Errorf(
"unexpected validate input: service ID %q, version %d",
input.ServiceID,
input.ServiceVersion,
)
}
return true, "", nil
}
}

func validateVersionInvalid(message string) func(context.Context, *fastly.ValidateVersionInput) (bool, string, error) {
return func(_ context.Context, _ *fastly.ValidateVersionInput) (bool, string, error) {
return false, message, nil
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/service/version/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func NewValidateCommand(parent argparser.Registerer, g *global.Data) *ValidateCo
Description: argparser.FlagServiceIDDesc,
Dst: &g.Manifest.Flag.ServiceID,
Short: 's',
Required: true,
})
c.RegisterFlag(argparser.StringFlagOpts{
Name: argparser.FlagVersionName,
Expand Down