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

Commit

Permalink
make sandbox_processor and sandbox_publisher to 100% code coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Future Outlier <eric901201@gmai.com>
  • Loading branch information
Future Outlier committed Aug 9, 2023
1 parent 22d84e7 commit 85bbe17
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions pkg/async/notifications/implementations/sandbox_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package implementations
import (
"context"
"testing"
"time"

"github.com/flyteorg/flyteadmin/pkg/async/notifications/mocks"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
Expand All @@ -12,7 +13,7 @@ import (

var mockSandboxEmailer mocks.MockEmailer

func TestSandboxProcessor_StartProcessing(t *testing.T) {
func TestSandboxProcessor_StartProcessingSuccess(t *testing.T) {
msgChan := make(chan []byte, 1)
msgChan <- msg
testSandboxProcessor := NewSandboxProcessor(msgChan, &mockSandboxEmailer)
Expand All @@ -29,12 +30,36 @@ func TestSandboxProcessor_StartProcessing(t *testing.T) {
assert.Nil(t, testSandboxProcessor.(*SandboxProcessor).run())
}

func TestSandboxProcessor_StartProcessingNoMessage(t *testing.T) {
msgChan := make(chan []byte, 1)
testSandboxProcessor := NewSandboxProcessor(msgChan, &mockSandboxEmailer)
go testSandboxProcessor.StartProcessing()
time.Sleep(1 * time.Second)
}

func TestSandboxProcessor_StartProcessingError(t *testing.T) {
msgChan := make(chan []byte, 1)
msgChan <- msg

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

testSandboxProcessor := NewSandboxProcessor(msgChan, &mockSandboxEmailer)
go testSandboxProcessor.StartProcessing()

// give time to receive the err in StartProcessing
time.Sleep(1 * time.Second)
assert.Zero(t, len(msgChan))
}

func TestSandboxProcessor_StartProcessingMessageError(t *testing.T) {
msgChan := make(chan []byte, 1)
invalidProtoMessage := []byte("invalid message")
msgChan <- invalidProtoMessage
testSandboxProcessor := NewSandboxProcessor(msgChan, &mockSandboxEmailer)

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

Expand Down

0 comments on commit 85bbe17

Please sign in to comment.