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-10-19 09:09:13 +00:00
|
|
|
_, _, _, err := s.server.processRequest(nil, 10, 20, []byte{}, 0, nil, false)
|
2018-06-27 12:22:09 +00:00
|
|
|
s.Error(err)
|
|
|
|
s.Equal("recovered from panic in processRequest: panicDB panic on NewIterator", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MailServerDBPanicSuite) testPanicRecover(method string) {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
s.Failf("error recovering panic", "expected recover to return nil, got: %+v", r)
|
|
|
|
}
|
|
|
|
}
|