Skip to content

Commit

Permalink
chore: fix "task" e2e test's AfterSuite (aws#5783)
Browse files Browse the repository at this point in the history
Our "task" e2e test has being failing because we aren't able to empty the bucket. It is because we keep deploying tasks under the same group name; the latter-deployed tasks are in default cluster, which effectively removes the env manager role's permission to manage the bucket.

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
Lou1415926 committed Apr 18, 2024
1 parent 4fe1ad9 commit 0374622
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
28 changes: 12 additions & 16 deletions e2e/task/task_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (

var cli *client.CLI
var aws *client.AWS
var appName, envName, groupName, taskStackName, repoName string
var appName, envName string
var tasks []client.TaskRunInput

/**
The task suite runs through several tests focusing on running one-off tasks with different configurations.
Expand All @@ -33,23 +34,18 @@ var _ = BeforeSuite(func() {

appName = fmt.Sprintf("e2e-task-%d", time.Now().Unix())
envName = "test"
groupName = fmt.Sprintf("e2e-task-%d", time.Now().Unix())
// We name task stack in format of "task-${groupName}".
// See https://github.com/aws/copilot-cli/blob/e9e3114561e740c367fb83b5e075750f232ad639/internal/pkg/deploy/cloudformation/stack/name.go#L26.
taskStackName = fmt.Sprintf("task-%s", groupName)
// We name ECR repo name in format of "copilot-${groupName}".
// See https://github.com/aws/copilot-cli/blob/e9e3114561e740c367fb83b5e075750f232ad639/templates/task/cf.yml#L75.
repoName = fmt.Sprintf("copilot-%s", groupName)
})

var _ = AfterSuite(func() {
_, err := cli.TaskDelete(&client.TaskDeleteInput{
App: appName,
Env: envName,
Name: groupName,
Default: false,
})
Expect(err).NotTo(HaveOccurred(), "delete task")
_, err = cli.AppDelete()
for _, task := range tasks {
_, err := cli.TaskDelete(&client.TaskDeleteInput{
App: task.AppName,
Env: task.Env,
Name: task.GroupName,
Default: task.Default,
})
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("delete task %s", task.GroupName))
}
_, err := cli.AppDelete()
Expect(err).NotTo(HaveOccurred(), "delete Copilot application")
})
28 changes: 18 additions & 10 deletions e2e/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package task

import (
"fmt"
"time"

"github.com/aws/copilot-cli/e2e/internal/client"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -57,16 +60,18 @@ var _ = Describe("Task", func() {
Context("when running in an environment", Ordered, func() {
var err error
BeforeAll(func() {
_, err = cli.TaskRun(&client.TaskRunInput{
GroupName: groupName,
task := client.TaskRunInput{
GroupName: fmt.Sprintf("e2e-task-%d", time.Now().Unix()),

Dockerfile: "./backend/Dockerfile",

AppName: appName,
Env: envName,

EnvFile: "./sesame.env",
})
}
_, err = cli.TaskRun(&task)
tasks = append(tasks, task)
})

It("should succeed", func() {
Expand All @@ -78,14 +83,16 @@ var _ = Describe("Task", func() {
var err error
var taskLogs string
BeforeAll(func() {
taskLogs, err = cli.TaskRun(&client.TaskRunInput{
GroupName: groupName,
task := client.TaskRunInput{
GroupName: fmt.Sprintf("e2e-task-%d", time.Now().Unix()),

Dockerfile: "./backend/Dockerfile",

Default: true,
Follow: true,
})
}
taskLogs, err = cli.TaskRun(&task)
tasks = append(tasks, task)
})

It("should succeed", func() {
Expand All @@ -111,8 +118,8 @@ var _ = Describe("Task", func() {
var err error
var taskLogs string
BeforeAll(func() {
taskLogs, err = cli.TaskRun(&client.TaskRunInput{
GroupName: groupName,
task := client.TaskRunInput{
GroupName: fmt.Sprintf("e2e-task-%d", time.Now().Unix()),

Dockerfile: "./backend/Dockerfile",

Expand All @@ -121,8 +128,9 @@ var _ = Describe("Task", func() {

Default: true,
Follow: true,
})

}
taskLogs, err = cli.TaskRun(&task)
tasks = append(tasks, task)
})

It("should succeed", func() {
Expand Down

0 comments on commit 0374622

Please sign in to comment.