Skip to content

Commit

Permalink
fix email test casses
Browse files Browse the repository at this point in the history
Signed-off-by: FogDong <[email protected]>
  • Loading branch information
FogDong committed Apr 27, 2024
1 parent c6f4d84 commit f3b4133
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions pkg/providers/legacy/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type MailParams = providertypes.LegacyParams[MailVars]
var emailRoutine sync.Map

// Send sends email
func Send(ctx context.Context, params *MailParams) (*any, error) {
func Send(ctx context.Context, params *MailParams) (res *any, err error) {
pCtx := params.ProcessContext
act := params.Action
id := fmt.Sprint(pCtx.GetData(model.ContextStepSessionID))
Expand Down Expand Up @@ -97,8 +97,9 @@ func Send(ctx context.Context, params *MailParams) (*any, error) {
go func() {
if routine, ok := emailRoutine.Load(id); ok && routine == "initializing" {
emailRoutine.Store(id, "sending")
if err := dial.DialAndSend(m); err != nil {
if err = dial.DialAndSend(m); err != nil {
emailRoutine.Store(id, err.Error())
fmt.Println("=========", err.Error())
return
}
emailRoutine.Store(id, "success")
Expand Down
11 changes: 5 additions & 6 deletions pkg/providers/legacy/email/email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package email

import (
"context"
"errors"
"fmt"
"reflect"
"testing"
Expand All @@ -30,6 +29,7 @@ import (

"github.com/kubevela/workflow/pkg/cue/model"
"github.com/kubevela/workflow/pkg/cue/process"
"github.com/kubevela/workflow/pkg/errors"
"github.com/kubevela/workflow/pkg/mock"
providertypes "github.com/kubevela/workflow/pkg/providers/types"
)
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestSendEmail(t *testing.T) {
if tc.errMsg != "" {
patch.Reset()
patch = ApplyMethod(reflect.TypeOf(dial), "DialAndSend", func(_ *gomail.Dialer, _ ...*gomail.Message) error {
return errors.New(tc.errMsg)
return fmt.Errorf(tc.errMsg)
})
defer patch.Reset()
}
Expand All @@ -109,7 +109,8 @@ func TestSendEmail(t *testing.T) {
r.Equal(tc.expectedErr.Error(), err.Error())
return
}
r.NoError(err)
_, ok := err.(errors.GenericActionError)
r.Equal(ok, true)
r.Equal(act.Phase, "Wait")

// mock reconcile
Expand All @@ -122,10 +123,8 @@ func TestSendEmail(t *testing.T) {
},
})
if tc.errMsg != "" {
r.Equal(fmt.Errorf("failed to send email: %s", tc.errMsg), err)
return
r.Contains(err.Error(), tc.errMsg)
}
r.NoError(err)
})
}
}

0 comments on commit f3b4133

Please sign in to comment.