Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
13 changes: 13 additions & 0 deletions pkg/commands/compute/compute_mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ func createBackendOK(i *fastly.CreateBackendInput) (*fastly.Backend, error) {
}, nil
}

func createConfigStoreOK(i *fastly.CreateConfigStoreInput) (*fastly.ConfigStore, error) {
return &fastly.ConfigStore{
Name: i.Name,
}, nil
}

func createConfigStoreItemOK(i *fastly.CreateConfigStoreItemInput) (*fastly.ConfigStoreItem, error) {
return &fastly.ConfigStoreItem{
Key: i.Key,
Value: i.Value,
}, nil
}

func createDictionaryOK(i *fastly.CreateDictionaryInput) (*fastly.Dictionary, error) {
return &fastly.Dictionary{
ServiceID: i.ServiceID,
Expand Down
16 changes: 8 additions & 8 deletions pkg/commands/compute/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ func pkgUpload(spinner text.Spinner, client api.Interface, serviceID string, ver
type setupObjects struct {
domains *setup.Domains
backends *setup.Backends
dictionaries *setup.Dictionaries
configStores *setup.ConfigStores
loggers *setup.Loggers
kvStores *setup.KVStores
secretStores *setup.SecretStores
Expand Down Expand Up @@ -907,13 +907,13 @@ func constructSetupObjects(
Stdout: out,
}

so.dictionaries = &setup.Dictionaries{
so.configStores = &setup.ConfigStores{
APIClient: c.Globals.APIClient,
AcceptDefaults: c.Globals.Flags.AcceptDefaults,
NonInteractive: c.Globals.Flags.NonInteractive,
ServiceID: serviceID,
ServiceVersion: serviceVersion,
Setup: c.Manifest.File.Setup.Dictionaries,
Setup: c.Manifest.File.Setup.ConfigStores,
Stdin: in,
Stdout: out,
}
Expand Down Expand Up @@ -976,10 +976,10 @@ func processSetupConfig(
return fmt.Errorf("error configuring service backends: %w", err)
}

if so.dictionaries.Predefined() {
if err := so.dictionaries.Configure(); err != nil {
if so.configStores.Predefined() {
if err := so.configStores.Configure(); err != nil {
errLogService(c.Globals.ErrLog, err, serviceID, serviceVersion)
return fmt.Errorf("error configuring service dictionaries: %w", err)
return fmt.Errorf("error configuring service config stores: %w", err)
}
}

Expand Down Expand Up @@ -1038,7 +1038,7 @@ func processSetupCreation(
// We presume if we're dealing with newService they have been set.
if newService {
so.backends.Spinner = spinner
so.dictionaries.Spinner = spinner
so.configStores.Spinner = spinner
so.kvStores.Spinner = spinner
so.secretStores.Spinner = spinner

Expand All @@ -1053,7 +1053,7 @@ func processSetupCreation(
return err
}

if err := so.dictionaries.Create(); err != nil {
if err := so.configStores.Create(); err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Accept defaults": c.Globals.Flags.AcceptDefaults,
"Auto-yes": c.Globals.Flags.AutoYes,
Expand Down
159 changes: 81 additions & 78 deletions pkg/commands/compute/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ func TestDeploy(t *testing.T) {
},
},
{
name: "success with setup.dictionaries configuration and existing service",
name: "success with setup.config_stores configuration and existing service",
args: args("compute deploy --service-id 123 --token 123"),
api: mock.API{
ActivateVersionFn: activateVersionOk,
Expand Down Expand Up @@ -1188,12 +1188,12 @@ func TestDeploy(t *testing.T) {
manifest_version = 2
language = "rust"

[setup.dictionaries.dict_a]
[setup.config_stores.example]
description = "My first dictionary"
[setup.dictionaries.dict_a.items.foo]
[setup.config_stores.example.items.foo]
value = "my default value for foo"
description = "a good description about foo"
[setup.dictionaries.dict_a.items.bar]
[setup.config_stores.example.items.bar]
value = "my default value for bar"
description = "a good description about bar"
`,
Expand All @@ -1204,29 +1204,30 @@ func TestDeploy(t *testing.T) {
},
dontWantOutput: []string{
"Configuring dictionary 'dict_a'",
"Create a dictionary key called 'foo'",
"Create a dictionary key called 'bar'",
"Creating dictionary 'dict_a'",
"Creating dictionary item 'foo'",
"Creating dictionary item 'bar'",
"Create a config store key called 'foo'",
"Create a config store key called 'bar'",
"Creating config store 'example'",
"Creating config store item 'foo'",
"Creating config store item 'bar'",
},
},
{
name: "success with setup.dictionaries configuration and no existing service",
name: "success with setup.config_stores configuration and no existing service",
args: args("compute deploy --token 123"),
api: mock.API{
ActivateVersionFn: activateVersionOk,
CreateBackendFn: createBackendOK,
CreateDictionaryFn: createDictionaryOK,
CreateDictionaryItemFn: createDictionaryItemOK,
CreateDomainFn: createDomainOK,
CreateServiceFn: createServiceOK,
GetPackageFn: getPackageOk,
GetServiceFn: getServiceOK,
GetServiceDetailsFn: getServiceDetailsWasm,
ListDomainsFn: listDomainsOk,
ListVersionsFn: testutil.ListVersions,
UpdatePackageFn: updatePackageOk,
ActivateVersionFn: activateVersionOk,
CreateBackendFn: createBackendOK,
CreateConfigStoreFn: createConfigStoreOK,
CreateConfigStoreItemFn: createConfigStoreItemOK,
CreateResourceFn: createResourceOK,
CreateDomainFn: createDomainOK,
CreateServiceFn: createServiceOK,
GetPackageFn: getPackageOk,
GetServiceFn: getServiceOK,
GetServiceDetailsFn: getServiceDetailsWasm,
ListDomainsFn: listDomainsOk,
ListVersionsFn: testutil.ListVersions,
UpdatePackageFn: updatePackageOk,
},
httpClientRes: []*http.Response{
{
Expand All @@ -1243,49 +1244,50 @@ func TestDeploy(t *testing.T) {
manifest_version = 2
language = "rust"

[setup.dictionaries.dict_a]
description = "My first dictionary"
[setup.dictionaries.dict_a.items.foo]
[setup.config_stores.example]
description = "My first store"
[setup.config_stores.example.items.foo]
value = "my default value for foo"
description = "a good description about foo"
[setup.dictionaries.dict_a.items.bar]
[setup.config_stores.example.items.bar]
value = "my default value for bar"
description = "a good description about bar"
`,
stdin: []string{
"Y", // when prompted to create a new service
},
wantOutput: []string{
"Configuring dictionary 'dict_a'",
"My first dictionary",
"Create a dictionary key called 'foo'",
"Configuring config store 'example'",
"My first store",
"Create a config store key called 'foo'",
"my default value for foo",
"Create a dictionary key called 'bar'",
"Create a config store key called 'bar'",
"my default value for bar",
"Creating dictionary 'dict_a'",
"Creating dictionary item 'foo'",
"Creating dictionary item 'bar'",
"Creating config store 'example'",
"Creating config store item 'foo'",
"Creating config store item 'bar'",
"Uploading package",
"Activating service",
"SUCCESS: Deployed package (service 12345, version 1)",
},
},
{
name: "success with setup.dictionaries configuration and no existing service and --non-interactive",
name: "success with setup.config_stores configuration and no existing service and --non-interactive",
args: args("compute deploy --non-interactive --token 123"),
api: mock.API{
ActivateVersionFn: activateVersionOk,
CreateBackendFn: createBackendOK,
CreateDictionaryFn: createDictionaryOK,
CreateDictionaryItemFn: createDictionaryItemOK,
CreateDomainFn: createDomainOK,
CreateServiceFn: createServiceOK,
GetPackageFn: getPackageOk,
GetServiceFn: getServiceOK,
GetServiceDetailsFn: getServiceDetailsWasm,
ListDomainsFn: listDomainsOk,
ListVersionsFn: testutil.ListVersions,
UpdatePackageFn: updatePackageOk,
ActivateVersionFn: activateVersionOk,
CreateBackendFn: createBackendOK,
CreateConfigStoreFn: createConfigStoreOK,
CreateConfigStoreItemFn: createConfigStoreItemOK,
CreateResourceFn: createResourceOK,
CreateDomainFn: createDomainOK,
CreateServiceFn: createServiceOK,
GetPackageFn: getPackageOk,
GetServiceFn: getServiceOK,
GetServiceDetailsFn: getServiceDetailsWasm,
ListDomainsFn: listDomainsOk,
ListVersionsFn: testutil.ListVersions,
UpdatePackageFn: updatePackageOk,
},
httpClientRes: []*http.Response{
{
Expand All @@ -1302,43 +1304,44 @@ func TestDeploy(t *testing.T) {
manifest_version = 2
language = "rust"

[setup.dictionaries.dict_a]
description = "My first dictionary"
[setup.dictionaries.dict_a.items.foo]
[setup.config_stores.example]
description = "My first store"
[setup.config_stores.example.items.foo]
value = "my default value for foo"
description = "a good description about foo"
[setup.dictionaries.dict_a.items.bar]
[setup.config_stores.example.items.bar]
value = "my default value for bar"
description = "a good description about bar"
`,
stdin: []string{
"Y", // when prompted to create a new service
},
wantOutput: []string{
"Creating dictionary 'dict_a'",
"Creating dictionary item 'foo'",
"Creating dictionary item 'bar'",
"Creating config store 'example'",
"Creating config store item 'foo'",
"Creating config store item 'bar'",
"Uploading package",
"Activating service",
"SUCCESS: Deployed package (service 12345, version 1)",
},
},
{
name: "success with setup.dictionaries configuration and no existing service and no predefined values",
name: "success with setup.config_stores configuration and no existing service and no predefined values",
args: args("compute deploy --token 123"),
api: mock.API{
ActivateVersionFn: activateVersionOk,
CreateBackendFn: createBackendOK,
CreateDictionaryFn: createDictionaryOK,
CreateDictionaryItemFn: createDictionaryItemOK,
CreateDomainFn: createDomainOK,
CreateServiceFn: createServiceOK,
GetPackageFn: getPackageOk,
GetServiceFn: getServiceOK,
GetServiceDetailsFn: getServiceDetailsWasm,
ListDomainsFn: listDomainsOk,
ListVersionsFn: testutil.ListVersions,
UpdatePackageFn: updatePackageOk,
ActivateVersionFn: activateVersionOk,
CreateBackendFn: createBackendOK,
CreateConfigStoreFn: createConfigStoreOK,
CreateConfigStoreItemFn: createConfigStoreItemOK,
CreateResourceFn: createResourceOK,
CreateDomainFn: createDomainOK,
CreateServiceFn: createServiceOK,
GetPackageFn: getPackageOk,
GetServiceFn: getServiceOK,
GetServiceDetailsFn: getServiceDetailsWasm,
ListDomainsFn: listDomainsOk,
ListVersionsFn: testutil.ListVersions,
UpdatePackageFn: updatePackageOk,
},
httpClientRes: []*http.Response{
{
Expand All @@ -1355,30 +1358,30 @@ func TestDeploy(t *testing.T) {
manifest_version = 2
language = "rust"

[setup.dictionaries.dict_a]
[setup.dictionaries.dict_a.items.foo]
[setup.dictionaries.dict_a.items.bar]
[setup.config_stores.example]
[setup.config_stores.example.items.foo]
[setup.config_stores.example.items.bar]
`,
stdin: []string{
"Y", // when prompted to create a new service
},
wantOutput: []string{
"Configuring dictionary 'dict_a'",
"Create a dictionary key called 'foo'",
"Create a dictionary key called 'bar'",
"Creating dictionary 'dict_a'",
"Creating dictionary item 'foo'",
"Creating dictionary item 'bar'",
"Configuring config store 'example'",
"Create a config store key called 'foo'",
"Create a config store key called 'bar'",
"Creating config store 'example'",
"Creating config store item 'foo'",
"Creating config store item 'bar'",
"Uploading package",
"Activating service",
"SUCCESS: Deployed package (service 12345, version 1)",
},
// The following are predefined values for the `description` and `value`
// fields from the prior setup.dictionaries tests that we expect to not
// be present in the stdout/stderr as the [setup/dictionaries]
// fields from the prior setup.config_stores tests that we expect to not
// be present in the stdout/stderr as the [setup.config_stores]
// configuration does not define them.
dontWantOutput: []string{
"My first dictionary",
"My first store",
"my default value for foo",
"my default value for bar",
},
Expand Down
Loading