update mailserver tests to write to a temporary directory instead of using /tmp (#1066)
This commit is contained in:
parent
809db97e54
commit
8aa046e893
|
@ -22,6 +22,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -47,28 +48,47 @@ type ServerTestParams struct {
|
||||||
key *ecdsa.PrivateKey
|
key *ecdsa.PrivateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dataDirPrefix = "whisper-server-test"
|
||||||
|
|
||||||
func TestMailserverSuite(t *testing.T) {
|
func TestMailserverSuite(t *testing.T) {
|
||||||
suite.Run(t, new(MailserverSuite))
|
suite.Run(t, new(MailserverSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
type MailserverSuite struct {
|
type MailserverSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
server *WMailServer
|
server *WMailServer
|
||||||
shh *whisper.Whisper
|
shh *whisper.Whisper
|
||||||
config *params.WhisperConfig
|
config *params.WhisperConfig
|
||||||
|
dataDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MailserverSuite) SetupTest() {
|
func (s *MailserverSuite) SetupTest() {
|
||||||
s.server = &WMailServer{}
|
s.server = &WMailServer{}
|
||||||
s.shh = whisper.New(&whisper.DefaultConfig)
|
s.shh = whisper.New(&whisper.DefaultConfig)
|
||||||
s.shh.RegisterServer(s.server)
|
s.shh.RegisterServer(s.server)
|
||||||
|
|
||||||
|
var err error
|
||||||
|
s.dataDir, err = ioutil.TempDir("/tmp", dataDirPrefix)
|
||||||
|
if err != nil {
|
||||||
|
s.FailNow("failed creating tmp data dir", err)
|
||||||
|
}
|
||||||
|
|
||||||
s.config = ¶ms.WhisperConfig{
|
s.config = ¶ms.WhisperConfig{
|
||||||
DataDir: "/tmp/",
|
DataDir: s.dataDir,
|
||||||
Password: "pwd",
|
Password: "pwd",
|
||||||
MailServerRateLimit: 5,
|
MailServerRateLimit: 5,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *MailserverSuite) TearDownTest() {
|
||||||
|
if s.dataDir != "" {
|
||||||
|
if err := os.RemoveAll(s.dataDir); err != nil {
|
||||||
|
fmt.Printf("couldn't remove temporary data dir %s: %v", s.dataDir, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (s *MailserverSuite) TestInit() {
|
func (s *MailserverSuite) TestInit() {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
config params.WhisperConfig
|
config params.WhisperConfig
|
||||||
|
@ -83,7 +103,7 @@ func (s *MailserverSuite) TestInit() {
|
||||||
info: "Initializing a mail server with a config with empty DataDir",
|
info: "Initializing a mail server with a config with empty DataDir",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
config: params.WhisperConfig{DataDir: "/tmp/", Password: ""},
|
config: params.WhisperConfig{DataDir: s.dataDir, Password: ""},
|
||||||
expectedError: errPasswordNotProvided,
|
expectedError: errPasswordNotProvided,
|
||||||
limiterActive: false,
|
limiterActive: false,
|
||||||
info: "Initializing a mail server with a config with an empty password",
|
info: "Initializing a mail server with a config with an empty password",
|
||||||
|
@ -102,7 +122,7 @@ func (s *MailserverSuite) TestInit() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
config: params.WhisperConfig{
|
config: params.WhisperConfig{
|
||||||
DataDir: "/tmp/",
|
DataDir: s.dataDir,
|
||||||
Password: "pwd",
|
Password: "pwd",
|
||||||
},
|
},
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
|
@ -368,17 +388,11 @@ func (s *MailserverSuite) TestBloomFromReceivedMessage() {
|
||||||
|
|
||||||
func (s *MailserverSuite) setupServer(server *WMailServer) {
|
func (s *MailserverSuite) setupServer(server *WMailServer) {
|
||||||
const password = "password_for_this_test"
|
const password = "password_for_this_test"
|
||||||
const dbPath = "whisper-server-test"
|
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", dbPath)
|
|
||||||
if err != nil {
|
|
||||||
s.T().Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
s.shh = whisper.New(&whisper.DefaultConfig)
|
s.shh = whisper.New(&whisper.DefaultConfig)
|
||||||
s.shh.RegisterServer(server)
|
s.shh.RegisterServer(server)
|
||||||
|
|
||||||
err = server.Init(s.shh, ¶ms.WhisperConfig{DataDir: dir, Password: password, MinimumPoW: powRequirement})
|
err := server.Init(s.shh, ¶ms.WhisperConfig{DataDir: s.dataDir, Password: password, MinimumPoW: powRequirement})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.T().Fatal(err)
|
s.T().Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue