github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/jujuclient/bootstrapconfig_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package jujuclient_test 5 6 import ( 7 "os" 8 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/jujuclient" 13 "github.com/juju/juju/testing" 14 ) 15 16 type BootstrapConfigSuite struct { 17 testing.FakeJujuXDGDataHomeSuite 18 store jujuclient.BootstrapConfigStore 19 } 20 21 var _ = gc.Suite(&BootstrapConfigSuite{}) 22 23 func (s *BootstrapConfigSuite) SetUpTest(c *gc.C) { 24 s.FakeJujuXDGDataHomeSuite.SetUpTest(c) 25 s.store = jujuclient.NewFileClientStore() 26 writeTestBootstrapConfigFile(c) 27 } 28 29 func (s *BootstrapConfigSuite) TestBootstrapConfigForControllerNoFile(c *gc.C) { 30 err := os.Remove(jujuclient.JujuBootstrapConfigPath()) 31 c.Assert(err, jc.ErrorIsNil) 32 details, err := s.store.BootstrapConfigForController("not-found") 33 c.Assert(err, gc.ErrorMatches, "bootstrap config for controller not-found not found") 34 c.Assert(details, gc.IsNil) 35 } 36 37 func (s *BootstrapConfigSuite) TestBootstrapConfigForControllerNotFound(c *gc.C) { 38 details, err := s.store.BootstrapConfigForController("not-found") 39 c.Assert(err, gc.ErrorMatches, "bootstrap config for controller not-found not found") 40 c.Assert(details, gc.IsNil) 41 } 42 43 func (s *BootstrapConfigSuite) TestBootstrapConfigForController(c *gc.C) { 44 cfg, err := s.store.BootstrapConfigForController("local.aws-test") 45 c.Assert(err, jc.ErrorIsNil) 46 c.Assert(cfg, gc.NotNil) 47 c.Assert(*cfg, jc.DeepEquals, testBootstrapConfig["local.aws-test"]) 48 } 49 50 func (s *BootstrapConfigSuite) TestUpdateBootstrapConfigNewController(c *gc.C) { 51 err := s.store.UpdateBootstrapConfig("new-controller", testBootstrapConfig["local.mallards"]) 52 c.Assert(err, jc.ErrorIsNil) 53 cfg, err := s.store.BootstrapConfigForController("new-controller") 54 c.Assert(err, jc.ErrorIsNil) 55 c.Assert(*cfg, jc.DeepEquals, testBootstrapConfig["local.mallards"]) 56 } 57 58 func (s *BootstrapConfigSuite) TestUpdateBootstrapConfigOverwrites(c *gc.C) { 59 err := s.store.UpdateBootstrapConfig("local.aws-test", testBootstrapConfig["local.mallards"]) 60 c.Assert(err, jc.ErrorIsNil) 61 cfg, err := s.store.BootstrapConfigForController("local.aws-test") 62 c.Assert(err, jc.ErrorIsNil) 63 c.Assert(*cfg, jc.DeepEquals, testBootstrapConfig["local.mallards"]) 64 }