update mailserver tests to write to a temporary directory instead of using /tmp (#1066)

This commit is contained in:
Andrea Franz 2018-07-02 09:44:02 +02:00 committed by GitHub
parent 809db97e54
commit 8aa046e893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 13 deletions

View File

@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
@ -47,28 +48,47 @@ type ServerTestParams struct {
key *ecdsa.PrivateKey
}
const dataDirPrefix = "whisper-server-test"
func TestMailserverSuite(t *testing.T) {
suite.Run(t, new(MailserverSuite))
}
type MailserverSuite struct {
suite.Suite
server *WMailServer
shh *whisper.Whisper
config *params.WhisperConfig
server *WMailServer
shh *whisper.Whisper
config *params.WhisperConfig
dataDir string
}
func (s *MailserverSuite) SetupTest() {
s.server = &WMailServer{}
s.shh = whisper.New(&whisper.DefaultConfig)
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 = &params.WhisperConfig{
DataDir: "/tmp/",
DataDir: s.dataDir,
Password: "pwd",
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() {
testCases := []struct {
config params.WhisperConfig
@ -83,7 +103,7 @@ func (s *MailserverSuite) TestInit() {
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,
limiterActive: false,
info: "Initializing a mail server with a config with an empty password",
@ -102,7 +122,7 @@ func (s *MailserverSuite) TestInit() {
},
{
config: params.WhisperConfig{
DataDir: "/tmp/",
DataDir: s.dataDir,
Password: "pwd",
},
expectedError: nil,
@ -368,17 +388,11 @@ func (s *MailserverSuite) TestBloomFromReceivedMessage() {
func (s *MailserverSuite) setupServer(server *WMailServer) {
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.RegisterServer(server)
err = server.Init(s.shh, &params.WhisperConfig{DataDir: dir, Password: password, MinimumPoW: powRequirement})
err := server.Init(s.shh, &params.WhisperConfig{DataDir: s.dataDir, Password: password, MinimumPoW: powRequirement})
if err != nil {
s.T().Fatal(err)
}