* add API methods for setting and deleting email * fix service.SetStringUserDetail signature to return string * switch table test with description to t.Run() * remove debug logging * clarify error handling, functions names * add email integration test * add information about email subscription to readme * change email API calls method from PUT to POST * typo fix, remove unneeded capturing of range variable * email test draft * fix notify mock, email notification test draft * add MockDestination to startupT return * fix tests * add email retrieval for notifications sending * fix mock for notify * rearrange mock notify declaration * add GET /email API handler, fix typos * revert startupT signature change * get rid of startupTWithDest workaround * add rest examples for rest notification * improve email messages formatting * fix email send repeater location * remove unneeded context from sendMessage * change signatures of buildMessage functions to have same field name * add missing authenticate call on TLS connection * add dev user auth token to email requests * change email verification template * email code and tests cleanup * replace fixed spaces with normal ones * human-readable variables names for new comment reply notification * rename Comment to CommentText * add html for comment email notification * fix comment notification html style * fix email test * fix notify email messages rendering * fix comments on rest examples for email * explicitly state email notify email template fields * clarify email API documentation * change email test not to check quoted-printable part of message * Fix link color, add unsubscribe link * fix rest examples tokens * add UnsubscribeLink support to Email * add unsubscribe email handler * fix new reply notification email style
41 lines
751 B
Go
41 lines
751 B
Go
package notify
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sync"
|
|
"time"
|
|
|
|
log "github.com/go-pkgz/lgr"
|
|
)
|
|
|
|
type MockDest struct {
|
|
data []Request
|
|
id int
|
|
closed bool
|
|
lock sync.Mutex
|
|
}
|
|
|
|
func (m *MockDest) Send(ctx context.Context, r Request) error {
|
|
m.lock.Lock()
|
|
defer m.lock.Unlock()
|
|
select {
|
|
case <-time.After(10 * time.Millisecond):
|
|
m.data = append(m.data, r)
|
|
log.Printf("sent %s -> %d", r.Comment.ID, m.id)
|
|
case <-ctx.Done():
|
|
log.Printf("ctx closed %d", m.id)
|
|
m.closed = true
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *MockDest) Get() []Request {
|
|
m.lock.Lock()
|
|
defer m.lock.Unlock()
|
|
res := make([]Request, len(m.data))
|
|
copy(res, m.data)
|
|
return res
|
|
}
|
|
func (m *MockDest) String() string { return fmt.Sprintf("mock id=%d, closed=%v", m.id, m.closed) }
|