From 037462229d3ac8b60372e1340771a0d776389a3d Mon Sep 17 00:00:00 2001 From: Wanxian Yang <79273084+Lou1415926@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:34:47 -0700 Subject: [PATCH] chore: fix "task" e2e test's `AfterSuite` (#5783) 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. --- e2e/task/task_suite_test.go | 28 ++++++++++++---------------- e2e/task/task_test.go | 28 ++++++++++++++++++---------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/e2e/task/task_suite_test.go b/e2e/task/task_suite_test.go index 2edc25284e8..7863ef1f8e1 100644 --- a/e2e/task/task_suite_test.go +++ b/e2e/task/task_suite_test.go @@ -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. @@ -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") }) diff --git a/e2e/task/task_test.go b/e2e/task/task_test.go index 1bd0100c0e1..23f355a4a7f 100644 --- a/e2e/task/task_test.go +++ b/e2e/task/task_test.go @@ -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" @@ -57,8 +60,8 @@ 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", @@ -66,7 +69,9 @@ var _ = Describe("Task", func() { Env: envName, EnvFile: "./sesame.env", - }) + } + _, err = cli.TaskRun(&task) + tasks = append(tasks, task) }) It("should succeed", func() { @@ -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() { @@ -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", @@ -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() {