forked from aws/copilot-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ecs): describe job and generate run task request from job workl…
…oad (aws#2246) This PR implement the function to generate a run task request from a deployed job, and the functions to support it. This PR is rebased from aws#2201 (which is not merged yet). The real changes to this PR are at - `ecs/run_task_request.go` (where the information needed to generated a `task run` command is grabbed from a Copilot job) - `ecs/run_task_request_test.go` - `aws/stepfunctions/*` (where the client to make API calls to stepfunctions is implemented) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
- Loading branch information
1 parent
c1f9857
commit 904dd44
Showing
11 changed files
with
707 additions
and
4 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
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
50 changes: 50 additions & 0 deletions
50
internal/pkg/aws/stepfunctions/mocks/mock_stepfunctions.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,41 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package stepfunctions provides a client to make API requests to Amazon Step Functions. | ||
package stepfunctions | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/sfn" | ||
) | ||
|
||
type api interface { | ||
DescribeStateMachine(input *sfn.DescribeStateMachineInput) (*sfn.DescribeStateMachineOutput, error) | ||
} | ||
|
||
// StepFunctions wraps an AWS StepFunctions client. | ||
type StepFunctions struct { | ||
client api | ||
} | ||
|
||
// New returns StepFunctions configured against the input session. | ||
func New(s *session.Session) *StepFunctions { | ||
return &StepFunctions{ | ||
client: sfn.New(s), | ||
} | ||
} | ||
|
||
// StateMachineDefinition returns the JSON-based state machine definition. | ||
func (s *StepFunctions) StateMachineDefinition(stateMachineARN string) (string, error) { | ||
out, err := s.client.DescribeStateMachine(&sfn.DescribeStateMachineInput{ | ||
StateMachineArn: aws.String(stateMachineARN), | ||
}) | ||
if err != nil { | ||
return "", fmt.Errorf("describe state machine: %w", err) | ||
} | ||
|
||
return aws.StringValue(out.Definition), nil | ||
} |
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,70 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package stepfunctions provides a client to make API requests to Amazon Step Functions. | ||
package stepfunctions | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/sfn" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/aws/copilot-cli/internal/pkg/aws/stepfunctions/mocks" | ||
"github.com/golang/mock/gomock" | ||
) | ||
|
||
func TestStepFunctions_StateMachineDefinition(t *testing.T) { | ||
testCases := map[string]struct { | ||
inStateMachineARN string | ||
|
||
mockStepFunctionsClient func(m *mocks.Mockapi) | ||
|
||
wantedError error | ||
wantedDefinition string | ||
}{ | ||
"fail to describe state machine": { | ||
inStateMachineARN: "ninth inning", | ||
mockStepFunctionsClient: func(m *mocks.Mockapi) { | ||
m.EXPECT().DescribeStateMachine(&sfn.DescribeStateMachineInput{ | ||
StateMachineArn: aws.String("ninth inning"), | ||
}).Return(nil, errors.New("some error")) | ||
}, | ||
wantedError: errors.New("describe state machine: some error"), | ||
}, | ||
"success": { | ||
inStateMachineARN: "ninth inning", | ||
mockStepFunctionsClient: func(m *mocks.Mockapi) { | ||
m.EXPECT().DescribeStateMachine(&sfn.DescribeStateMachineInput{ | ||
StateMachineArn: aws.String("ninth inning"), | ||
}).Return(&sfn.DescribeStateMachineOutput{ | ||
Definition: aws.String("{\n \"Version\": \"42\",\n \"Comment\": \"very important comment\"\n}"), | ||
}, nil) | ||
}, | ||
wantedDefinition: "{\n \"Version\": \"42\",\n \"Comment\": \"very important comment\"\n}", | ||
}, | ||
} | ||
|
||
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockStepFunctionsClient := mocks.NewMockapi(ctrl) | ||
tc.mockStepFunctionsClient(mockStepFunctionsClient) | ||
sfn := StepFunctions{ | ||
client: mockStepFunctionsClient, | ||
} | ||
|
||
out, err := sfn.StateMachineDefinition(tc.inStateMachineARN) | ||
if tc.wantedError != nil { | ||
require.EqualError(t, tc.wantedError, err.Error()) | ||
} else { | ||
require.Equal(t, tc.wantedDefinition, out) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.