-
Notifications
You must be signed in to change notification settings - Fork 7
fix(snapshot ecs): handle clusters with zero services #966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+107
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,58 @@ | ||
| package aws | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| ecsTypes "github.com/aws/aws-sdk-go-v2/service/ecs/types" | ||
| "github.com/kosli-dev/cli/internal/filters" | ||
| "github.com/kosli-dev/cli/internal/logger" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestGetFilteredECSServicesInCluster_EmptyCluster reproduces the regression | ||
| // where a cluster with no services caused DescribeServices to be called with an | ||
| // empty Services list, which the real AWS API rejects with | ||
| // "InvalidParameterException: Services cannot be empty". | ||
| // | ||
| // An empty cluster should simply contribute zero services without error. | ||
| func TestGetFilteredECSServicesInCluster_EmptyCluster(t *testing.T) { | ||
| client := &FakeECSClient{ | ||
| ServiceArns: []string{}, // cluster has no services | ||
| Services: []ecsTypes.Service{}, | ||
| } | ||
|
|
||
| allServices, err := getFilteredECSServicesInCluster( | ||
| client, | ||
| "empty-cluster", | ||
| &[]ecsTypes.Service{}, | ||
| &filters.ResourceFilterOptions{}, | ||
| nil, | ||
| logger.NewStandardLogger(), | ||
| ) | ||
|
|
||
| require.NoError(t, err) | ||
| require.Empty(t, *allServices) | ||
| } | ||
|
|
||
| // TestGetFilteredECSServicesInCluster_WithServices verifies the happy path is | ||
| // unchanged by the empty-cluster guard: a cluster with services returns them. | ||
| func TestGetFilteredECSServicesInCluster_WithServices(t *testing.T) { | ||
| svcName := "my-service" | ||
| client := &FakeECSClient{ | ||
| ServiceArns: []string{"arn:aws:ecs:eu-central-1:123:service/cluster/my-service"}, | ||
| Services: []ecsTypes.Service{{ServiceName: &svcName}}, | ||
| } | ||
|
|
||
| allServices, err := getFilteredECSServicesInCluster( | ||
| client, | ||
| "cluster", | ||
| &[]ecsTypes.Service{}, | ||
| &filters.ResourceFilterOptions{}, | ||
| nil, | ||
| logger.NewStandardLogger(), | ||
| ) | ||
|
|
||
| require.NoError(t, err) | ||
| require.Len(t, *allServices, 1) | ||
| require.Equal(t, svcName, *(*allServices)[0].ServiceName) | ||
| } |
This file contains hidden or 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,32 @@ | ||
| package aws | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/service/ecs" | ||
| ecsTypes "github.com/aws/aws-sdk-go-v2/service/ecs/types" | ||
| ) | ||
|
|
||
| // FakeECSClient is an in-memory implementation of ECSServicesAPI for testing. | ||
| // It returns the configured services for a cluster and reproduces the real AWS | ||
| // contract where DescribeServices rejects an empty Services list. | ||
| type FakeECSClient struct { | ||
| // ServiceArns is the list of service ARNs returned by ListServices. | ||
| ServiceArns []string | ||
| // Services is the list of services returned by DescribeServices. | ||
| Services []ecsTypes.Service | ||
| } | ||
|
|
||
| func (f *FakeECSClient) ListServices(_ context.Context, _ *ecs.ListServicesInput, _ ...func(*ecs.Options)) (*ecs.ListServicesOutput, error) { | ||
| return &ecs.ListServicesOutput{ServiceArns: f.ServiceArns}, nil | ||
| } | ||
|
|
||
| func (f *FakeECSClient) DescribeServices(_ context.Context, params *ecs.DescribeServicesInput, _ ...func(*ecs.Options)) (*ecs.DescribeServicesOutput, error) { | ||
| // Mirror the real AWS ECS API, which rejects an empty Services list with | ||
| // InvalidParameterException: Services cannot be empty. | ||
| if len(params.Services) == 0 { | ||
| return nil, fmt.Errorf("InvalidParameterException: Services cannot be empty") | ||
| } | ||
| return &ecs.DescribeServicesOutput{Services: f.Services}, nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.