github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/cmd/juju/system/list_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package system_test 5 6 import ( 7 "github.com/juju/errors" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 11 "github.com/juju/juju/cmd/juju/system" 12 "github.com/juju/juju/environs/configstore" 13 "github.com/juju/juju/feature" 14 "github.com/juju/juju/testing" 15 ) 16 17 type ListSuite struct { 18 testing.FakeJujuHomeSuite 19 store configstore.Storage 20 } 21 22 var _ = gc.Suite(&ListSuite{}) 23 24 type errorStore struct { 25 err error 26 } 27 28 func (errorStore) CreateInfo(envName string) configstore.EnvironInfo { 29 panic("CreateInfo not implemented") 30 } 31 32 func (errorStore) List() ([]string, error) { 33 panic("List not implemented") 34 } 35 36 func (e errorStore) ListSystems() ([]string, error) { 37 return nil, e.err 38 } 39 40 func (errorStore) ReadInfo(envName string) (configstore.EnvironInfo, error) { 41 panic("ReadInfo not implemented") 42 } 43 44 func (s *ListSuite) SetUpTest(c *gc.C) { 45 s.FakeJujuHomeSuite.SetUpTest(c) 46 s.SetFeatureFlags(feature.JES) 47 s.store = configstore.NewMem() 48 49 var envList = []struct { 50 name string 51 serverUUID string 52 envUUID string 53 }{ 54 { 55 name: "test1", 56 serverUUID: "test1-uuid", 57 envUUID: "test1-uuid", 58 }, { 59 name: "test2", 60 serverUUID: "test1-uuid", 61 envUUID: "test2-uuid", 62 }, { 63 name: "test3", 64 envUUID: "test3-uuid", 65 }, 66 } 67 for _, env := range envList { 68 info := s.store.CreateInfo(env.name) 69 info.SetAPIEndpoint(configstore.APIEndpoint{ 70 Addresses: []string{"localhost"}, 71 CACert: testing.CACert, 72 EnvironUUID: env.envUUID, 73 ServerUUID: env.serverUUID, 74 }) 75 err := info.Write() 76 c.Assert(err, jc.ErrorIsNil) 77 } 78 } 79 80 func (s *ListSuite) TestSystemList(c *gc.C) { 81 context, err := testing.RunCommand(c, system.NewListCommand(s.store)) 82 c.Assert(err, jc.ErrorIsNil) 83 c.Assert(testing.Stdout(context), gc.Equals, "test1\ntest3\n") 84 } 85 86 func (s *ListSuite) TestUnrecognizedArg(c *gc.C) { 87 _, err := testing.RunCommand(c, system.NewListCommand(s.store), "whoops") 88 c.Assert(err, gc.ErrorMatches, `unrecognized args: \["whoops"\]`) 89 } 90 91 func (s *ListSuite) TestListSystemsError(c *gc.C) { 92 s.store = errorStore{err: errors.New("cannot read info")} 93 _, err := testing.RunCommand(c, system.NewListCommand(s.store)) 94 c.Assert(err, gc.ErrorMatches, "failed to list systems in config store: cannot read info") 95 }