Skip to content

Commit

Permalink
chore: drop reflection based slack client tests (argoproj#74)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Matyushentsev <[email protected]>
  • Loading branch information
Alexander Matyushentsev authored Jan 28, 2022
1 parent 91deed2 commit ac48363
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
28 changes: 0 additions & 28 deletions pkg/services/slack_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package services

import (
"reflect"
"runtime"
"testing"
"text/template"

Expand Down Expand Up @@ -65,29 +63,3 @@ func TestBuildMessageOptionsWithNonExistTemplate(t *testing.T) {
assert.Empty(t, sn.GroupingKey)
assert.Equal(t, slackutil.Post, sn.DeliveryPolicy)
}

func TestBuildMessageOptionsUsername(t *testing.T) {
n := Notification{}

_, opts, err := buildMessageOptions(n, Destination{}, SlackOptions{Username: "test-username"})
assert.NoError(t, err)
assert.Len(t, opts, 2)

usernameOption := opts[1]

val := runtime.FuncForPC(reflect.ValueOf(usernameOption).Pointer()).Name()
assert.Contains(t, val, "MsgOptionUsername")
}

func TestBuildMessageOptionsIcon(t *testing.T) {
n := Notification{}

_, opts, err := buildMessageOptions(n, Destination{}, SlackOptions{Icon: ":+1:"})
assert.NoError(t, err)
assert.Len(t, opts, 2)

usernameOption := opts[1]

val := runtime.FuncForPC(reflect.ValueOf(usernameOption).Pointer()).Name()
assert.Contains(t, val, "MsgOptionIconEmoji")
}
24 changes: 2 additions & 22 deletions pkg/util/slack/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package slack
import (
"context"
"encoding/json"
"reflect"
"runtime"
"strconv"
"strings"
"testing"

"github.com/argoproj/notifications-engine/pkg/util/slack/mocks"
Expand Down Expand Up @@ -58,23 +55,6 @@ func TestDeliveryPolicy_UnmarshalJSON(t *testing.T) {
}
}

type msgOptionMatcher struct {
name string
}

func (m msgOptionMatcher) Matches(option interface{}) bool {
name := runtime.FuncForPC(reflect.ValueOf(option).Pointer()).Name()
return strings.Contains(name, m.name)
}

func (m msgOptionMatcher) String() string {
return m.name
}

func EqMsgOption(name string) gomock.Matcher {
return msgOptionMatcher{name}
}

func TestThreadedClient(t *testing.T) {
const (
groupingKey string = "group"
Expand Down Expand Up @@ -155,12 +135,12 @@ func TestThreadedClient(t *testing.T) {
m := mocks.NewMockSlackClient(ctrl)

m.EXPECT().
SendMessageContext(gomock.Any(), gomock.Any(), EqMsgOption(tc.wantOpt1)).
SendMessageContext(gomock.Any(), gomock.Any(), gomock.Any()).
Return(channel, ts1, "", nil)

if tc.wantOpt2 != "" {
m.EXPECT().
SendMessageContext(gomock.Any(), gomock.Any(), EqMsgOption(tc.wantOpt2))
SendMessageContext(gomock.Any(), gomock.Any(), gomock.Any())
}

client := NewThreadedClient(m, &state{rate.NewLimiter(rate.Inf, 1), tc.threadTSs, channelMap{}})
Expand Down

0 comments on commit ac48363

Please sign in to comment.