1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for info.
9
"github.com/juju/errors"
10
gitjujutesting "github.com/juju/testing"
11
jc "github.com/juju/testing/checkers"
12
gc "gopkg.in/check.v1"
13
"gopkg.in/juju/names.v2"
15
"github.com/juju/juju/apiserver/params"
16
"github.com/juju/juju/cmd/juju/model"
17
"github.com/juju/juju/jujuclient"
18
"github.com/juju/juju/jujuclient/jujuclienttesting"
19
"github.com/juju/juju/status"
20
"github.com/juju/juju/testing"
23
type ShowCommandSuite struct {
24
testing.FakeJujuXDGDataHomeSuite
25
fake fakeModelShowClient
26
store *jujuclienttesting.MemStore
30
var _ = gc.Suite(&ShowCommandSuite{})
32
type fakeModelShowClient struct {
38
func (f *fakeModelShowClient) Close() error {
39
f.MethodCall(f, "Close")
43
func (f *fakeModelShowClient) ModelInfo(tags []names.ModelTag) ([]params.ModelInfoResult, error) {
44
f.MethodCall(f, "ModelInfo", tags)
46
return nil, errors.Errorf("expected 1 tag, got %d", len(tags))
48
if tags[0] != testing.ModelTag {
49
return nil, errors.Errorf("expected %s, got %s", testing.ModelTag.Id(), tags[0].Id())
51
return []params.ModelInfoResult{{Result: &f.info, Error: f.err}}, f.NextErr()
54
type attrs map[string]interface{}
56
func (s *ShowCommandSuite) SetUpTest(c *gc.C) {
57
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
58
lastConnection := time.Date(2015, 3, 20, 0, 0, 0, 0, time.UTC)
59
statusSince := time.Date(2016, 4, 5, 0, 0, 0, 0, time.UTC)
61
users := []params.ModelUserInfo{{
62
UserName: "admin@local",
63
LastConnection: &lastConnection,
66
UserName: "bob@local",
73
s.fake.info = params.ModelInfo{
75
UUID: testing.ModelTag.Id(),
76
ControllerUUID: "1ca2293b-fdb9-4299-97d6-55583bb39364",
77
OwnerTag: "user-admin@local",
79
CloudRegion: "some-region",
80
ProviderType: "openstack",
82
Status: params.EntityStatus{
83
Status: status.StatusActive,
89
s.expectedOutput = attrs{
92
"model-uuid": "deadbeef-0bad-400d-8000-4b1d0d06f00d",
93
"controller-uuid": "1ca2293b-fdb9-4299-97d6-55583bb39364",
94
"owner": "admin@local",
95
"cloud": "some-cloud",
96
"region": "some-region",
101
"since": "2016-04-05",
104
"admin@local": attrs{
106
"last-connection": "2015-03-20",
109
"display-name": "Bob",
111
"last-connection": "never connected",
117
s.store = jujuclienttesting.NewMemStore()
118
s.store.CurrentControllerName = "testing"
119
s.store.Controllers["testing"] = jujuclient.ControllerDetails{}
120
s.store.Accounts["testing"] = jujuclient.AccountDetails{
123
err := s.store.UpdateModel("testing", "admin@local/mymodel", jujuclient.ModelDetails{
124
testing.ModelTag.Id(),
126
c.Assert(err, jc.ErrorIsNil)
127
s.store.Models["testing"].CurrentModel = "admin@local/mymodel"
130
func (s *ShowCommandSuite) TestShow(c *gc.C) {
131
_, err := testing.RunCommand(c, model.NewShowCommandForTest(&s.fake, s.store))
132
c.Assert(err, jc.ErrorIsNil)
133
s.fake.CheckCalls(c, []gitjujutesting.StubCall{
134
{"ModelInfo", []interface{}{[]names.ModelTag{testing.ModelTag}}},
139
func (s *ShowCommandSuite) TestShowFormatYaml(c *gc.C) {
140
ctx, err := testing.RunCommand(c, model.NewShowCommandForTest(&s.fake, s.store), "--format", "yaml")
141
c.Assert(err, jc.ErrorIsNil)
142
c.Assert(testing.Stdout(ctx), jc.YAMLEquals, s.expectedOutput)
145
func (s *ShowCommandSuite) TestShowFormatJson(c *gc.C) {
146
ctx, err := testing.RunCommand(c, model.NewShowCommandForTest(&s.fake, s.store), "--format", "json")
147
c.Assert(err, jc.ErrorIsNil)
148
c.Assert(testing.Stdout(ctx), jc.JSONEquals, s.expectedOutput)
151
func (s *ShowCommandSuite) TestUnrecognizedArg(c *gc.C) {
152
_, err := testing.RunCommand(c, model.NewShowCommandForTest(&s.fake, s.store), "-m", "admin", "whoops")
153
c.Assert(err, gc.ErrorMatches, `unrecognized args: \["whoops"\]`)