Skip to content

Commit

Permalink
internal: made the queue_test.go more robust (#238)
Browse files Browse the repository at this point in the history
* internal: made the queue_test.go more robust

* internal: made the queue_test.go more robust
  • Loading branch information
brainexe authored Oct 24, 2021
1 parent da8488d commit a7fa9f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
18 changes: 11 additions & 7 deletions command/queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ func TestQueue(t *testing.T) {
actual := command.Run(message)
assert.True(t, actual)
assert.Empty(t, client.InternalMessages)
})

t.Run("Render template with not open PR", func(t *testing.T) {
tpl, err := util.CompileTemplate(`{{$count1 := countBackgroundJobs}}{{$count2 := countBackgroundJobsInChannel "C1234"}}{{$count1}} - {{$count2}}`)
assert.Nil(t, err)
t.Run("Render template with not open PR", func(t *testing.T) {
tpl, err := util.CompileTemplate(`{{$count1 := countBackgroundJobs}}{{$count2 := countBackgroundJobsInChannel "C1234"}}{{$count1}} - {{$count2}}`)
assert.Nil(t, err)

res, err := util.EvalTemplate(tpl, util.Parameters{})
assert.Nil(t, err)
res, err := util.EvalTemplate(tpl, util.Parameters{})
assert.Nil(t, err)

assert.Equal(t, "0 - 0", res)
})
assert.Equal(t, "0 - 0", res)
})

t.Run("Test queue command", func(t *testing.T) {
Expand Down Expand Up @@ -143,12 +143,16 @@ func TestQueue(t *testing.T) {
expectedMessage.Text = "reply test"
expectedMessage.Channel = "C1234"
assert.Equal(t, handledEvent, expectedMessage)

assert.Empty(t, client.InternalMessages)
})

t.Run("Test refresh queue command", func(t *testing.T) {
message.Text = "list queue"
message.UpdatedMessage = true

assert.Empty(t, client.InternalMessages)

mocks.AssertReaction(slackClient, processingReaction, message)
mocks.AssertRemoveReaction(slackClient, processingReaction, message)
mocks.AssertContainsSlackBlocks(t, slackClient, message, client.GetTextBlock("*0 queued commands*"))
Expand Down
9 changes: 8 additions & 1 deletion mocks/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ func AssertContainsSlackBlocks(t *testing.T, slackClient *SlackClient, message m
expectedJSONBlock, err := json.Marshal(block)
assert.Nil(t, err)

return strings.Contains(string(givenJSON), string(expectedJSONBlock))
if strings.Contains(string(givenJSON), string(expectedJSONBlock)) {
// all good!
return true
}

fmt.Println("not matching:", string(givenJSON), string(expectedJSONBlock))

return false
}), mock.Anything).Once().Return("")
}

Expand Down

0 comments on commit a7fa9f7

Please sign in to comment.