Skip to content

Commit

Permalink
Fix stability of Cloud Slack test
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec committed Sep 25, 2023
1 parent f931233 commit 3f780e0
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions test/cloud-slack-dev-e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"testing"
"time"

"github.com/MakeNowJust/heredoc"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/proto"
Expand Down Expand Up @@ -346,6 +345,10 @@ func TestCloudSlackE2E(t *testing.T) {
}
err = tester.WaitForMessagePosted(tester.BotUserID(), channel.ID(), 3, assertionFn)

cmdHeader := func(command string) string {
return fmt.Sprintf("`%s` on `%s`", command, deployment.Name)
}

t.Run("Check basic commands", func(t *testing.T) {
t.Log("Testing ping with --cluster-name")
command := fmt.Sprintf("ping --cluster-name %s", deployment.Name)
Expand Down Expand Up @@ -383,7 +386,7 @@ func TestCloudSlackE2E(t *testing.T) {
t.Log("Testing getting all deployments")
command = "kubectl get deployments -A"
assertionFn := func(msg string) (bool, int, string) {
return strings.Contains(msg, heredoc.Doc(fmt.Sprintf("`%s` on `%s`", command, deployment.Name))) &&
return strings.Contains(msg, cmdHeader(command)) &&
strings.Contains(msg, "coredns") &&
strings.Contains(msg, "botkube"), 0, ""
}
Expand Down Expand Up @@ -454,12 +457,20 @@ func TestCloudSlackE2E(t *testing.T) {
t.Log("Verifying disabled notification on Cloud...")
deploy := gqlCli.MustGetDeployment(t, graphql.ID(deployment.ID))
require.True(t, *deploy.Platforms.CloudSlacks[0].Channels[0].NotificationsDisabled)

t.Log("Verifying disabled notifications on chat...")
command := "status notifications"
expectedBody := formatx.CodeBlock(fmt.Sprintf("Notifications from cluster '%s' are disabled here.", deployment.Name))
expectedMessage := fmt.Sprintf("%s\n%s", cmdHeader(command), expectedBody)
tester.PostMessageToBot(t, channel.ID(), "status notifications")
err = tester.WaitForLastMessageEqual(tester.BotUserID(), channel.ID(), expectedMessage)
require.NoError(t, err)
})

t.Run("Cloud -> Botkube Deployment sync", func(t *testing.T) {
t.Log("Removing source binding from Slack platform & add actions")
d := gqlCli.MustGetDeployment(t, graphql.ID(deployment.ID)) // Get final resource version
deployment = removeCloudSlackSourcesFromDeployment(t, gqlCli.Client, &d)
deployment = removeSourcesAndAddActions(t, gqlCli.Client, &d)

t.Log("Waiting for config reload message...")
expectedReloadMsg := fmt.Sprintf(":arrows_counterclockwise: Configuration reload requested for cluster '%s'. Hold on a sec...", deployment.Name)
Expand All @@ -473,12 +484,12 @@ func TestCloudSlackE2E(t *testing.T) {
tester.PostMessageToBot(t, channel.ID(), "list sources")

t.Log("Waiting for empty source list...")
expectedSourceListMsg := fmt.Sprintf("`list sources` on `%s`\n```\nSOURCE ENABLED\n```", deployment.Name)
expectedSourceListMsg := fmt.Sprintf("%s\n```\nSOURCE ENABLED\n```", cmdHeader("list sources"))
err = tester.WaitForLastMessageEqual(tester.BotUserID(), channel.ID(), expectedSourceListMsg)
require.NoError(t, err)
tester.PostMessageToBot(t, channel.ID(), "list actions")
t.Log("Waiting for actions list...")
expectedActionsListMsg := fmt.Sprintf("`list actions` on `%s`\n```\nACTION ENABLED DISPLAY NAME\naction_xxx22 true Action Name\n```", deployment.Name)
expectedActionsListMsg := fmt.Sprintf("%s\n```\nACTION ENABLED DISPLAY NAME\naction_xxx22 true Action Name\n```", cmdHeader("list actions"))
err = tester.WaitForLastMessageEqual(tester.BotUserID(), channel.ID(), expectedActionsListMsg)
require.NoError(t, err)
})
Expand Down Expand Up @@ -554,7 +565,7 @@ func newBrowserPage(t *testing.T, browser *rod.Browser, cfg E2ESlackConfig) *rod
return page
}

func removeCloudSlackSourcesFromDeployment(t *testing.T, gql *graphql.Client, existingDeployment *gqlModel.Deployment) *gqlModel.Deployment {
func removeSourcesAndAddActions(t *testing.T, gql *graphql.Client, existingDeployment *gqlModel.Deployment) *gqlModel.Deployment {
existingDeployment.HelmCommand = nil
existingDeployment.InstallUpgradeInstructions = nil
existingDeployment.APIKey = nil
Expand Down

0 comments on commit 3f780e0

Please sign in to comment.