github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/juju/model/dump_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for info. 3 4 package model_test 5 6 import ( 7 gitjujutesting "github.com/juju/testing" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 "gopkg.in/juju/names.v2" 11 12 "github.com/juju/juju/cmd/juju/model" 13 "github.com/juju/juju/jujuclient" 14 "github.com/juju/juju/jujuclient/jujuclienttesting" 15 "github.com/juju/juju/testing" 16 ) 17 18 type DumpCommandSuite struct { 19 testing.FakeJujuXDGDataHomeSuite 20 fake fakeDumpClient 21 store *jujuclienttesting.MemStore 22 } 23 24 var _ = gc.Suite(&DumpCommandSuite{}) 25 26 type fakeDumpClient struct { 27 gitjujutesting.Stub 28 } 29 30 func (f *fakeDumpClient) Close() error { 31 f.MethodCall(f, "Close") 32 return f.NextErr() 33 } 34 35 func (f *fakeDumpClient) DumpModel(model names.ModelTag) (map[string]interface{}, error) { 36 f.MethodCall(f, "DumpModel", model) 37 err := f.NextErr() 38 if err != nil { 39 return nil, err 40 } 41 return map[string]interface{}{ 42 "model-uuid": "fake uuid", 43 }, nil 44 } 45 46 func (s *DumpCommandSuite) SetUpTest(c *gc.C) { 47 s.FakeJujuXDGDataHomeSuite.SetUpTest(c) 48 s.fake.ResetCalls() 49 s.store = jujuclienttesting.NewMemStore() 50 s.store.CurrentControllerName = "testing" 51 s.store.Controllers["testing"] = jujuclient.ControllerDetails{} 52 s.store.Accounts["testing"] = jujuclient.AccountDetails{ 53 User: "admin@local", 54 } 55 err := s.store.UpdateModel("testing", "admin@local/mymodel", jujuclient.ModelDetails{ 56 testing.ModelTag.Id(), 57 }) 58 c.Assert(err, jc.ErrorIsNil) 59 s.store.Models["testing"].CurrentModel = "admin@local/mymodel" 60 } 61 62 func (s *DumpCommandSuite) TestDump(c *gc.C) { 63 ctx, err := testing.RunCommand(c, model.NewDumpCommandForTest(&s.fake, s.store)) 64 c.Assert(err, jc.ErrorIsNil) 65 s.fake.CheckCalls(c, []gitjujutesting.StubCall{ 66 {"DumpModel", []interface{}{testing.ModelTag}}, 67 {"Close", nil}, 68 }) 69 70 out := testing.Stdout(ctx) 71 c.Assert(out, gc.Equals, "model-uuid: fake uuid\n") 72 }