github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/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 port := 12345 29 oplogSizeMB := 10 30 conf := mongo.NewConf(dataDir, dbDir, mongodPath, port, oplogSizeMB, false) 31 32 expected := common.Conf{ 33 Desc: "juju state database", 34 Limit: map[string]int{ 35 "nofile": 65000, 36 "nproc": 20000, 37 }, 38 Timeout: 300, 39 ExecStart: "/mgo/bin/mongod" + 40 " --auth" + 41 " --dbpath '/var/lib/juju/db'" + 42 " --sslOnNormalPorts" + 43 " --sslPEMKeyFile '/var/lib/juju/server.pem'" + 44 " --sslPEMKeyPassword ignored" + 45 " --port 12345" + 46 " --noprealloc" + 47 " --syslog" + 48 " --smallfiles" + 49 " --journal" + 50 " --keyFile '/var/lib/juju/shared-secret'" + 51 " --replSet juju" + 52 " --ipv6" + 53 " --oplogSize 10", 54 } 55 c.Check(conf, jc.DeepEquals, expected) 56 c.Check(strings.Fields(conf.ExecStart), jc.DeepEquals, strings.Fields(expected.ExecStart)) 57 } 58 59 func (s *serviceSuite) TestIsServiceInstalledWhenInstalled(c *gc.C) { 60 namespace := "some-namespace" 61 svcName := mongo.ServiceName(namespace) 62 svcData := svctesting.NewFakeServiceData(svcName) 63 mongo.PatchService(s.PatchValue, svcData) 64 65 isInstalled, err := mongo.IsServiceInstalled(namespace) 66 67 c.Assert(err, jc.ErrorIsNil) 68 c.Assert(isInstalled, jc.IsTrue) 69 } 70 71 func (s *serviceSuite) TestIsServiceInstalledWhenNotInstalled(c *gc.C) { 72 mongo.PatchService(s.PatchValue, svctesting.NewFakeServiceData()) 73 74 isInstalled, err := mongo.IsServiceInstalled("some-namespace") 75 76 c.Assert(err, jc.ErrorIsNil) 77 c.Assert(isInstalled, jc.IsFalse) 78 }