Skip to content

Commit

Permalink
Add alternative option with OnChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Feb 7, 2024
1 parent 39dbf4a commit df16e04
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 131 deletions.
24 changes: 12 additions & 12 deletions .github/actions/cloud-slack-e2e/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ runs:
if: ${{ failure() }}
uses: ./.github/actions/dump-cluster

- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
if: ${{ failure() }}
env:
SLACK_USERNAME: Botkube Cloud CI
SLACK_COLOR: 'red'
SLACK_TITLE: 'Message'
SLACK_CHANNEL: 'botkube-cloud-ci-alerts'
SLACK_MESSAGE: "Cloud Slack ${{ inputs.e2e_type }} E2E tests failed :scream:"
SLACK_ICON_EMOJI: ':this-is-fine-fire:'
SLACK_FOOTER: "Fingers crossed it's just an outdated/flaky test..."
SLACK_WEBHOOK: ${{ inputs.slack_alerts_webhook }}
# - name: Slack Notification
# uses: rtCamp/action-slack-notify@v2
# if: ${{ failure() }}
# env:
# SLACK_USERNAME: Botkube Cloud CI
# SLACK_COLOR: 'red'
# SLACK_TITLE: 'Message'
# SLACK_CHANNEL: 'botkube-cloud-ci-alerts'
# SLACK_MESSAGE: "Cloud Slack ${{ inputs.e2e_type }} E2E tests failed :scream:"
# SLACK_ICON_EMOJI: ':this-is-fine-fire:'
# SLACK_FOOTER: "Fingers crossed it's just an outdated/flaky test..."
# SLACK_WEBHOOK: ${{ inputs.slack_alerts_webhook }}
5 changes: 5 additions & 0 deletions .github/actions/setup-go-mod-private/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ inputs:
runs:
using: "composite"
steps:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: './test/go.mod'
cache: true
- name: Download Go modules with private repository
shell: bash
run: |
Expand Down
76 changes: 35 additions & 41 deletions .github/workflows/branch-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ jobs:
with:
persist-credentials: false

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true

- name: Setup Go modules
uses: ./.github/actions/setup-go-mod-private
with:
Expand Down Expand Up @@ -281,39 +275,39 @@ jobs:
# SLACK_ICON_EMOJI: ':this-is-fine-fire:'
# SLACK_FOOTER: "Fingers crossed it's just an outdated/flaky test..."
# SLACK_WEBHOOK: ${{ secrets.SLACK_CI_ALERTS_WEBHOOK }}
#
# cloud-slack-dev-e2e:
# name: Botkube Cloud Slack Dev E2E
# runs-on: ubuntu-latest

cloud-slack-dev-e2e:
name: Botkube Cloud Slack Dev E2E
runs-on: ubuntu-latest
# needs: [ build ]
# permissions:
# contents: read
# packages: read
# concurrency:
# group: cloud-slack-dev-e2e
# cancel-in-progress: false
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Run e2e tests
# uses: ./.github/actions/cloud-slack-e2e
# with:
# access_token: ${{ secrets.E2E_TEST_GH_DEV_ACCOUNT_PAT }}
#
# slack_workspace_name: ${{ secrets.E2E_DEV_SLACK_WORKSPACE_NAME }}
# slack_email: ${{ secrets.E2E_DEV_SLACK_EMAIL }}
# slack_password: ${{ secrets.E2E_DEV_SLACK_USER_PASSWORD }}
# slack_bot_display_name: "BotkubeDev"
# slack_tester_bot_token: ${{ secrets.E2E_DEV_SLACK_TESTER_BOT_TOKEN }}
# slack_tester_bot_name: "botkubedev"
#
# botkube_cloud_api_base_url: "https://api-dev.botkube.io"
# botkube_cloud_email: ${{ secrets.E2E_DEV_BOTKUBE_CLOUD_EMAIL }}
# botkube_cloud_password: ${{ secrets.E2E_DEV_BOTKUBE_CLOUD_PASSWORD }}
# botkube_cloud_team_organization_id: ${{ secrets.E2E_DEV_BOTKUBE_CLOUD_TEAM_ORGANIZATION_ID }}
# botkube_cloud_free_organization_id: ${{ secrets.E2E_DEV_BOTKUBE_CLOUD_FREE_ORGANIZATION_ID }}
# botkube_cloud_plugin_repo_url: "https://storage.googleapis.com/botkube-plugins-latest/plugins-dev-index.yaml"
#
# slack_alerts_webhook: ${{ secrets.SLACK_CI_ALERTS_WEBHOOK }}
#
# e2e_type: "DEV"
permissions:
contents: read
packages: read
concurrency:
group: cloud-slack-dev-e2e
cancel-in-progress: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run e2e tests
uses: ./.github/actions/cloud-slack-e2e
with:
access_token: ${{ secrets.E2E_TEST_GH_DEV_ACCOUNT_PAT }}

slack_workspace_name: ${{ secrets.E2E_DEV_SLACK_WORKSPACE_NAME }}
slack_email: ${{ secrets.E2E_DEV_SLACK_EMAIL }}
slack_password: ${{ secrets.E2E_DEV_SLACK_USER_PASSWORD }}
slack_bot_display_name: "BotkubeDev"
slack_tester_bot_token: ${{ secrets.E2E_DEV_SLACK_TESTER_BOT_TOKEN }}
slack_tester_bot_name: "botkubedev"

botkube_cloud_api_base_url: "https://api-dev.botkube.io"
botkube_cloud_email: ${{ secrets.E2E_DEV_BOTKUBE_CLOUD_EMAIL }}
botkube_cloud_password: ${{ secrets.E2E_DEV_BOTKUBE_CLOUD_PASSWORD }}
botkube_cloud_team_organization_id: ${{ secrets.E2E_DEV_BOTKUBE_CLOUD_TEAM_ORGANIZATION_ID }}
botkube_cloud_free_organization_id: ${{ secrets.E2E_DEV_BOTKUBE_CLOUD_FREE_ORGANIZATION_ID }}
botkube_cloud_plugin_repo_url: "https://storage.googleapis.com/botkube-plugins-latest/plugins-dev-index.yaml"

slack_alerts_webhook: ${{ secrets.SLACK_CI_ALERTS_WEBHOOK }}

e2e_type: "DEV"
42 changes: 27 additions & 15 deletions test/cloud-slack-dev-e2e/cloud_slack_dev_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,34 +374,46 @@ func TestCloudSlackE2E(t *testing.T) {
t.Log("Testing ping with --cluster-name")
command := fmt.Sprintf("ping --cluster-name %s", deployment.Name)
expectedMessage := fmt.Sprintf("`%s` on `%s`\n```\npong", command, deployment.Name)
tester.PostMessageToBot(t, channel.ID(), command)
tester.PostMessageToBot(t, channel.Identifier(), command)
err = tester.WaitForLastMessageContains(tester.BotUserID(), channel.ID(), expectedMessage)
require.NoError(t, err)

t.Log("Testing ping for not connected deployment #2")
command = "ping"
expectedBlockMessage := notConnectedMessage(deployment2.Name, deployment2.ID)
tester.PostMessageToBot(t, channel.ID(), fmt.Sprintf("%s --cluster-name %s", command, deployment2.Name))
tester.PostMessageToBot(t, channel.Identifier(), fmt.Sprintf("%s --cluster-name %s", command, deployment2.Name))

renderedMsg := interactive.RenderMessage(tester.MDFormatter(), expectedBlockMessage)
renderedMsg = strings.Replace(renderedMsg, "\n", " ", -1)
renderedMsg = strings.TrimSuffix(renderedMsg, " ")
err = tester.WaitForLastInteractiveMessagePostedEqualWithCustomRender(tester.BotUserID(), channel.ID(), renderedMsg)
if err != nil { // the new cloud backend not release yet
t.Logf("Fallback to the old behavior with message sent at the channel level...")
err = tester.OnChannel().WaitForLastInteractiveMessagePostedEqualWithCustomRender(tester.BotUserID(), channel.ID(), renderedMsg)
}
require.NoError(t, err)

t.Log("Testing ping for not existing deployment")
command = "ping"
deployName := "non-existing-deployment"
expectedMessage = fmt.Sprintf("*Instance not found* The cluster %q does not exist.", deployName)
tester.PostMessageToBot(t, channel.ID(), fmt.Sprintf("%s --cluster-name %s", command, deployName))
tester.PostMessageToBot(t, channel.Identifier(), fmt.Sprintf("%s --cluster-name %s", command, deployName))
err = tester.WaitForLastMessageContains(tester.BotUserID(), channel.ID(), expectedMessage)
if err != nil { // the new cloud backend not release yet
t.Logf("Fallback to the old behavior with message sent at the channel level...")
err = tester.OnChannel().WaitForLastMessageContains(tester.BotUserID(), channel.ID(), expectedMessage)
}
require.NoError(t, err)

t.Log("Setting cluster as default")
tester.PostMessageToBot(t, channel.ID(), fmt.Sprintf("cloud set default-instance %s", deployment.ID))
tester.PostMessageToBot(t, channel.Identifier(), fmt.Sprintf("cloud set default-instance %s", deployment.ID))
t.Log("Waiting for confirmation message...")
expectedClusterDefaultMsg := fmt.Sprintf(":white_check_mark: Instance %s was successfully selected as the default cluster for this channel.", deployment.Name)
err = tester.WaitForLastMessageEqual(tester.BotUserID(), channel.ID(), expectedClusterDefaultMsg)
if err != nil { // the new cloud backend not release yet
t.Logf("Fallback to the old behavior with message sent at the channel level...")
err = tester.OnChannel().WaitForLastMessageEqual(tester.BotUserID(), channel.ID(), expectedClusterDefaultMsg)
}
require.NoError(t, err)

t.Log("Testing getting all deployments")
Expand All @@ -411,7 +423,7 @@ func TestCloudSlackE2E(t *testing.T) {
strings.Contains(msg, "coredns") &&
strings.Contains(msg, "botkube"), 0, ""
}
tester.PostMessageToBot(t, channel.ID(), command)
tester.PostMessageToBot(t, channel.Identifier(), command)
err = tester.WaitForMessagePosted(tester.BotUserID(), channel.ID(), 1, assertionFn)
require.NoError(t, err)
})
Expand Down Expand Up @@ -458,23 +470,23 @@ func TestCloudSlackE2E(t *testing.T) {
}
return result, 0, ""
}
err = tester.ExpectChannelMessage(channel.ID()).WaitForMessagePosted(tester.BotUserID(), channel.ID(), 1, assertionFn)
err = tester.OnChannel().WaitForMessagePosted(tester.BotUserID(), channel.ID(), 1, assertionFn)
require.NoError(t, err)
})

t.Run("Botkube Deployment -> Cloud sync", func(t *testing.T) {
t.Log("Disabling notification...")
tester.PostMessageToBot(t, channel.ID(), "disable notifications")
tester.PostMessageToBot(t, channel.Identifier(), "disable notifications")
t.Log("Waiting for config reload message...")
expectedReloadMsg := fmt.Sprintf(":arrows_counterclockwise: Configuration reload requested for cluster '%s'. Hold on a sec...", deployment.Name)
err = tester.ExpectChannelMessage(channel.ID()).WaitForMessagePostedRecentlyEqual(tester.BotUserID(), channel.ID(), expectedReloadMsg)

err = tester.OnChannel().WaitForMessagePostedRecentlyEqual(tester.BotUserID(), channel.ID(), expectedReloadMsg)
require.NoError(t, err)

t.Log("Waiting for watch begin message...")
expectedWatchBeginMsg := fmt.Sprintf("My watch begins for cluster '%s'! :crossed_swords:", deployment.Name)
recentMessages := 2 // take into the account the optional "upgrade checker message"
err = tester.WaitForMessagePosted(tester.BotUserID(), channel.ID(), recentMessages, func(msg string) (bool, int, string) {
err = tester.OnChannel().WaitForMessagePosted(tester.BotUserID(), channel.ID(), recentMessages, func(msg string) (bool, int, string) {
if !strings.EqualFold(expectedWatchBeginMsg, msg) {
count := diff.CountMatchBlock(expectedWatchBeginMsg, msg)
msgDiff := diff.Diff(expectedWatchBeginMsg, msg)
Expand All @@ -491,7 +503,7 @@ func TestCloudSlackE2E(t *testing.T) {
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")
tester.PostMessageToBot(t, channel.Identifier(), "status notifications")
err = tester.WaitForLastMessageEqual(tester.BotUserID(), channel.ID(), expectedMessage)
require.NoError(t, err)
})
Expand All @@ -503,13 +515,13 @@ func TestCloudSlackE2E(t *testing.T) {

t.Log("Waiting for config reload message...")
expectedReloadMsg := fmt.Sprintf(":arrows_counterclockwise: Configuration reload requested for cluster '%s'. Hold on a sec...", deployment.Name)
err = tester.ExpectChannelMessage(channel.ID()).WaitForMessagePostedRecentlyEqual(tester.BotUserID(), channel.ID(), expectedReloadMsg)
err = tester.OnChannel().WaitForMessagePostedRecentlyEqual(tester.BotUserID(), channel.ID(), expectedReloadMsg)
require.NoError(t, err)

t.Log("Waiting for watch begin message...")
expectedWatchBeginMsg := fmt.Sprintf("My watch begins for cluster '%s'! :crossed_swords:", deployment.Name)
recentMessages := 2 // take into the account the optional "upgrade checker message"
err = tester.WaitForMessagePosted(tester.BotUserID(), channel.ID(), recentMessages, func(msg string) (bool, int, string) {
err = tester.OnChannel().WaitForMessagePosted(tester.BotUserID(), channel.ID(), recentMessages, func(msg string) (bool, int, string) {
if !strings.EqualFold(expectedWatchBeginMsg, msg) {
count := diff.CountMatchBlock(expectedWatchBeginMsg, msg)
msgDiff := diff.Diff(expectedWatchBeginMsg, msg)
Expand All @@ -518,13 +530,13 @@ func TestCloudSlackE2E(t *testing.T) {
return true, 0, ""
})
require.NoError(t, err)
tester.PostMessageToBot(t, channel.ID(), "list sources")
tester.PostMessageToBot(t, channel.Identifier(), "list sources")

t.Log("Waiting for empty source list...")
expectedSourceListMsg := fmt.Sprintf("%s\n```\nSOURCE ENABLED RESTARTS STATUS LAST_RESTART\n```", cmdHeader("list sources"))
err = tester.WaitForLastMessageEqual(tester.BotUserID(), channel.ID(), expectedSourceListMsg)
require.NoError(t, err)
tester.PostMessageToBot(t, channel.ID(), "list actions")
tester.PostMessageToBot(t, channel.Identifier(), "list actions")
t.Log("Waiting for actions list...")
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)
Expand Down
5 changes: 5 additions & 0 deletions test/commplatform/discord_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,8 @@ func (d *DiscordTester) findUserID(t *testing.T, name string) string {
func (d *DiscordTester) ReplaceBotNamePlaceholder(msg *interactive.CoreMessage, clusterName string) {
msg.ReplaceBotNamePlaceholder(d.BotName())
}

// OnChannel assertion is the default mode for Discord, no action needed.
func (d *DiscordTester) OnChannel() BotDriver {
return d
}
1 change: 1 addition & 0 deletions test/commplatform/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type BotDriver interface {
Timeout() time.Duration
ReplaceBotNamePlaceholder(msg *interactive.CoreMessage, clusterName string)
AssertEquals(expectedMessage string) MessageAssertion
OnChannel() BotDriver
}

type MessageAssertion func(content string) (bool, int, string)
Expand Down
Loading

0 comments on commit df16e04

Please sign in to comment.