Skip to content

Commit

Permalink
fix: svc package should apply override when static site (#4952)
Browse files Browse the repository at this point in the history
currently override doesn't get applied to svc package output when svc type is static site. This PR fixes this issue.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
  • Loading branch information
iamhopaul123 authored Jun 5, 2023
1 parent 5e9045c commit 65dca5f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 7 deletions.
6 changes: 2 additions & 4 deletions internal/pkg/cli/deploy/static_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ func (d *staticSiteDeployer) DeployWorkload(in *DeployWorkloadInput) (ActionReco
if err != nil {
return nil, err
}
if err := d.deploy(in.Options, svcStackConfigurationOutput{
conf: cloudformation.WrapWithTemplateOverrider(conf, d.overrider),
}); err != nil {
if err := d.deploy(in.Options, svcStackConfigurationOutput{conf: conf}); err != nil {
return nil, err
}
return noopActionRecommender{}, nil
Expand Down Expand Up @@ -176,7 +174,7 @@ func (d *staticSiteDeployer) stackConfiguration(in *StackRuntimeConfiguration) (
if err != nil {
return nil, fmt.Errorf("create stack configuration: %w", err)
}
return conf, nil
return cloudformation.WrapWithTemplateOverrider(conf, d.overrider), nil
}

func (d *staticSiteDeployer) validateSources() error {
Expand Down
76 changes: 73 additions & 3 deletions internal/pkg/cli/deploy/static_site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/aws/copilot-cli/internal/pkg/deploy/cloudformation/stack"
"github.com/aws/copilot-cli/internal/pkg/deploy/upload/customresource"
"github.com/aws/copilot-cli/internal/pkg/manifest"
"github.com/aws/copilot-cli/internal/pkg/manifest/manifestinfo"
"github.com/aws/copilot-cli/internal/pkg/template"
"github.com/golang/mock/gomock"
"github.com/spf13/afero"
Expand Down Expand Up @@ -137,8 +138,9 @@ func TestStaticSiteDeployer_UploadArtifacts(t *testing.T) {

func TestStaticSiteDeployer_stackConfiguration(t *testing.T) {
tests := map[string]struct {
deployer *staticSiteDeployer
wantErr string
deployer *staticSiteDeployer
wantErr string
wantTemplate string
}{
"error getting service discovery endpoint": {
deployer: &staticSiteDeployer{
Expand Down Expand Up @@ -401,16 +403,78 @@ func TestStaticSiteDeployer_stackConfiguration(t *testing.T) {
},
},
},
"success with overrider": {
deployer: &staticSiteDeployer{
svcDeployer: &svcDeployer{
workloadDeployer: &workloadDeployer{
app: &config.Application{
Name: "mockApp",
Domain: "example.com",
},
env: &config.Environment{
Name: "mockEnv",
},
envConfig: &manifest.Environment{},
endpointGetter: &endpointGetterDouble{
ServiceDiscoveryEndpointFn: ReturnsValues("", error(nil)),
},
envVersionGetter: &versionGetterDouble{
VersionFn: ReturnsValues("", error(nil)),
},
resources: &stack.AppRegionalResources{},
overrider: &mockOverrider{},
},
},
appVersionGetter: &versionGetterDouble{
VersionFn: ReturnsValues("v1.2.0", error(nil)),
},
staticSiteMft: &manifest.StaticSite{
StaticSiteConfig: manifest.StaticSiteConfig{
HTTP: manifest.StaticSiteHTTP{
Alias: "hi.mockApp.example.com",
},
},
},
newStack: func(*stack.StaticSiteConfig) (*stack.StaticSite, error) {
return stack.NewStaticSite(&stack.StaticSiteConfig{
EnvManifest: &manifest.Environment{
Workload: manifest.Workload{
Name: aws.String("mockEnv"),
},
},
App: &config.Application{
Name: "mockApp",
},
Manifest: &manifest.StaticSite{
Workload: manifest.Workload{
Name: aws.String("static"),
Type: aws.String(manifestinfo.StaticSiteType),
},
},
RuntimeConfig: stack.RuntimeConfig{
Region: "us-west-2",
},
ArtifactBucketName: "mockBucket",
})
},
},
wantTemplate: "mockOverride",
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
_, gotErr := tc.deployer.stackConfiguration(&StackRuntimeConfiguration{})
out, gotErr := tc.deployer.stackConfiguration(&StackRuntimeConfiguration{})
if tc.wantErr != "" {
require.EqualError(t, gotErr, tc.wantErr)
return
}
require.NoError(t, gotErr)
if tc.wantTemplate != "" {
s, err := out.Template()
require.NoError(t, err)
require.Equal(t, tc.wantTemplate, s)
}
})
}
}
Expand All @@ -420,3 +484,9 @@ func ReturnsValues[A, B any](a A, b B) func() (A, B) {
return a, b
}
}

type mockOverrider struct{}

func (o *mockOverrider) Override(body []byte) (out []byte, err error) {
return []byte("mockOverride"), nil
}

0 comments on commit 65dca5f

Please sign in to comment.