Skip to content

Commit

Permalink
Resource lister refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiamac committed Jul 28, 2017
1 parent 7effc9c commit 1e0ff6d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
4 changes: 0 additions & 4 deletions cmd/juju/resource/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@ func UploadCommandService(c *UploadCommand) string {
}

var FormatServiceResources = formatServiceResources

func SetResourceLister(c modelcmd.Command, lister ResourceLister) {
modelcmd.InnerCommand(c).(*ListCharmResourcesCommand).resourceLister = lister
}
7 changes: 5 additions & 2 deletions cmd/juju/resource/list_charm_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ type ListCharmResourcesCommand struct {

// NewListCharmResourcesCommand returns a new command that lists resources defined
// by a charm.
func NewListCharmResourcesCommand() modelcmd.ModelCommand {
func NewListCharmResourcesCommand(resourceLister ResourceLister) modelcmd.ModelCommand {
var c ListCharmResourcesCommand
c.resourceLister = &c
if resourceLister == nil {
resourceLister = &c
}
c.resourceLister = resourceLister
return modelcmd.Wrap(&c)
}

Expand Down
12 changes: 4 additions & 8 deletions cmd/juju/resource/list_charm_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ func (s *ListCharmSuite) TestOkay(c *gc.C) {
resources[0].Revision = 2
s.client.ReturnListResources = [][]charmresource.Resource{resources}

command := resourcecmd.NewListCharmResourcesCommand()
resourcecmd.SetResourceLister(command, s.client)
command := resourcecmd.NewListCharmResourcesCommand(s.client)
code, stdout, stderr := runCmd(c, command, "cs:a-charm")
c.Check(code, gc.Equals, 0)

Expand All @@ -95,8 +94,7 @@ music 1
func (s *ListCharmSuite) TestNoResources(c *gc.C) {
s.client.ReturnListResources = [][]charmresource.Resource{{}}

command := resourcecmd.NewListCharmResourcesCommand()
resourcecmd.SetResourceLister(command, s.client)
command := resourcecmd.NewListCharmResourcesCommand(s.client)
code, stdout, stderr := runCmd(c, command, "cs:a-charm")
c.Check(code, gc.Equals, 0)

Expand Down Expand Up @@ -167,8 +165,7 @@ music 1
}
for format, expected := range formats {
c.Logf("checking format %q", format)
command := resourcecmd.NewListCharmResourcesCommand()
resourcecmd.SetResourceLister(command, s.client)
command := resourcecmd.NewListCharmResourcesCommand(s.client)
args := []string{
"--format", format,
"cs:a-charm",
Expand All @@ -191,8 +188,7 @@ func (s *ListCharmSuite) TestChannelFlag(c *gc.C) {
charmRes(c, "music", ".mp3", "mp3 of your backing vocals", string(fp2.Bytes())),
}
s.client.ReturnListResources = [][]charmresource.Resource{resources}
command := resourcecmd.NewListCharmResourcesCommand()
resourcecmd.SetResourceLister(command, s.client)
command := resourcecmd.NewListCharmResourcesCommand(s.client)

code, _, stderr := runCmd(c, command,
"--channel", "development",
Expand Down
2 changes: 1 addition & 1 deletion component/all/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r resources) registerPublicCommands() {
return
}

charmcmd.RegisterSubCommand(resourcecmd.NewListCharmResourcesCommand())
charmcmd.RegisterSubCommand(resourcecmd.NewListCharmResourcesCommand(nil))

commands.RegisterEnvCommand(func() modelcmd.ModelCommand {
return resourcecmd.NewUploadCommand(resourcecmd.UploadDeps{
Expand Down

0 comments on commit 1e0ff6d

Please sign in to comment.