Project: Botkube (Observability and Analysis / Observability)
File: README.md

This directory contains E2E tests. The tests instrument both Slack and Discord using a tester app and tester bot respectively. Basically, our testers listen to events sent from Botkube in a test cluster. And, the testers also trigger commands for Botkube to execute. On Kubernetes, the E2E tests are self-contained. They just require a Botkube installation on a cluster as highlighted in the instructions below. Kubernetes cluster (e.g. local one created with `k3d`) Export the `GOPRIVATE` environment variable: ```shell go env -w GOPRIVATE=github.com/kubeshop/botkube-cloud ``` Update your global git config file (`~/.gitconfig`) with the new section: ```text [url "git@github.com:kubeshop/botkube-cloud.git"] insteadOf = https://github.com/kubeshop/botkube-cloud ``` Alternatively, if you prefer to use: ```text [url "git@github.com:"] insteadOf = https://github.com/ ``` This new section informs Git that any URL starting with https://github.com/ should have that prefix replaced with ssh://git@github.com/ instead. Since Go uses HTTPS by default, this also affects your `go get` commands. From now on, you can build and run end-to-end tests and update the version in `go.mod` by running: ```shell go get -u github.com/kubeshop/botkube-cloud ``` If you are using IntelliJ, you can define the following environment variable for Go modules: ```shell GOPRIVATE=github.com/kubeshop/botkube-cloud ``` Botkube bot app configured for a Slack workspace according to the Botkube tester app configured according to the NOTE: This is something you need to do only once. Once the tester app is configured, you can use its token for running integration tests as many times as you want. Create new Slack Application on Use "From an app manifest" option Copy and paste this manifest: ```yaml display_information: name: Botkube tester features: bot_user: display_name: Tester always_online: false oauth_config: scopes: bot: channels:join channels:manage chat:write users:read channels:history settings: orgdeployenabled: false socketmodeenabled: false tokenrotationenabled: false ``` Install this app into your workspace Navigate to the OAuth & Permissions section Copy the Bot User OAuth Token and save it for later. You can already export it as environment variable for or : ```bash export SLACKTESTERAPP_TOKEN="{Botkube tester app token} ``` A Discord server available, . Botkube bot app configured for a Discord server according to the . > NOTE: Please name the app `botkube` and skip step 11 as it's not required. Botkube tester bot app configured according to the . NOTE: This is something you need to do only once. Once the tester app is configured, you can use its token for running integration tests as many times as you want. Create a new Discord app . Name the app: `botkube_tester`. Navigate to the Bot

Toggle `PUBLIC BOT` to OFF. Toggle `MESSAGE CONTENT INTENT` to ON. Click the "Reset Token" button. Copy the Token and export it as the `DISCORDTESTERAPP_TOKEN` environment variable. ```bash export DISCORDTESTERAPP_TOKEN="{Botkube Discord tester app bot token}" ``` Click on the "OAuth2" menu section, and navigate to the "URL Generator" page. Select `SCOPES` as `bot`. Select `BOT PERMISSIONS` as: Manage Channels. Read Messages/View Channels. Send Messages. Manage Messages. Embed Links. Attach Files. Read Message History. Mention Everyone. Generate the URL using the OAuth2 URL Generator available under the OAuth2 section to add bot to your Discord server. Copy the generated URL. Paste the generated URL in a new tab, select the discord server to which you want to add the bot, click Continue and Authorize Bot addition. Find the name of the server in the top left. Right click and select `CopyID` to copy the server ID. This is the `DISCORDGUILDID` that we'll need to run tests against the server. ```bash export DISCORDGUILDID="{Botkube Discord tester guildID}" ``` Use environment vars for the specific platform (Slack or Discord or both) when running your E2E tests. For example, if you're only running Discord tests, you can omit env var prefixed with `SLACK_..`. Export required environment variables: ```bash export SLACKBOTTOKEN="{token for your configured Slack Botkube app}" # WARNING: Token for Botkube Slack bot, not the Tester! export DISCORDBOTID="{Botkube Discord bot ClientID}" # WARNING: ClientID for Botkube Discord bot, not the Tester bot! export DISCORDBOTTOKEN="{token for your configured Discord Botkube bot}" # WARNING: Token for Botkube Discord bot, not the Tester! export IMAGE_REGISTRY="ghcr.io" export IMAGE_REPOSITORY="kubeshop/botkube" export IMAGE_TAG="v9.99.9-dev" export SLACKTESTERAPP_TOKEN="{Botkube Slack tester app token}" # WARNING: Token for Tester, not the Botkube Slack bot! export DISCORDTESTERAPP_TOKEN="{Botkube Discord tester app token}" # WARNING: Token for Tester, not the Botkube Discord bot! export DISCORDGUILDID="{Discord server ID}" # Where the tests will export SLACKTESTERNAME="{Name of Botkube SLACK tester app}" # WARNING: tester name defaults to `tester` when a name is not provided for local test runs! export DISCORDTESTERNAME="{Name of Botkube DISCORD tester app}" # WARNING: tester name defaults to `tester` when a name is not provided for local test runs! ``` Install Botkube using Helm chart: ```bash helm install botkube --namespace botkube ./helm/botkube --wait --create-namespace \ -f ./helm/botkube/e2e-test-values.yaml \ --set communications.default-group.slack.token="${SLACKBOTTOKEN}" \ --set communications.default-group.discord.token="${DISCORDBOTTOKEN}" \ --set communications.default-group.discord.botID="${DISCORDBOTID}" \ --set image.registry="${IMAGE_REGISTRY}" \ --set image.repository="${IMAGE_REPOSITORY}" \ --set image.tag="${IMAGE_TAG}" ``` We test also the Botkube plugins system. To compile Botkube plugins, run: ```bash OUTPUT_MODE="archive" make build-plugins ``` By default, built plugins' binaries are available under `plugin-dist`

The e2e framework builds the plugins index file dynamically and starts the HTTP server that is later accessible from the k3d cluster. To override default settings, export following environment variables: ```bash export PLUGINSBINARIESDIRECTORY="./plugin-dist" export PLUGINSSERVERHOST="http://host.k3d.internal" # on K3d enabling you to access your host system by referring to it as host.k3d.internal export PLUGINSSERVERPORT="3000" ``` Ensure the environment variables for your target platforms are exported: ```bash export KUBECONFIG=/Users/$USER/.kube/config # set custom path if necessary export SLACKTESTERAPP_TOKEN="{Botkube Slack tester app token}" # WARNING: Token for Tester, not the Botkube Slack bot! export DISCORDTESTERAPP_TOKEN="{Botkube Discord tester app token}" # WARNING: Token for Tester, not the Botkube Discord bot! export DISCORDGUILDID="{Discord server ID}" ``` Run the tests for Slack: ```bash make test-integration-slack ``` Run the tests for Discord: ```bash make test-integration-discord ``` Botkube tracks whether the initial help message was sent or not to minimise spam. This is tracked in a `botkube-system` ConfigMap. After running the tests for an e2e target, e.g. `make test-integration-slack`, please ensure this ConfigMap is removed before rerunning the test against another target, e.g. `make test-integration-discord`. ```bash kubectl delete cm botkube-system -n botkube # or the namespace where Botkube is installed ``` If you don't remove the ConfigMap, any e2e tests looking to verify that a help message is displayed will error. This also stops the rest of the e2e tests from running. You can test Botkube Cloud Slack with Botkube Cloud. Follow the instructions below to set up the test environment and run the tests. Create Slack user for testing purposes with access to a given Slack workspace. Create Botkube Cloud user with two organizations: FREE and TEAM one (with Cloud Slack quota). Follow the instructions to set up "Tester" bot. To run the tests, get all the noted data from previous steps and export them as environment variables. ```bash export SLACKWORKSPACENAME="" # e.g. my-workspace export SLACK_EMAIL="" # e.g. my-email@example.com export SLACK_PASSWORD="" export SLACKTESTERBOT_NAME="" # e.g. botkubedev export SLACKTESTERTESTERBOTTOKEN="" # e.g. xoxb-... export BOTKUBECLOUDEMAIL="" # e.g. my-email@example.com export BOTKUBECLOUDPASSWORD="" export BOTKUBECLOUDTEAMORGANIZATIONID="" # e.g. 204a2d86-265c-4ae2-89a8-928f823ec4da export BOTKUBECLOUDFREEORGANIZATIONID="" # e.g. c03bd605-7b8d-490f-b4d5-57c8a0560e83 export KUBECONFIG="" # path to your kubeconfig export BOTKUBECLOUDAPIBASEURL="" e.g. http://localhost:8080 export BOTKUBECLOUDAPISLACKAPPINSTALLATIONBASEURLOVERRIDE="" # provide if necessary e.g. using ngrok: https://d5ac-194-33-77-250.ngrok-free.app export SLACKBOTDISPLAY_NAME="" # e.g. BotkubeDev export SLACKWORKSPACEALREADY_CONNECTED="false" export SLACKDISCONNECTWORKSPACEAFTERTESTS="true" export PAGE_TIMEOUT="1m" export SCREENSHOTS_ENABLED="false" # disable screenshots ``` To run the test in headless mode (without browser window), run: ```shell make test-cloud-slack-dev-e2e ``` To run the tests with Chromium browser window visible, run: ```shell test-cloud-slack-dev-e2e-show-browser ``` Refer to the `E2ESlackConfig` (`./cloud-slack-dev-e2e/cloudslackdeve2etest.go`) for all possible environment variables.