github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/juju/paths/paths_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package paths_test
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/juju/paths"
    14  	"github.com/juju/juju/testing"
    15  )
    16  
    17  var _ = gc.Suite(&pathsSuite{})
    18  
    19  type pathsSuite struct {
    20  	testing.BaseSuite
    21  }
    22  
    23  func (s *pathsSuite) TestMongorestorePathDefaultMongoExists(c *gc.C) {
    24  	calledWithPaths := []string{}
    25  	osStat := func(aPath string) (os.FileInfo, error) {
    26  		calledWithPaths = append(calledWithPaths, aPath)
    27  		return nil, nil
    28  	}
    29  	s.PatchValue(paths.OsStat, osStat)
    30  	mongoPath, err := paths.MongorestorePath()
    31  	c.Assert(err, jc.ErrorIsNil)
    32  	c.Assert(mongoPath, gc.Equals, "/usr/lib/juju/bin/mongorestore")
    33  	c.Assert(calledWithPaths, gc.DeepEquals, []string{"/usr/lib/juju/bin/mongorestore"})
    34  }
    35  
    36  func (s *pathsSuite) TestMongorestorePathNoDefaultMongo(c *gc.C) {
    37  	calledWithPaths := []string{}
    38  	osStat := func(aPath string) (os.FileInfo, error) {
    39  		calledWithPaths = append(calledWithPaths, aPath)
    40  		return nil, fmt.Errorf("sorry no mongo")
    41  	}
    42  	s.PatchValue(paths.OsStat, osStat)
    43  
    44  	calledWithLookup := []string{}
    45  	execLookPath := func(aLookup string) (string, error) {
    46  		calledWithLookup = append(calledWithLookup, aLookup)
    47  		return "/a/fake/mongo/path", nil
    48  	}
    49  	s.PatchValue(paths.ExecLookPath, execLookPath)
    50  
    51  	mongoPath, err := paths.MongorestorePath()
    52  	c.Assert(err, jc.ErrorIsNil)
    53  	c.Assert(mongoPath, gc.Equals, "/a/fake/mongo/path")
    54  	c.Assert(calledWithPaths, gc.DeepEquals, []string{"/usr/lib/juju/bin/mongorestore"})
    55  	c.Assert(calledWithLookup, gc.DeepEquals, []string{"mongorestore"})
    56  }