github.com/blend/go-sdk@v1.20220411.3/slack/mock_sender.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package slack 9 10 import ( 11 "context" 12 ) 13 14 // NewMockWebhookSender creates a new mock sender. 15 func NewMockWebhookSender() MockWebhookSender { 16 return MockWebhookSender(make(chan Message)) 17 } 18 19 var ( 20 _ Sender = (*MockWebhookSender)(nil) 21 ) 22 23 // MockWebhookSender is a mocked sender. 24 type MockWebhookSender chan Message 25 26 // Send sends a mocked message. 27 func (ms MockWebhookSender) Send(ctx context.Context, m Message) error { 28 ms <- m 29 return nil 30 } 31 32 // SendAndReadResponse sends a mocked message. 33 func (ms MockWebhookSender) SendAndReadResponse(ctx context.Context, m Message) (*PostMessageResponse, error) { 34 ms <- m 35 return nil, nil 36 } 37 38 // PostMessage sends a mocked message. 39 func (ms MockWebhookSender) PostMessage(channel, text string, options ...MessageOption) error { 40 m := Message{ 41 Channel: channel, 42 Text: text, 43 } 44 for _, option := range options { 45 option(&m) 46 } 47 48 ms <- m 49 return nil 50 } 51 52 // PostMessageContext sends a mocked message. 53 func (ms MockWebhookSender) PostMessageContext(ctx context.Context, channel, text string, options ...MessageOption) error { 54 m := Message{ 55 Channel: channel, 56 Text: text, 57 } 58 for _, option := range options { 59 option(&m) 60 } 61 62 ms <- m 63 return nil 64 }