launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/store/config_test.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package store_test
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  	"path"
    10  
    11  	gc "launchpad.net/gocheck"
    12  
    13  	"launchpad.net/juju-core/store"
    14  	"launchpad.net/juju-core/testing/testbase"
    15  )
    16  
    17  type ConfigSuite struct {
    18  	testbase.LoggingSuite
    19  }
    20  
    21  var _ = gc.Suite(&ConfigSuite{})
    22  
    23  const testConfig = `
    24  mongo-url: localhost:23456
    25  foo: 1
    26  bar: false
    27  `
    28  
    29  func (s *ConfigSuite) SetUpSuite(c *gc.C) {
    30  	s.LoggingSuite.SetUpSuite(c)
    31  }
    32  
    33  func (s *ConfigSuite) TearDownSuite(c *gc.C) {
    34  	s.LoggingSuite.TearDownSuite(c)
    35  }
    36  
    37  func (s *ConfigSuite) TestReadConfig(c *gc.C) {
    38  	confDir := c.MkDir()
    39  	f, err := os.Create(path.Join(confDir, "charmd.conf"))
    40  	c.Assert(err, gc.IsNil)
    41  	cfgPath := f.Name()
    42  	{
    43  		defer f.Close()
    44  		fmt.Fprint(f, testConfig)
    45  	}
    46  
    47  	dstr, err := store.ReadConfig(cfgPath)
    48  	c.Assert(err, gc.IsNil)
    49  	c.Assert(dstr.MongoURL, gc.Equals, "localhost:23456")
    50  }