Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Cloud Slack Dev E2E test after recent changes #1277

Merged
merged 7 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion .github/workflows/branch-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- fix-cloud-slack-tests # TODO:
mszostok marked this conversation as resolved.
Show resolved Hide resolved
repository_dispatch:
types: [ trigger-e2e-tests ]

Expand Down Expand Up @@ -119,10 +120,28 @@ jobs:
env:
# we hardcode plugins version, so it's predictable in e2e tests
GORELEASER_CURRENT_TAG: "v0.0.0-latest"
OUTPUT_MODE: "archive"
OUTPUT_MODE: "binary"
SINGLE_PLATFORM: "true"
PLUGIN_TARGETS: "kubernetes,kubectl,cm-watcher,echo,helm"
run: |
make build-plugins

- name: CLI Cache
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
dist/botkube-cli_linux_amd64_v1/botkube
key: ${{ runner.os }}-botkube-cli

- name: Build CLI
run: make release-snapshot-cli

- name: Add Botkube CLI to env
run: |
echo CONFIG_PROVIDER_BOTKUBE_CLI_BINARY_PATH="$PWD/dist/botkube-cli_linux_amd64_v1/botkube" >> $GITHUB_ENV

- name: Run ${{ matrix.integration }} tests
env:
SLACK_TESTER_APP_TOKEN: ${{ secrets.SLACK_TESTER_APP_TOKEN }}
Expand All @@ -132,6 +151,12 @@ jobs:
DISCORD_GUILD_ID: ${{ secrets.DISCORD_GUILD_ID }}
DISCORD_ADDITIONAL_CONTEXT_MESSAGE: "Branch test - commit SHA: ${{github.sha}} - https://github.com/kubeshop/botkube/commit/${{github.sha}}"
PLUGINS_BINARIES_DIRECTORY: ${{ github.workspace }}/plugin-dist
CONFIG_PROVIDER_API_KEY: ${{ secrets.CONFIG_PROVIDER_API_KEY }}
CONFIG_PROVIDER_ENDPOINT: ${{ secrets.CONFIG_PROVIDER_ENDPOINT }}
CONFIG_PROVIDER_SLACK_WORKSPACE_TEAM_ID: ${{ secrets.CONFIG_PROVIDER_SLACK_WORKSPACE_TEAM_ID }}
CONFIG_PROVIDER_IMAGE_REPOSITORY: ${{ env.IMAGE_REPOSITORY }}
CONFIG_PROVIDER_IMAGE_TAG: ${{ env.IMAGE_TAG }}
CONFIG_PROVIDER_HELM_REPO_DIRECTORY: ${{ github.workspace }}/helm
run: |
KUBECONFIG=$(k3d kubeconfig write ${{ matrix.integration }}-test-cluster) \
make test-integration-${{ matrix.integration }}
Expand Down
4 changes: 3 additions & 1 deletion test/cloud-slack-dev-e2e/cloud_slack_dev_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func TestCloudSlackE2E(t *testing.T) {
err := envconfig.Init(&cfg)
require.NoError(t, err)

cfg.Slack.Tester.CloudBasedTestEnabled = false // override property used only in the Cloud Slack E2E tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be good to differentiate a bit more it as we now have two things named cloud slack e2e tests, maybe sth like:

  • cloud Slack enablement tests
  • cloud Slack conversation tests

but let's follow up on this in a separate PR once you will be back @pkosiec


authHeaderValue := ""
firstPageClosed := false
helmChartUninstalled := false
Expand Down Expand Up @@ -267,7 +269,7 @@ func TestCloudSlackE2E(t *testing.T) {
require.NotEmpty(t, authHeaderValue, "Previous subtest needs to pass to get authorization header value")

t.Log("Initializing Slack...")
tester, err := commplatform.NewSlackTester(cfg.Slack.Tester)
tester, err := commplatform.NewSlackTester(cfg.Slack.Tester, nil)
require.NoError(t, err)

t.Log("Initializing users...")
Expand Down
8 changes: 5 additions & 3 deletions test/commplatform/slack_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/kubeshop/botkube/internal/ptr"
"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/bot"
"github.com/kubeshop/botkube/pkg/bot/interactive"
Expand Down Expand Up @@ -75,18 +76,19 @@ func (s *SlackTester) ReplaceBotNamePlaceholder(msg *interactive.CoreMessage, cl
msg.ReplaceBotNamePlaceholder(s.BotName(), api.BotNameWithClusterName(clusterName))
}

func NewSlackTester(slackCfg SlackConfig, apiKey string) (BotDriver, error) {
func NewSlackTester(slackCfg SlackConfig, apiKey *string) (BotDriver, error) {
var token string
if slackCfg.TesterAppToken == "" && slackCfg.TesterBotToken == "" && slackCfg.CloudTesterAppToken == "" {
return nil, errors.New("slack tester tokens are not set")
}

if slackCfg.TesterAppToken != "" {
token = slackCfg.TesterAppToken
}
if slackCfg.TesterBotToken != "" {
token = slackCfg.TesterBotToken
}
if slackCfg.CloudBasedTestEnabled {
if slackCfg.CloudBasedTestEnabled && slackCfg.CloudTesterAppToken != "" {
token = slackCfg.CloudTesterAppToken
}

Expand All @@ -98,7 +100,7 @@ func NewSlackTester(slackCfg SlackConfig, apiKey string) (BotDriver, error) {
mdFormatter := interactive.NewMDFormatter(interactive.NewlineFormatter, func(msg string) string {
return fmt.Sprintf("*%s*", msg)
})
return &SlackTester{cli: slackCli, cfg: slackCfg, mdFormatter: mdFormatter, configProviderApiKey: apiKey}, nil
return &SlackTester{cli: slackCli, cfg: slackCfg, mdFormatter: mdFormatter, configProviderApiKey: ptr.ToValue(apiKey)}, nil
}

func (s *SlackTester) InitUsers(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/bots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/client-go/tools/clientcmd"

"github.com/kubeshop/botkube/internal/httpx"
"github.com/kubeshop/botkube/internal/ptr"
"github.com/kubeshop/botkube/internal/source/kubernetes/filterengine/filters"
"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/bot/interactive"
Expand Down Expand Up @@ -151,7 +152,7 @@ func TestDiscord(t *testing.T) {
func newBotDriver(cfg Config, driverType commplatform.DriverType) (commplatform.BotDriver, error) {
switch driverType {
case commplatform.SlackBot:
return commplatform.NewSlackTester(cfg.Slack, cfg.ConfigProvider.ApiKey)
return commplatform.NewSlackTester(cfg.Slack, ptr.FromType(cfg.ConfigProvider.ApiKey))
case commplatform.DiscordBot:
return commplatform.NewDiscordTester(cfg.Discord)
}
Expand Down
Loading