Skip to content

Commit

Permalink
Fix the test to make sure the dir exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
howbazaar committed Jul 31, 2014
1 parent 7cfb1f3 commit 07570a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 3 additions & 4 deletions mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ func EnsureServer(args EnsureServerParams) error {
)
dbDir := filepath.Join(args.DataDir, "db")

if err := os.MkdirAll(dbDir, 0700); err != nil {
return fmt.Errorf("cannot create mongo database directory: %v", err)
}
oplogSizeMB := args.OplogSize
if oplogSizeMB == 0 {
var err error
Expand All @@ -192,10 +195,6 @@ func EnsureServer(args EnsureServerParams) error {
return nil
}

if err := os.MkdirAll(dbDir, 0700); err != nil {
return fmt.Errorf("cannot create mongo database directory: %v", err)
}

certKey := args.Cert + "\n" + args.PrivateKey
err = utils.AtomicWriteFile(sslKeyPath(args.DataDir), []byte(certKey), 0600)
if err != nil {
Expand Down
12 changes: 11 additions & 1 deletion mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,17 @@ func (s *MongoSuite) SetUpTest(c *gc.C) {
s.PatchValue(&mongo.JujuMongodPath, s.mongodPath)

// Patch "df" such that it always reports there's 1MB free.
s.PatchValue(mongo.AvailSpace, func(dir string) (float64, error) { return 1, nil })
s.PatchValue(mongo.AvailSpace, func(dir string) (float64, error) {
info, err := os.Stat(dir)
if err != nil {
return 0, err
}
if info.IsDir() {
return 1, nil

}
return 0, fmt.Errorf("not a directory")
})
s.PatchValue(mongo.MinOplogSizeMB, 1)

testPath := c.MkDir()
Expand Down

0 comments on commit 07570a6

Please sign in to comment.