Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
add email error for sandbox processor test, trying to imporove the co…
Browse files Browse the repository at this point in the history
…de coverage

Signed-off-by: Future Outlier <eric901201@gmai.com>
  • Loading branch information
Future Outlier committed Aug 9, 2023
1 parent 44e5e86 commit c2a9301
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/async/notifications/implementations/sandbox_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (

"github.com/flyteorg/flyteadmin/pkg/async/notifications/mocks"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

var mockSandboxEmailer mocks.MockEmailer

func TestSandboxProcessor_StartProcessing(t *testing.T) {
msgChan := make(chan []byte, 1)
msgChan <- msg
testSandboxProcessor := NewSandboxProcessor(msgChan, &mockSandboxEmailer)

sendEmailValidationFunc := func(ctx context.Context, email admin.EmailMessage) error {
Expand All @@ -22,6 +24,27 @@ func TestSandboxProcessor_StartProcessing(t *testing.T) {
assert.Equal(t, testEmail.SenderEmail, email.SenderEmail)
return nil
}

mockSandboxEmailer.SetSendEmailFunc(sendEmailValidationFunc)
assert.Nil(t, testSandboxProcessor.(*SandboxProcessor).run())
}

func TestSandboxProcessor_StartProcessingEmailError(t *testing.T) {
msgChan := make(chan []byte, 1)
msgChan <- msg
testSandboxProcessor := NewSandboxProcessor(msgChan, &mockSandboxEmailer)

emailError := errors.New("error sending email")
sendEmailValidationFunc := func(ctx context.Context, email admin.EmailMessage) error {
return emailError
}

mockSandboxEmailer.SetSendEmailFunc(sendEmailValidationFunc)
assert.NotNil(t, testSandboxProcessor.(*SandboxProcessor).run())
}

func TestSandboxProcessor_StopProcessing(t *testing.T) {
msgChan := make(chan []byte, 1)
testSandboxProcessor := NewSandboxProcessor(msgChan, &mockSandboxEmailer)
assert.Nil(t, testSandboxProcessor.StopProcessing())
}

0 comments on commit c2a9301

Please sign in to comment.