Skip to content

Commit

Permalink
wip - we probably don't need describetask anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
therealvio committed Nov 27, 2024
1 parent 32b3cde commit 4154d59
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 84 deletions.
17 changes: 0 additions & 17 deletions src/internal/aws/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,6 @@ func TaskIdFromArn(taskArn string) string {
return parts[len(parts)-1]
}

// Describes a single task from a cluster using the native `ecs:DescribeTasks` API.
// The taskArn is the task of interest to be described
func DescribeTask(ctx context.Context, ecsClientAPI EcsClientAPI, taskArn string) (types.Task, error) {
cluster := ClusterFromTaskArn(taskArn)
response, err := ecsClientAPI.DescribeTasks(ctx, &ecs.DescribeTasksInput{
Tasks: []string{taskArn},
Cluster: &cluster,
})

if err != nil {
return types.Task{}, err
}

// Given the input of `DescribeTasks` we should only be getting one Task back
return response.Tasks[0], nil
}

// Acquires LogStream details for given ECS Task
func FindLogStreamFromTask(ctx context.Context, ecsClientApi EcsClientAPI, task types.Task) (LogDetails, error) {
response, err := ecsClientApi.DescribeTaskDefinition(ctx, &ecs.DescribeTaskDefinitionInput{
Expand Down
67 changes: 0 additions & 67 deletions src/internal/aws/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,73 +173,6 @@ func TestTaskIdFromArn(t *testing.T) {
}
}

func TestDescribeTask(t *testing.T) {
taskArn1 := "arn:aws:ecs:us-west-2:123456789012:task/test-cluster/07cc583696bd44e0be450bff7314ddaf"
taskArn2 := "arn:aws:ecs:us-west-2:123456789012:task/jabroni-cluster/a3d695562e90bdd0723cce136f7c59b5"

containers := []types.Container{
{
ExitCode: aws.Int32(0),
},
}

task1 := types.Task{
TaskArn: aws.String(taskArn1),
Containers: containers,
}
task2 := types.Task{
TaskArn: aws.String(taskArn2),
Containers: containers,
}

tests := []struct {
name string
input string
client EcsClientAPI
expected types.Task
}{
{
// This is a regression test to ensure that the signature of the DescribeTask function doesn't change
name: "given a task ARN, it should return the associated task's details",
input: taskArn1,
client: mockECSClient{
mockDescribeTasks: func(ctx context.Context, params *ecs.DescribeTasksInput, optFns ...func(*ecs.Options)) (*ecs.DescribeTasksOutput, error) {
return &ecs.DescribeTasksOutput{
Tasks: []types.Task{task1},
}, nil
},
},
expected: task1,
},
{
// Again, we're testing to ensure that we the signature of the DescribeTask function doesn't change
name: "given a task ARN, if by some miracle two tasks are returned, only the first should be returned",
input: taskArn1,
client: mockECSClient{
mockDescribeTasks: func(ctx context.Context, params *ecs.DescribeTasksInput, optFns ...func(*ecs.Options)) (*ecs.DescribeTasksOutput, error) {
return &ecs.DescribeTasksOutput{
Tasks: []types.Task{task1, task2},
}, nil
},
},
expected: task1,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
result, err := DescribeTask(context.TODO(), tc.client, tc.input)

// Since we're mocking the result, there's a whole lot of noise in the output. So we're just going to log the
// taskArn string of the container, not the pointer.
t.Logf("result: %v", *result.TaskArn)
t.Logf("expected: %v", *tc.expected.TaskArn)
assert.NoError(t, err)
assert.Equal(t, tc.expected, result)
})
}
}

func TestFindLogStreamFromTask(t *testing.T) {
task := types.Task{
TaskArn: aws.String("arn:aws:ecs:us-west-2:123456789012:task/test-cluster/07cc583696bd44e0be450bff7314ddaf"),
Expand Down

0 comments on commit 4154d59

Please sign in to comment.