2018-06-27 12:22:09 +00:00
|
|
|
package mailserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-09-25 07:05:38 +00:00
|
|
|
whisper "github.com/status-im/whisper/whisperv6"
|
2018-06-27 12:22:09 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/syndtr/goleveldb/leveldb"
|
|
|
|
"github.com/syndtr/goleveldb/leveldb/iterator"
|
|
|
|
"github.com/syndtr/goleveldb/leveldb/opt"
|
|
|
|
"github.com/syndtr/goleveldb/leveldb/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
type panicDB struct{}
|
|
|
|
|
|
|
|
func (db *panicDB) Close() error {
|
|
|
|
panic("panicDB panic on Close")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db *panicDB) Write(b *leveldb.Batch, opts *opt.WriteOptions) error {
|
|
|
|
panic("panicDB panic on Write")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db *panicDB) Put(k []byte, v []byte, opts *opt.WriteOptions) error {
|
|
|
|
panic("panicDB panic on Put")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db *panicDB) Get(k []byte, opts *opt.ReadOptions) ([]byte, error) {
|
|
|
|
panic("panicDB panic on Get")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db *panicDB) NewIterator(r *util.Range, opts *opt.ReadOptions) iterator.Iterator {
|
|
|
|
panic("panicDB panic on NewIterator")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMailServerDBPanicSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(MailServerDBPanicSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type MailServerDBPanicSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
server *WMailServer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MailServerDBPanicSuite) SetupTest() {
|
|
|
|
s.server = &WMailServer{}
|
|
|
|
s.server.db = &panicDB{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MailServerDBPanicSuite) TestArchive() {
|
|
|
|
defer s.testPanicRecover("Archive")
|
|
|
|
s.server.Archive(&whisper.Envelope{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MailServerDBPanicSuite) TestDeliverMail() {
|
|
|
|
defer s.testPanicRecover("DeliverMail")
|
2018-12-06 09:48:28 +00:00
|
|
|
s.server.DeliverMail(&whisper.Peer{}, &whisper.Envelope{})
|
2018-06-27 12:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MailServerDBPanicSuite) testPanicRecover(method string) {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
s.Failf("error recovering panic", "expected recover to return nil, got: %+v", r)
|
|
|
|
}
|
|
|
|
}
|