Skip to content

Commit

Permalink
Merge pull request #502 from innogames/mock_cleanup
Browse files Browse the repository at this point in the history
test: cleanup mocks to find unwanted asserts
  • Loading branch information
brainexe authored Nov 20, 2023
2 parents 4f4424f + c1e6761 commit 3bb5733
Show file tree
Hide file tree
Showing 39 changed files with 44 additions and 54 deletions.
2 changes: 1 addition & 1 deletion bot/matcher/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestAdmin(t *testing.T) {
t.Run("Test no Admin", func(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)

cfg := config.Config{}
cfg.AdminUsers = []string{
Expand Down
4 changes: 2 additions & 2 deletions bot/matcher/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestGroup(t *testing.T) {
NewRegexpMatcher(`add reaction :(?P<reaction>.*):`, testRunner),
NewAdminMatcher(
cfg.AdminUsers,
&mocks.SlackClient{},
mocks.NewSlackClient(t),
NewRegexpMatcher(`remove reaction :(?P<reaction>.*):`, testRunner),
),
)
Expand Down Expand Up @@ -62,7 +62,7 @@ func BenchmarkMatchChained(b *testing.B) {
NewPrefixMatcher(`prefix`, testRunner),
NewAdminMatcher(
config.UserList{},
&mocks.SlackClient{},
mocks.NewSlackClient(b),
NewTextMatcher(`text`, testRunner),
),
NewVoidMatcher(),
Expand Down
2 changes: 1 addition & 1 deletion command/add_button_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestAddButton(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)

base := bot.BaseCommand{SlackClient: slackClient}

Expand Down
2 changes: 1 addition & 1 deletion command/add_link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestAddLink(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

command := bot.Commands{}
Expand Down
2 changes: 1 addition & 1 deletion command/admin/bot_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestBotLog(t *testing.T) {
testFile := "test.log"

slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

client.AllUsers = config.UserMap{
Expand Down
2 changes: 1 addition & 1 deletion command/admin/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestPing(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

botLog := newPingCommand(base)
Expand Down
2 changes: 1 addition & 1 deletion command/admin/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestStatsLog(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

cfg := &config.Config{}
Expand Down
2 changes: 1 addition & 1 deletion command/clouds/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestGetCommands(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

t.Run("AWS is not active", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion command/cron/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func TestCron(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

crons := []config.Cron{
Expand Down
2 changes: 1 addition & 1 deletion command/custom_commmands/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestCustomCommands(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

lock := mocks.LockInternalMessages()
Expand Down
2 changes: 1 addition & 1 deletion command/custom_variables/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestCustomCommands(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

cfg := &config.Config{}
Expand Down
4 changes: 2 additions & 2 deletions command/defined_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestInvalidMacro(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

client.InternalMessages = make(chan msg.Message, 2)
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestInvalidMacro(t *testing.T) {
}

func TestDefinedCommands(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

lock := mocks.LockInternalMessages()
Expand Down
2 changes: 1 addition & 1 deletion command/delay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func TestDelay(t *testing.T) {
client.InternalMessages = make(chan msg.Message, 2)
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)

base := bot.BaseCommand{SlackClient: slackClient}

Expand Down
2 changes: 1 addition & 1 deletion command/games/number_guesser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestNumberGuesser(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

command := NewNumberGuesserCommand(base)
Expand Down
2 changes: 1 addition & 1 deletion command/games/quiz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestQuiz(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion command/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestHelp(t *testing.T) {
cfg := config.Config{}
cfg.Jenkins.Host = "bitbucket.example.com"
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)

base := bot.BaseCommand{SlackClient: slackClient}

Expand Down
4 changes: 2 additions & 2 deletions command/jenkins/client/start_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func TestStartBuild(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
cfg := config.JobConfig{}
message := msg.Message{}

Expand Down Expand Up @@ -143,7 +143,7 @@ func TestGetAttachment(t *testing.T) {
}

func TestSendBuildStartedMessage(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
ref := msg.MessageRef{}

job := &gojenkins.Job{
Expand Down
2 changes: 1 addition & 1 deletion command/jenkins/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func getTestJenkinsCommand() (*mocks.SlackClient, *mocks.Client, jenkinsCommand)
}

func TestGetCommands(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

t.Run("Jenkins is not active", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion command/jira/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestCommands(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)

cfg := &config.Jira{
Host: "https://issues.apache.org/jira/",
Expand Down
2 changes: 1 addition & 1 deletion command/jira/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestCommentJira(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)

mux := http.NewServeMux()
server := httptest.NewServer(mux)
Expand Down
2 changes: 1 addition & 1 deletion command/jira/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func TestJiraSearch(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)

cfg := &config.Jira{
Host: "https://issues.apache.org/jira/",
Expand Down
2 changes: 1 addition & 1 deletion command/jira/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestWatchJira(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)

// todo fake http client
cfg := &config.Jira{
Expand Down
2 changes: 1 addition & 1 deletion command/openai/dalle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestDalle(t *testing.T) {
// init memory based storage
storage.InitStorage("")

slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

t.Run("test http error", func(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions command/openai/openai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestOpenai(t *testing.T) {
// init memory based storage
storage.InitStorage("")

slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

t.Run("Openai is not active", func(t *testing.T) {
Expand Down Expand Up @@ -157,7 +157,6 @@ data: [DONE]`,
mocks.AssertReaction(slackClient, ":coffee:", message)
mocks.AssertRemoveReaction(slackClient, ":coffee:", message)
mocks.AssertSlackMessage(slackClient, message, "...", mock.Anything)
mocks.AssertSlackMessage(slackClient, message, "The answer is 3", mock.Anything)

actual = commands.Run(message)
queue.WaitTillHavingNoQueuedMessage()
Expand Down
2 changes: 1 addition & 1 deletion command/pool/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
var _ bot.Runnable = &poolCommands{}

func TestPools(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

t.Run("Pools are not active", func(t *testing.T) {
Expand Down
6 changes: 2 additions & 4 deletions command/pullrequest/bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func TestBitbucketNotActive(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

cfg := &config.DefaultConfig
Expand All @@ -42,7 +42,7 @@ func TestBitbucketNotActive(t *testing.T) {
}

func TestBitbucketFakeServer(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

server := spawnBitbucketTestServer()
Expand All @@ -65,8 +65,6 @@ func TestBitbucketFakeServer(t *testing.T) {
message.Text = server.URL + "/projects/myProject/repos/myRepo/pull-requests/1339 please review ASAP!"

slackClient.On("GetReactions", message.GetMessageRef(), slack.NewGetReactionsParameters()).Return([]slack.ItemReaction{}, nil)
mocks.AssertReaction(slackClient, "white_check_mark", message)
mocks.AssertReaction(slackClient, "twisted_rightwards_arrows", message)

actual := command.Run(message)
assert.True(t, actual)
Expand Down
2 changes: 1 addition & 1 deletion command/pullrequest/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func TestGithub(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

cfg := &config.DefaultConfig
Expand Down
2 changes: 1 addition & 1 deletion command/pullrequest/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func TestGitlab(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

server := spawnTestServer()
Expand Down
7 changes: 1 addition & 6 deletions command/pullrequest/pull_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (t *testFetcher) getHelp() []bot.Help {
}

func TestGetCommands(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

cfg := &config.Config{}
Expand Down Expand Up @@ -82,7 +82,6 @@ func TestPullRequest(t *testing.T) {
slackClient.
On("GetReactions", msgRef, slack.NewGetReactionsParameters()).Return(nil, nil)

mocks.AssertRemoveReaction(slackClient, "eyes", message)
mocks.AssertReaction(slackClient, "project_approve", message)
mocks.AssertReaction(slackClient, "twisted_rightwards_arrows", message)

Expand All @@ -102,8 +101,6 @@ func TestPullRequest(t *testing.T) {
}
message.Text = "vcd.example.com/projects/foo/repos/bar/pull-requests/1337"

mocks.AssertRemoveReaction(slackClient, "eyes", message)
mocks.AssertRemoveReaction(slackClient, "project_approve", message)
mocks.AssertReaction(slackClient, "x", message)

actual := commands.Run(message)
Expand All @@ -122,8 +119,6 @@ func TestPullRequest(t *testing.T) {
}
message.Text = "vcd.example.com/projects/foo/repos/bar/pull-requests/1337"

mocks.AssertRemoveReaction(slackClient, "eyed", message)
mocks.AssertRemoveReaction(slackClient, "x", message)
mocks.AssertReaction(slackClient, "approve_backend", message)

actual := commands.Run(message)
Expand Down
5 changes: 2 additions & 3 deletions command/queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func TestQueue(t *testing.T) {
client.InternalMessages = make(chan msg.Message, 2)
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

message := msg.Message{}
Expand Down Expand Up @@ -83,7 +83,6 @@ func TestQueue(t *testing.T) {

mocks.AssertReaction(slackClient, waitIcon, message)
mocks.AssertReaction(slackClient, doneIcon, message)
mocks.AssertRemoveReaction(slackClient, waitIcon, message)

actual := command.Run(message)
assert.True(t, actual)
Expand Down Expand Up @@ -164,7 +163,7 @@ func TestQueue(t *testing.T) {

func TestFallbackQueue(t *testing.T) {
client.InternalMessages = make(chan msg.Message, 2)
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

message := msg.Message{}
Expand Down
2 changes: 1 addition & 1 deletion command/random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestRandom(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

randomCommand := NewRandomCommand(base).(*randomCommand)
Expand Down
2 changes: 1 addition & 1 deletion command/reaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestReaction(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

reaction := NewReactionCommand(base)
Expand Down
2 changes: 1 addition & 1 deletion command/reply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestReply(t *testing.T) {
slackClient := &mocks.SlackClient{}
slackClient := mocks.NewSlackClient(t)
base := bot.BaseCommand{SlackClient: slackClient}

reply := NewReplyCommand(base)
Expand Down
Loading

0 comments on commit 3bb5733

Please sign in to comment.