github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/mongo/service_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package mongo_test 5 6 import ( 7 "strings" 8 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/mongo" 13 "github.com/juju/juju/service/common" 14 svctesting "github.com/juju/juju/service/common/testing" 15 coretesting "github.com/juju/juju/testing" 16 ) 17 18 type serviceSuite struct { 19 coretesting.BaseSuite 20 } 21 22 var _ = gc.Suite(&serviceSuite{}) 23 24 func (s *serviceSuite) TestNewConf(c *gc.C) { 25 dataDir := "/var/lib/juju" 26 dbDir := dataDir + "/db" 27 mongodPath := "/mgo/bin/mongod" 28 mongodVersion := mongo.Mongo24 29 port := 12345 30 oplogSizeMB := 10 31 conf := mongo.NewConf(mongo.ConfigArgs{ 32 DataDir: dataDir, 33 DBDir: dbDir, 34 MongoPath: mongodPath, 35 Port: port, 36 OplogSizeMB: oplogSizeMB, 37 WantNUMACtl: false, 38 Version: mongodVersion, 39 Auth: true, 40 IPv6: true, 41 }) 42 43 expected := common.Conf{ 44 Desc: "juju state database", 45 Limit: map[string]int{ 46 "nofile": 65000, 47 "nproc": 20000, 48 }, 49 Timeout: 300, 50 ExecStart: "/mgo/bin/mongod" + 51 " --dbpath '/var/lib/juju/db'" + 52 " --sslOnNormalPorts" + 53 " --sslPEMKeyFile '/var/lib/juju/server.pem'" + 54 " --sslPEMKeyPassword=ignored" + 55 " --port 12345" + 56 " --syslog" + 57 " --journal" + 58 " --replSet juju" + 59 " --quiet" + 60 " --oplogSize 10" + 61 " --ipv6" + 62 " --auth" + 63 " --keyFile '/var/lib/juju/shared-secret'" + 64 " --noprealloc" + 65 " --smallfiles", 66 } 67 68 c.Check(conf, jc.DeepEquals, expected) 69 c.Check(strings.Fields(conf.ExecStart), jc.DeepEquals, strings.Fields(expected.ExecStart)) 70 } 71 72 func (s *serviceSuite) TestIsServiceInstalledWhenInstalled(c *gc.C) { 73 svcName := mongo.ServiceName 74 svcData := svctesting.NewFakeServiceData(svcName) 75 mongo.PatchService(s.PatchValue, svcData) 76 77 isInstalled, err := mongo.IsServiceInstalled() 78 79 c.Assert(err, jc.ErrorIsNil) 80 c.Assert(isInstalled, jc.IsTrue) 81 } 82 83 func (s *serviceSuite) TestIsServiceInstalledWhenNotInstalled(c *gc.C) { 84 mongo.PatchService(s.PatchValue, svctesting.NewFakeServiceData()) 85 86 isInstalled, err := mongo.IsServiceInstalled() 87 88 c.Assert(err, jc.ErrorIsNil) 89 c.Assert(isInstalled, jc.IsFalse) 90 }