github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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 "github.com/juju/cmd/cmdtesting" 8 gitjujutesting "github.com/juju/testing" 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 "gopkg.in/juju/names.v2" 12 13 "github.com/juju/juju/cmd/juju/model" 14 coremodel "github.com/juju/juju/core/model" 15 "github.com/juju/juju/jujuclient" 16 "github.com/juju/juju/testing" 17 ) 18 19 type DumpCommandSuite struct { 20 testing.FakeJujuXDGDataHomeSuite 21 fake fakeDumpClient 22 store *jujuclient.MemStore 23 } 24 25 var _ = gc.Suite(&DumpCommandSuite{}) 26 27 type fakeDumpClient struct { 28 gitjujutesting.Stub 29 } 30 31 func (f *fakeDumpClient) Close() error { 32 f.MethodCall(f, "Close") 33 return f.NextErr() 34 } 35 36 func (f *fakeDumpClient) DumpModel(model names.ModelTag, simplified bool) (map[string]interface{}, error) { 37 f.MethodCall(f, "DumpModel", model) 38 err := f.NextErr() 39 if err != nil { 40 return nil, err 41 } 42 return map[string]interface{}{ 43 "model-uuid": "fake uuid", 44 "simple": simplified, 45 }, nil 46 } 47 48 func (s *DumpCommandSuite) SetUpTest(c *gc.C) { 49 s.FakeJujuXDGDataHomeSuite.SetUpTest(c) 50 s.fake.ResetCalls() 51 s.store = jujuclient.NewMemStore() 52 s.store.CurrentControllerName = "testing" 53 s.store.Controllers["testing"] = jujuclient.ControllerDetails{} 54 s.store.Accounts["testing"] = jujuclient.AccountDetails{ 55 User: "admin", 56 } 57 err := s.store.UpdateModel("testing", "admin/mymodel", jujuclient.ModelDetails{ 58 ModelUUID: testing.ModelTag.Id(), 59 ModelType: coremodel.IAAS, 60 }) 61 c.Assert(err, jc.ErrorIsNil) 62 s.store.Models["testing"].CurrentModel = "admin/mymodel" 63 } 64 65 func (s *DumpCommandSuite) TestDump(c *gc.C) { 66 ctx, err := cmdtesting.RunCommand(c, model.NewDumpCommandForTest(&s.fake, s.store)) 67 c.Assert(err, jc.ErrorIsNil) 68 s.fake.CheckCalls(c, []gitjujutesting.StubCall{ 69 {"DumpModel", []interface{}{testing.ModelTag}}, 70 {"Close", nil}, 71 }) 72 73 out := cmdtesting.Stdout(ctx) 74 c.Assert(out, gc.Equals, "model-uuid: fake uuid\nsimple: false\n") 75 } 76 77 func (s *DumpCommandSuite) TestDumpSimple(c *gc.C) { 78 ctx, err := cmdtesting.RunCommand(c, model.NewDumpCommandForTest(&s.fake, s.store), "--simplified") 79 c.Assert(err, jc.ErrorIsNil) 80 s.fake.CheckCalls(c, []gitjujutesting.StubCall{ 81 {"DumpModel", []interface{}{testing.ModelTag}}, 82 {"Close", nil}, 83 }) 84 85 out := cmdtesting.Stdout(ctx) 86 c.Assert(out, gc.Equals, "model-uuid: fake uuid\nsimple: true\n") 87 }