github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/state/backups/internal_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 // +build !windows 5 6 package backups 7 8 import ( 9 "fmt" 10 "os" 11 12 jc "github.com/juju/testing/checkers" 13 gc "gopkg.in/check.v1" 14 15 "github.com/juju/juju/testing" 16 ) 17 18 var _ = gc.Suite(&pathsSuite{}) 19 20 type pathsSuite struct { 21 testing.BaseSuite 22 } 23 24 func (s *pathsSuite) SetUpTest(c *gc.C) { 25 s.PatchValue(&getMongodPath, func() (string, error) { 26 return "path/to/mongod", nil 27 }) 28 } 29 30 func (s *pathsSuite) TestPathDefaultMongoExists(c *gc.C) { 31 calledWithPaths := []string{} 32 osStat := func(aPath string) (os.FileInfo, error) { 33 calledWithPaths = append(calledWithPaths, aPath) 34 return nil, nil 35 } 36 mongoPath, err := getMongoToolPath("tool", osStat, nil) 37 c.Assert(err, jc.ErrorIsNil) 38 c.Assert(mongoPath, gc.Equals, "path/to/tool") 39 c.Assert(calledWithPaths, gc.DeepEquals, []string{"path/to/tool"}) 40 } 41 42 func (s *pathsSuite) TestPathNoDefaultMongo(c *gc.C) { 43 calledWithPaths := []string{} 44 osStat := func(aPath string) (os.FileInfo, error) { 45 calledWithPaths = append(calledWithPaths, aPath) 46 return nil, fmt.Errorf("sorry no mongo") 47 } 48 49 calledWithLookup := []string{} 50 execLookPath := func(aLookup string) (string, error) { 51 calledWithLookup = append(calledWithLookup, aLookup) 52 return "/a/fake/mongo/path", nil 53 } 54 55 mongoPath, err := getMongoToolPath("tool", osStat, execLookPath) 56 c.Assert(err, jc.ErrorIsNil) 57 c.Assert(mongoPath, gc.Equals, "/a/fake/mongo/path") 58 c.Assert(calledWithPaths, gc.DeepEquals, []string{"path/to/tool"}) 59 c.Assert(calledWithLookup, gc.DeepEquals, []string{"tool"}) 60 }