Skip to content

Commit

Permalink
Fix message assertion for Cloud Slack
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec committed Sep 22, 2023
1 parent 8355680 commit f07b5d6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/cloud-slack-dev-e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,13 @@ func TestCloudSlackE2E(t *testing.T) {

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

renderedMsg := interactive.RenderMessage(tester.MDFormatter(), expectedBlockMessage)
renderedMsg = strings.Replace(renderedMsg, "\n", " ", -1)
renderedMsg = strings.TrimSuffix(renderedMsg, " ")
err = tester.WaitForLastInteractiveMessagePostedEqualWithCustomRender(tester.BotUserID(), channel.ID(), renderedMsg)
require.NoError(t, err)

t.Log("Testing ping for not existing deployment")
Expand Down
15 changes: 15 additions & 0 deletions test/commplatform/discord_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func (d *DiscordTester) ThirdChannel() Channel {
return d.thirdChannel
}

func (d *DiscordTester) MDFormatter() interactive.MDFormatter {
return d.mdFormatter
}

func (d *DiscordTester) InitUsers(t *testing.T) {
t.Helper()

Expand Down Expand Up @@ -427,6 +431,17 @@ func (d *DiscordTester) WaitForLastInteractiveMessagePostedEqual(userID, channel
})
}

func (d *DiscordTester) WaitForLastInteractiveMessagePostedEqualWithCustomRender(userID, channelID string, renderedMsg string) error {
return d.WaitForMessagePosted(userID, channelID, 1, func(msg string) (bool, int, string) {
if !strings.EqualFold(renderedMsg, msg) {
count := diff.CountMatchBlock(renderedMsg, msg)
msgDiff := diff.Diff(renderedMsg, msg)
return false, count, msgDiff
}
return true, 0, ""
})
}

func (d *DiscordTester) findUserID(t *testing.T, name string) string {
t.Logf("Getting user %q...", name)
res, err := d.cli.GuildMembersSearch(d.cfg.GuildID, name, 50)
Expand Down
2 changes: 2 additions & 0 deletions test/commplatform/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ type BotDriver interface {
BotName() string
BotUserID() string
TesterUserID() string
MDFormatter() interactive.MDFormatter
WaitForInteractiveMessagePostedRecentlyEqual(userID string, channelID string, message interactive.CoreMessage) error
WaitForLastInteractiveMessagePostedEqual(userID string, channelID string, message interactive.CoreMessage) error
WaitForLastInteractiveMessagePostedEqualWithCustomRender(userID, channelID string, renderedMsg string) error
}

type MessageAssertion func(content string) (bool, int, string)
Expand Down
16 changes: 16 additions & 0 deletions test/commplatform/slack_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func (s *SlackTester) ThirdChannel() Channel {
return s.thirdChannel
}

func (s *SlackTester) MDFormatter() interactive.MDFormatter {
return s.mdFormatter
}

func (s *SlackTester) PostInitialMessage(t *testing.T, channelName string) {
t.Helper()
t.Log("Posting welcome message...")
Expand Down Expand Up @@ -361,6 +365,18 @@ func (s *SlackTester) WaitForLastInteractiveMessagePostedEqual(userID, channelID
})
}

func (s *SlackTester) WaitForLastInteractiveMessagePostedEqualWithCustomRender(userID, channelID string, renderedMsg string) error {
return s.WaitForMessagePosted(userID, channelID, 1, func(msg string) (bool, int, string) {
msg = strings.NewReplacer("<https", "https", ">\n", "\n").Replace(msg)
if !strings.EqualFold(renderedMsg, msg) {
count := diff.CountMatchBlock(renderedMsg, msg)
msgDiff := diff.Diff(renderedMsg, msg)
return false, count, msgDiff
}
return true, 0, ""
})
}

func (s *SlackTester) findUserID(t *testing.T, name string) string {
t.Log("Getting users...")
res, err := s.cli.GetUsers()
Expand Down

0 comments on commit f07b5d6

Please sign in to comment.