Skip to content

Commit

Permalink
Update Cloud Slack E2E tests with plugin enable/disable (#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec authored Jan 22, 2024
1 parent e7c907a commit 9c62fd5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 41 deletions.
3 changes: 3 additions & 0 deletions internal/remote/graphql/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 46 additions & 37 deletions test/cloud-slack-dev-e2e/cloud_slack_dev_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cloud_slack_dev_e2e

import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -91,7 +92,6 @@ func TestCloudSlackE2E(t *testing.T) {
cfg.Slack.Tester.CloudBasedTestEnabled = false // override property used only in the Cloud Slack E2E tests

authHeaderValue := ""
firstPageClosed := false
helmChartUninstalled := false
gqlEndpoint := fmt.Sprintf("%s/%s", cfg.BotkubeCloud.APIBaseURL, cfg.BotkubeCloud.APIGraphQLEndpoint)

Expand Down Expand Up @@ -119,14 +119,7 @@ func TestCloudSlackE2E(t *testing.T) {

page := newBrowserPage(t, browser, cfg)
t.Cleanup(func() {
if firstPageClosed {
return
}

err := page.Close()
if err != nil {
t.Logf("Failed to close page: %v", err)
}
closePage(t, "page", page)
})

var slackAppInstallationURL string
Expand Down Expand Up @@ -165,16 +158,12 @@ func TestCloudSlackE2E(t *testing.T) {
screenshotIfShould(t, cfg, page)
page.MustElementR("a", "open this link in your browser")
page.MustClose()
firstPageClosed = true

t.Log("Opening new window...")
// Workaround for the Slack protocol handler modal which cannot be closed programmatically
slackPage := newBrowserPage(t, browser, cfg)
t.Cleanup(func() {
err := slackPage.Close()
if err != nil {
t.Logf("Failed to close Slack page: %v", err)
}
closePage(t, "slackPage", slackPage)
})

t.Logf("Navigating to the conversation with %q bot...", cfg.Slack.BotDisplayName)
Expand All @@ -183,6 +172,9 @@ func TestCloudSlackE2E(t *testing.T) {

// sometimes it shows up - not sure if that really helps as I didn't see it later ¯\_(ツ)_/¯ We need to test it
shortTimeoutPage := slackPage.Timeout(cfg.DefaultWaitTime)
t.Cleanup(func() {
closePage(t, "shortTimeoutPage", shortTimeoutPage)
})
elem, _ := shortTimeoutPage.Element("button.p-download_modal__not_now")
if elem != nil {
t.Log("Closing the 'Download the Slack app' modal...")
Expand Down Expand Up @@ -215,10 +207,7 @@ func TestCloudSlackE2E(t *testing.T) {
elems[len(elems)-1].MustClick()
botkubePage := wait()
t.Cleanup(func() {
err := botkubePage.Close()
if err != nil {
t.Logf("Failed to close Botkube page: %v", err)
}
closePage(t, "botkubePage", botkubePage)
})

t.Logf("Signing in to Botkube Cloud as %q...", cfg.BotkubeCloud.Email)
Expand Down Expand Up @@ -264,20 +253,34 @@ func TestCloudSlackE2E(t *testing.T) {

t.Log("Finalizing Slack workspace connection...")
if cfg.Slack.WorkspaceAlreadyConnected {
t.Log("Expecting already connected message...")
botkubePage.MustElementR("div.ant-result-title", "Organization Already Connected!")
} else {
t.Log("Finalizing connection...")
screenshotIfShould(t, cfg, botkubePage)
botkubePage.MustElement("a.logo-link")
screenshotIfShould(t, cfg, botkubePage)
botkubePage.MustElementR("button > span", "Connect").MustParent().MustClick()
screenshotIfShould(t, cfg, botkubePage)

// detect homepage
time.Sleep(cfg.DefaultWaitTime) // ensure the screenshots shows a view after button click
screenshotIfShould(t, cfg, botkubePage)
_, err := botkubePage.ElementR(".ant-layout-content p", "All Botkube installations managed by Botkube Cloud.")
assert.NoError(t, err) // fail the test, but move on: try to disconnect Slack workspace later
return
}

t.Log("Finalizing connection...")
screenshotIfShould(t, cfg, botkubePage)
botkubePage.MustElement("a.logo-link")
screenshotIfShould(t, cfg, botkubePage)
botkubePage.MustElementR("button > span", "Connect").MustParent().MustClick()
screenshotIfShould(t, cfg, botkubePage)

t.Log("Detecting homepage...")
time.Sleep(cfg.DefaultWaitTime) // ensure the screenshots shows a view after button click
screenshotIfShould(t, cfg, botkubePage)

// Case 1: There are other instances on the list
shortBkTimeoutPage := botkubePage.Timeout(cfg.DefaultWaitTime)
t.Cleanup(func() {
closePage(t, "shortBkTimeoutPage", shortBkTimeoutPage)
})
_, err := shortBkTimeoutPage.ElementR(".ant-layout-content p", "All Botkube installations managed by Botkube Cloud.")
if err != nil {
t.Logf("Failed to detect homepage with other instances created: %v", err)
// Case 2:
t.Logf("Checking if the homepage is in the 'no instances' state...")
_, err := botkubePage.ElementR(".ant-layout-content h2", "Create your Botkube instance!")
assert.NoError(t, err)
}
})

Expand Down Expand Up @@ -578,12 +581,6 @@ func newBrowserPage(t *testing.T, browser *rod.Browser, cfg E2ESlackConfig) *rod

page, err := browser.Page(proto.TargetCreateTarget{URL: ""})
require.NoError(t, err)
t.Cleanup(func() {
err := page.Close()
if err != nil {
t.Logf("Failed to close page: %s", err.Error())
}
})
page.MustSetUserAgent(&proto.NetworkSetUserAgentOverride{
UserAgent: chromeUserAgent,
})
Expand Down Expand Up @@ -729,3 +726,15 @@ func notConnectedMessage(name, id string) interactive.CoreMessage {
},
}
}

func closePage(t *testing.T, name string, page *rod.Page) {
t.Helper()
err := page.Close()
if err != nil {
if errors.Is(err, context.Canceled) {
return
}

t.Logf("Failed to close page %q: %v", name, err)
}
}
6 changes: 6 additions & 0 deletions test/cloud_graphql/graphql_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (c *Client) MustCreateBasicDeployment(t *testing.T) *gqlModel.Deployment {
Configuration: "{\"recommendations\":{\"pod\":{\"noLatestImageTag\":true,\"labelsSet\":true},\"ingress\":{\"backendServiceValid\":true,\"tlsSecretValid\":true}}}",
},
},
Enabled: true,
},
{
Name: "botkube/kubernetes",
Expand All @@ -105,6 +106,7 @@ func (c *Client) MustCreateBasicDeployment(t *testing.T) *gqlModel.Deployment {
Configuration: "{\"recommendations\":{\"pod\":{\"noLatestImageTag\":true,\"labelsSet\":true},\"ingress\":{\"backendServiceValid\":true,\"tlsSecretValid\":true}}}",
},
},
Enabled: true,
},
{
Name: "botkube/kubectl",
Expand All @@ -116,6 +118,7 @@ func (c *Client) MustCreateBasicDeployment(t *testing.T) *gqlModel.Deployment {
Configuration: "{\"recommendations\":{\"pod\":{\"noLatestImageTag\":true,\"labelsSet\":true},\"ingress\":{\"backendServiceValid\":true,\"tlsSecretValid\":true}}}",
},
},
Enabled: true,
},
},
},
Expand Down Expand Up @@ -178,6 +181,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Configuration: "{\"recommendations\":{\"pod\":{\"noLatestImageTag\":true,\"labelsSet\":true},\"ingress\":{\"backendServiceValid\":true,\"tlsSecretValid\":true}},\"namespaces\":{\"include\":[\"default\"],\"exclude\":[]},\"event\":{\"types\":[\"create\"]},\"resources\":[{\"type\":\"v1/pods\"},{\"type\":\"v1/services\"},{\"type\":\"networking.k8s.io/v1/ingresses\"},{\"type\":\"v1/nodes\"},{\"type\":\"v1/namespaces\"},{\"type\":\"v1/persistentvolumes\"},{\"type\":\"v1/persistentvolumeclaims\"},{\"type\":\"v1/configmaps\"},{\"type\":\"rbac.authorization.k8s.io/v1/roles\"},{\"type\":\"rbac.authorization.k8s.io/v1/rolebindings\"},{\"type\":\"rbac.authorization.k8s.io/v1/clusterrolebindings\"},{\"type\":\"rbac.authorization.k8s.io/v1/clusterroles\"},{\"type\":\"apps/v1/deployments\"},{\"type\":\"apps/v1/statefulsets\"},{\"type\":\"apps/v1/daemonsets\"},{\"type\":\"batch/v1/jobs\"}],\"commands\":{\"verbs\":[\"api-resources\",\"api-versions\",\"cluster-info\",\"describe\",\"explain\",\"get\",\"logs\",\"top\"],\"resources\":[\"deployments\",\"pods\",\"namespaces\",\"daemonsets\",\"statefulsets\",\"storageclasses\",\"nodes\",\"configmaps\",\"services\",\"ingresses\"]},\"filters\":{\"objectAnnotationChecker\":true,\"nodeEventsChecker\":true},\"informerResyncPeriod\":\"30m\",\"log\":{\"level\":\"info\",\"disableColors\":false}}",
},
},
Enabled: true,
},
{
Name: "botkube/kubernetes",
Expand All @@ -189,6 +193,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Configuration: "{\"recommendations\":{\"pod\":{\"noLatestImageTag\":true,\"labelsSet\":true},\"ingress\":{\"backendServiceValid\":true,\"tlsSecretValid\":true}}}",
},
},
Enabled: true,
},
{
Name: "botkube/kubectl",
Expand All @@ -200,6 +205,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Configuration: "{\"recommendations\":{\"pod\":{\"noLatestImageTag\":true,\"labelsSet\":true},\"ingress\":{\"backendServiceValid\":true,\"tlsSecretValid\":true}}}",
},
},
Enabled: true,
},
},
},
Expand Down
4 changes: 1 addition & 3 deletions test/commplatform/slack_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ func (s *SlackTester) WaitForMessagePosted(userID, channelID string, limitMessag
func (s *SlackTester) WaitForInteractiveMessagePosted(userID, channelID string, limitMessages int, assertFn MessageAssertion) error {
var fetchedMessages []slack.Message
var lastErr error
// SA1019 suggested `PollWithContextTimeout` does not exist
// nolint:staticcheck
err := wait.Poll(pollInterval, s.cfg.MessageWaitTimeout, func() (done bool, err error) {
err := wait.PollUntilContextTimeout(context.Background(), pollInterval, s.cfg.MessageWaitTimeout, false, func(_ context.Context) (done bool, err error) {
historyRes, err := s.cli.GetConversationHistory(&slack.GetConversationHistoryParameters{
ChannelID: channelID, Limit: limitMessages,
})
Expand Down
20 changes: 19 additions & 1 deletion test/e2e/gql_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Rbac: &rbac,
},
},
Enabled: true,
},
{
Name: "botkube/kubernetes",
Expand All @@ -71,6 +72,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Rbac: &rbac,
},
},
Enabled: true,
},
{
Name: "botkube/kubernetes",
Expand All @@ -83,6 +85,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Rbac: &rbac,
},
},
Enabled: true,
},
{
Name: "botkube/kubernetes",
Expand All @@ -95,6 +98,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Rbac: &rbac,
},
},
Enabled: true,
},
{
Name: "botkube/kubernetes",
Expand All @@ -107,6 +111,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Rbac: &rbac,
},
},
Enabled: true,
},
{
Name: "botkube/kubernetes",
Expand All @@ -130,6 +135,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
},
},
},
Enabled: true,
},
{
Name: "botkube/kubernetes",
Expand All @@ -142,6 +148,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Rbac: &rbac,
},
},
Enabled: true,
},
{
Name: "botkube/kubernetes",
Expand All @@ -154,6 +161,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Rbac: &rbac,
},
},
Enabled: true,
},
{
Name: "botkube/cm-watcher",
Expand All @@ -166,6 +174,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Rbac: &rbac,
},
},
Enabled: true,
},
{
Name: "botkube/cm-watcher",
Expand All @@ -178,6 +187,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Rbac: &rbac,
},
},
Enabled: true,
},
{
Name: "botkube/kubectl",
Expand All @@ -189,6 +199,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Configuration: "{}",
},
},
Enabled: true,
},
{
Name: "botkube/kubectl",
Expand All @@ -209,10 +220,11 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
}},
},
},
Enabled: true,
},
{
Name: "botkube/kubectl",
DisplayName: "Not bounded",
DisplayName: "Not bound",
Type: gqlModel.PluginTypeExecutor,
Configurations: []*gqlModel.PluginConfigurationInput{
{
Expand All @@ -230,6 +242,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
},
},
},
Enabled: true,
},
{
Name: "botkube/kubectl",
Expand All @@ -251,6 +264,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
},
},
},
Enabled: true,
},
{
Name: "botkube/kubectl",
Expand All @@ -268,6 +282,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
},
},
},
Enabled: true,
},
{
Name: "botkube/helm",
Expand All @@ -280,6 +295,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Rbac: &rbac,
},
},
Enabled: true,
},
{
Name: "botkube/[email protected]",
Expand All @@ -291,6 +307,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Configuration: "{\"changeResponseToUpperCase\":true}",
},
},
Enabled: true,
},
{
Name: "botkube/[email protected]",
Expand All @@ -302,6 +319,7 @@ func (c *Client) CreateBasicDeploymentWithCloudSlack(t *testing.T, clusterName,
Configuration: "{\"changeResponseToUpperCase\":true}",
},
},
Enabled: true,
},
},
},
Expand Down

0 comments on commit 9c62fd5

Please sign in to comment.