Skip to content

Commit fe5bd94

Browse files
committed
Wrap command and fix tests.
1 parent 41c0227 commit fe5bd94

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

resource/cmd/export_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package cmd
22

3-
func ListCharmResourcesCommandChannel(c *ListCharmResourcesCommand) string {
4-
return c.channel
3+
import (
4+
"github.com/juju/juju/cmd/modelcmd"
5+
)
6+
7+
func ListCharmResourcesCommandChannel(c modelcmd.Command) string {
8+
return modelcmd.InnerCommand(c).(*ListCharmResourcesCommand).channel
59
}
610

711
func ShowServiceCommandTarget(c *ShowServiceCommand) string {
@@ -19,3 +23,7 @@ func UploadCommandService(c *UploadCommand) string {
1923
}
2024

2125
var FormatServiceResources = formatServiceResources
26+
27+
func SetResourceLister(c modelcmd.Command, lister ResourceLister) {
28+
modelcmd.InnerCommand(c).(*ListCharmResourcesCommand).resourceLister = lister
29+
}

resource/cmd/list_charm_resources.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ type ResourceLister interface {
2424
type ListCharmResourcesCommand struct {
2525
modelcmd.ModelCommandBase
2626

27-
// ResourceLister is called by Run to list charm resources. The
28-
// default implementation uses juju/juju/charmstore.Client, but
29-
// it may be set to mock out the call to that method.
30-
ResourceLister ResourceLister
27+
// resourceLister is called by Run to list charm resources and
28+
// uses juju/juju/charmstore.Client.
29+
resourceLister ResourceLister
3130

3231
out cmd.Output
3332
channel string
@@ -36,10 +35,10 @@ type ListCharmResourcesCommand struct {
3635

3736
// NewListCharmResourcesCommand returns a new command that lists resources defined
3837
// by a charm.
39-
func NewListCharmResourcesCommand() *ListCharmResourcesCommand {
38+
func NewListCharmResourcesCommand() modelcmd.ModelCommand {
4039
var c ListCharmResourcesCommand
41-
c.ResourceLister = &c
42-
return &c
40+
c.resourceLister = &c
41+
return modelcmd.Wrap(&c)
4342
}
4443

4544
var listCharmResourcesDoc = `
@@ -109,7 +108,7 @@ func (c *ListCharmResourcesCommand) Run(ctx *cmd.Context) error {
109108
charms[i] = charmstore.CharmID{URL: id, Channel: csparams.Channel(c.channel)}
110109
}
111110

112-
resources, err := c.ResourceLister.ListResources(charms)
111+
resources, err := c.resourceLister.ListResources(charms)
113112
if err != nil {
114113
return errors.Trace(err)
115114
}

resource/cmd/list_charm_resources_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (s *ListCharmSuite) TestOkay(c *gc.C) {
7070
s.client.ReturnListResources = [][]charmresource.Resource{resources}
7171

7272
command := resourcecmd.NewListCharmResourcesCommand()
73-
command.ResourceLister = s.client
73+
resourcecmd.SetResourceLister(command, s.client)
7474
code, stdout, stderr := runCmd(c, command, "cs:a-charm")
7575
c.Check(code, gc.Equals, 0)
7676

@@ -96,7 +96,7 @@ func (s *ListCharmSuite) TestNoResources(c *gc.C) {
9696
s.client.ReturnListResources = [][]charmresource.Resource{{}}
9797

9898
command := resourcecmd.NewListCharmResourcesCommand()
99-
command.ResourceLister = s.client
99+
resourcecmd.SetResourceLister(command, s.client)
100100
code, stdout, stderr := runCmd(c, command, "cs:a-charm")
101101
c.Check(code, gc.Equals, 0)
102102

@@ -168,7 +168,7 @@ music 1
168168
for format, expected := range formats {
169169
c.Logf("checking format %q", format)
170170
command := resourcecmd.NewListCharmResourcesCommand()
171-
command.ResourceLister = s.client
171+
resourcecmd.SetResourceLister(command, s.client)
172172
args := []string{
173173
"--format", format,
174174
"cs:a-charm",
@@ -192,7 +192,7 @@ func (s *ListCharmSuite) TestChannelFlag(c *gc.C) {
192192
}
193193
s.client.ReturnListResources = [][]charmresource.Resource{resources}
194194
command := resourcecmd.NewListCharmResourcesCommand()
195-
command.ResourceLister = s.client
195+
resourcecmd.SetResourceLister(command, s.client)
196196

197197
code, _, stderr := runCmd(c, command,
198198
"--channel", "development",

0 commit comments

Comments
 (0)