Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(services): apply mock and naming conventions #391

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: apply test conventions for lark service
  • Loading branch information
svaloumas committed Sep 12, 2022
commit 525374307c5f2178ddc3ab972b17fb505cebe712
4 changes: 4 additions & 0 deletions service/lark/common.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package lark

// sender is an interface for sending a message to an already defined receiver.
//
//go:generate mockery --name=sender --output=. --case=underscore --inpackage
type sender interface {
Send(subject, message string) error
}

// sender is an interface for sending a message to a specific receiver ID.
//
//go:generate mockery --name=sendToer --output=. --case=underscore --inpackage
type sendToer interface {
SendTo(subject, message, id, idType string) error
}
Expand Down
18 changes: 14 additions & 4 deletions service/lark/custom_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAddReceivers(t *testing.T) {
func TestLark_NewCustomAppService(t *testing.T) {
t.Parallel()

assert := require.New(t)

service := NewCustomAppService("", "")
assert.NotNil(service)
}

func TestLark_AddReceivers(t *testing.T) {
t.Parallel()

xs := []*ReceiverID{
Expand All @@ -31,7 +41,7 @@ func TestAddReceivers(t *testing.T) {
assert.ElementsMatch(t, svc.receiveIDs, append(xs, ys...))
}

func TestSendCustomApp(t *testing.T) {
func TestLark_SendCustomApp(t *testing.T) {
t.Parallel()
ctx := context.Background()
assert := assert.New(t)
Expand All @@ -46,7 +56,7 @@ func TestSendCustomApp(t *testing.T) {

// First, test for when the sender returns an error.
for _, tt := range tests {
mockSendToer := NewSendToer(t)
mockSendToer := newMockSendToer(t)
mockSendToer.
On("SendTo", "subject", "message", tt.id, string(tt.typ)).
Return(errors.New(""))
Expand All @@ -63,7 +73,7 @@ func TestSendCustomApp(t *testing.T) {

// Then test for when the sender does not return an error.
for _, tt := range tests {
mockSendToer := NewSendToer(t)
mockSendToer := newMockSendToer(t)
mockSendToer.
On("SendTo", "subject", "message", tt.id, string(tt.typ)).
Return(nil)
Expand Down
39 changes: 0 additions & 39 deletions service/lark/mock_sendToer.go

This file was deleted.

39 changes: 39 additions & 0 deletions service/lark/mock_send_toer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions service/lark/mock_sender.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions service/lark/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,27 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestSendWebhook(t *testing.T) {
func TestLark_NewWebhookService(t *testing.T) {
t.Parallel()

assert := require.New(t)

service := NewWebhookService("")
assert.NotNil(service)
}

func TestLark_SendWebhook(t *testing.T) {
t.Parallel()

assert := assert.New(t)
ctx := context.Background()

// First, test for when the sender returns an error.
{
mockSender := NewSender(t)
mockSender := newMockSender(t)
mockSender.
On("Send", "subject", "message").
Return(errors.New(""))
Expand All @@ -30,7 +40,7 @@ func TestSendWebhook(t *testing.T) {

// Then test for when the sender does not return an error.
{
mockSender := NewSender(t)
mockSender := newMockSender(t)
mockSender.
On("Send", "subject", "message").
Return(nil)
Expand Down