Skip to content

Commit

Permalink
Fix cleanup order
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec committed Jun 24, 2024
1 parent 25b30f2 commit f227f6a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion test/cloud-slack-dev-e2e/botkube_page_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (p *BotkubeCloudPage) openKubectlUpdateForm() {
p.page.Screenshot("after-selecting-kubectl-cfg-form")
}

func (p *BotkubeCloudPage) CleanupOnFail(t *testing.T, gqlCli *cloud_graphql.Client) {
func (p *BotkubeCloudPage) Cleanup(t *testing.T, gqlCli *cloud_graphql.Client) {
t.Log("Cleaning up Botkube instance on test failure...")

if p.ConnectedDeploy == nil {
Expand Down
19 changes: 8 additions & 11 deletions test/cloud-slack-dev-e2e/cloud_slack_dev_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,19 @@ func TestCloudSlackE2E(t *testing.T) {
botkubeCloudPage.HideCookieBanner(t)

botkubeCloudPage.CreateNewInstance(t, channel.Name())
t.Cleanup(func() {
gqlCli := createGQLCli(t, cfg, botkubeCloudPage)
botkubeCloudPage.CleanupOnFail(t, gqlCli)
})

botkubeCloudPage.InstallAgentInCluster(t, cfg.BotkubeCliBinaryPath)
botkubeCloudPage.OpenSlackAppIntegrationPage(t)

slackPage.ConnectWorkspace(t, browser)
t.Cleanup(func() {
gqlCli := createGQLCli(t, cfg, botkubeCloudPage)
slackPage.CleanupOnFail(t, gqlCli)
slackPage.Cleanup(t, gqlCli)
})

t.Cleanup(func() {
gqlCli := createGQLCli(t, cfg, botkubeCloudPage)
botkubeCloudPage.Cleanup(t, gqlCli)
})

botkubeCloudPage.ReAddSlackPlatformIfShould(t, isHeadless)
Expand All @@ -178,15 +179,11 @@ func TestCloudSlackE2E(t *testing.T) {

connectedDeploy := botkubeCloudPage.ConnectedDeploy
require.NotNil(t, connectedDeploy, "Previous subtest needs to pass to get connected deployment information")
t.Cleanup(func() {
deleteDeployment(t, gqlCli, connectedDeploy.ID, "first (connected)")
})
// cleanup is done in the upper test function

slackWorkspace := findConnectedSlackWorkspace(t, cfg, gqlCli)
t.Cleanup(func() {
disconnectConnectedSlackWorkspace(t, cfg, gqlCli, slackWorkspace)
})
require.NotNil(t, slackWorkspace)
// cleanup is done in the upper test function

t.Log("Creating a second deployment to test not connected flow...")
notConnectedDeploy := gqlCli.MustCreateBasicDeploymentWithCloudSlack(t, fmt.Sprintf("%s-2", channel.Name()), slackWorkspace.TeamID, channel.Name())
Expand Down
2 changes: 1 addition & 1 deletion test/cloud-slack-dev-e2e/page_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func closePage(t *testing.T, name string, page *rod.Page) {
t.Helper()
err := page.Close()
if err != nil {
if errors.Is(err, context.Canceled) {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return
}

Expand Down
7 changes: 1 addition & 6 deletions test/cloud-slack-dev-e2e/slack_page_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,12 @@ func (p *SlackPage) ConnectWorkspace(t *testing.T, browser *rod.Browser) {
assert.NoError(t, err)
}

func (p *SlackPage) CleanupOnFail(t *testing.T, gqlCli *cloud_graphql.Client) {
func (p *SlackPage) Cleanup(t *testing.T, gqlCli *cloud_graphql.Client) {
t.Log("Cleaning up Slack workspace on test failure...")
if !p.cfg.Slack.DisconnectWorkspaceAfterTests {
return
}

if !t.Failed() {
t.Log("Skipping Slack workspace cleanup as the subtest passed...")
return
}

slackWorkspace := findConnectedSlackWorkspace(t, p.cfg, gqlCli)
disconnectConnectedSlackWorkspace(t, p.cfg, gqlCli, slackWorkspace)
}

0 comments on commit f227f6a

Please sign in to comment.