Skip to content

Commit

Permalink
charm.Channel -> csparams.Channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Apr 8, 2016
1 parent 0a4b338 commit 6f1a83e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
7 changes: 5 additions & 2 deletions charmstore/charmid.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package charmstore

import "gopkg.in/juju/charm.v6-unstable"
import (
"gopkg.in/juju/charm.v6-unstable"
csparams "gopkg.in/juju/charmrepo.v2-unstable/csclient/params"
)

// CharmID is a type that encapsulates all the data required to interact with a
// unique charm from the charmstore.
Expand All @@ -9,5 +12,5 @@ type CharmID struct {
URL *charm.URL

// Channel is the channel in which the charm was published.
Channel charm.Channel
Channel csparams.Channel
}
28 changes: 14 additions & 14 deletions charmstore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
charmresource "gopkg.in/juju/charm.v6-unstable/resource"
"gopkg.in/juju/charmrepo.v2-unstable"
"gopkg.in/juju/charmrepo.v2-unstable/csclient"
"gopkg.in/juju/charmrepo.v2-unstable/csclient/params"
csparams "gopkg.in/juju/charmrepo.v2-unstable/csclient/params"
"gopkg.in/macaroon-bakery.v1/httpbakery"
)

Expand Down Expand Up @@ -84,7 +84,7 @@ func (c Client) GetResource(cURL *charm.URL, resourceName string, revision int)
if err != nil {
return charmresource.Resource{}, nil, errors.Trace(err)
}
res, err = params.API2Resource(meta)
res, err = csparams.API2Resource(meta)
if err != nil {
return charmresource.Resource{}, nil, errors.Trace(err)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (c Client) ResourceInfo(cURL *charm.URL, resourceName string, revision int)
if err != nil {
return charmresource.Resource{}, errors.Trace(err)
}
res, err := params.API2Resource(meta)
res, err := csparams.API2Resource(meta)
if err != nil {
return charmresource.Resource{}, errors.Trace(err)
}
Expand All @@ -137,7 +137,7 @@ func (c Client) ListResources(charms []CharmID) ([][]charmresource.Resource, err
}
list := make([]charmresource.Resource, len(resources))
for j, res := range resources {
resource, err := params.API2Resource(res)
resource, err := csparams.API2Resource(res)
if err != nil {
return nil, errors.Annotatef(err, "got bad data from server for resource %q", res.Name)
}
Expand All @@ -153,10 +153,10 @@ func (c Client) ListResources(charms []CharmID) ([][]charmresource.Resource, err
// csWrapper is a type that abstracts away the low-level implementation details
// of the charmstore client.
type csWrapper interface {
Latest(channel charm.Channel, ids []*charm.URL, headers map[string]string) ([]charmrepo.CharmRevision, error)
ListResources(channel charm.Channel, ids []*charm.URL) (map[string][]params.Resource, error)
Latest(channel csparams.Channel, ids []*charm.URL, headers map[string]string) ([]charmrepo.CharmRevision, error)
ListResources(channel csparams.Channel, ids []*charm.URL) (map[string][]csparams.Resource, error)
GetResource(id *charm.URL, name string, revision int) (csclient.ResourceData, error)
ResourceInfo(id *charm.URL, name string, revision int) (params.Resource, error)
ResourceInfo(id *charm.URL, name string, revision int) (csparams.Resource, error)
}

// csclientImpl is an implementation of csWrapper that uses the charmstore client.
Expand All @@ -167,15 +167,15 @@ type csclientImpl struct {
}

// Latest gets the latest CharmRevisions for the charm URLs on the channel.
func (c csclientImpl) Latest(channel charm.Channel, ids []*charm.URL, metadata map[string]string) ([]charmrepo.CharmRevision, error) {
repo := charmrepo.NewCharmStoreFromClient(c.client.WithChannel(params.Channel(channel)))
func (c csclientImpl) Latest(channel csparams.Channel, ids []*charm.URL, metadata map[string]string) ([]charmrepo.CharmRevision, error) {
repo := charmrepo.NewCharmStoreFromClient(c.client.WithChannel(csparams.Channel(channel)))
repo = repo.WithJujuAttrs(metadata)
return repo.Latest(ids...)
}

// Latest gets the latest resources for the charm URLs on the channel.
func (c csclientImpl) ListResources(channel charm.Channel, ids []*charm.URL) (map[string][]params.Resource, error) {
client := c.client.WithChannel(params.Channel(channel))
func (c csclientImpl) ListResources(channel csparams.Channel, ids []*charm.URL) (map[string][]csparams.Resource, error) {
client := c.client.WithChannel(csparams.Channel(channel))
return client.ListResources(ids)
}

Expand All @@ -185,7 +185,7 @@ func (c csclientImpl) GetResource(id *charm.URL, name string, revision int) (csc
}

// ResourceInfo gets the full metadata for the revisioned resource.
func (c csclientImpl) ResourceInfo(id *charm.URL, name string, revision int) (params.Resource, error) {
func (c csclientImpl) ResourceInfo(id *charm.URL, name string, revision int) (csparams.Resource, error) {
return c.client.ResourceMeta(id, name, revision)
}

Expand All @@ -200,8 +200,8 @@ type charmRequest struct {
// slice of charms for that channel, and a corresponding slice of the index of
// each charm in the orignal slice from which they were collated, so the results
// can be sorted into the original order.
func collate(charms []CharmID) map[charm.Channel]charmRequest {
results := map[charm.Channel]charmRequest{}
func collate(charms []CharmID) map[csparams.Channel]charmRequest {
results := map[csparams.Channel]charmRequest{}
for i, c := range charms {
request := results[c.Channel]
request.ids = append(request.ids, c.URL)
Expand Down
10 changes: 5 additions & 5 deletions charmstore/client_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *InternalClientSuite) TestCollate(c *gc.C) {
{URL: bat, Channel: "stable"},
}
output := collate(input)
c.Assert(output, gc.DeepEquals, map[charm.Channel]charmRequest{
c.Assert(output, gc.DeepEquals, map[params.Channel]charmRequest{
"stable": charmRequest{
ids: []*charm.URL{foo, bat},
indices: []int{0, 3},
Expand Down Expand Up @@ -75,8 +75,8 @@ func (s *InternalClientSuite) TestLatestRevisions(c *gc.C) {
}}, nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(ret, gc.DeepEquals, append(s.lowLevel.ReturnLatestStable, s.lowLevel.ReturnLatestDev...))
s.lowLevel.stableStub.CheckCall(c, 0, "Latest", charm.Channel("stable"), []*charm.URL{foo}, map[string]string(nil))
s.lowLevel.devStub.CheckCall(c, 0, "Latest", charm.Channel("development"), []*charm.URL{bar}, map[string]string(nil))
s.lowLevel.stableStub.CheckCall(c, 0, "Latest", params.StableChannel, []*charm.URL{foo}, map[string]string(nil))
s.lowLevel.devStub.CheckCall(c, 0, "Latest", params.DevelopmentChannel, []*charm.URL{bar}, map[string]string(nil))
}

func (s *InternalClientSuite) TestListResources(c *gc.C) {
Expand Down Expand Up @@ -133,6 +133,6 @@ func (s *InternalClientSuite) TestListResources(c *gc.C) {
{stableOut},
{devOut},
})
s.lowLevel.stableStub.CheckCall(c, 0, "ListResources", charm.Channel("stable"), []*charm.URL{foo})
s.lowLevel.devStub.CheckCall(c, 0, "ListResources", charm.Channel("development"), []*charm.URL{bar})
s.lowLevel.stableStub.CheckCall(c, 0, "ListResources", params.StableChannel, []*charm.URL{foo})
s.lowLevel.devStub.CheckCall(c, 0, "ListResources", params.DevelopmentChannel, []*charm.URL{bar})
}
4 changes: 2 additions & 2 deletions charmstore/latest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func (s *LatestCharmInfoSuite) TestSuccess(c *gc.C) {
expectedIds := []*charm.URL{spam, eggs, ham}

s.lowLevel.stableStub.CheckCallNames(c, "Latest", "ListResources")
s.lowLevel.stableStub.CheckCall(c, 0, "Latest", charm.Channel("stable"), expectedIds, map[string]string{"environment_uuid": uuid})
s.lowLevel.stableStub.CheckCall(c, 1, "ListResources", charm.Channel("stable"), expectedIds)
s.lowLevel.stableStub.CheckCall(c, 0, "Latest", params.StableChannel, expectedIds, map[string]string{"environment_uuid": uuid})
s.lowLevel.stableStub.CheckCall(c, 1, "ListResources", params.StableChannel, expectedIds)

expectedRes, err := params.API2Resource(fakeRes)
c.Assert(err, jc.ErrorIsNil)
Expand Down
4 changes: 2 additions & 2 deletions charmstore/stub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type fakeWrapper struct {
ReturnResourceInfo params.Resource
}

func (f *fakeWrapper) Latest(channel charm.Channel, ids []*charm.URL, headers map[string]string) ([]charmrepo.CharmRevision, error) {
func (f *fakeWrapper) Latest(channel params.Channel, ids []*charm.URL, headers map[string]string) ([]charmrepo.CharmRevision, error) {
if channel == "stable" {
f.stableStub.AddCall("Latest", channel, ids, headers)
return f.ReturnLatestStable, nil
Expand All @@ -43,7 +43,7 @@ func (f *fakeWrapper) Latest(channel charm.Channel, ids []*charm.URL, headers ma
return f.ReturnLatestDev, nil
}

func (f *fakeWrapper) ListResources(channel charm.Channel, ids []*charm.URL) (map[string][]params.Resource, error) {
func (f *fakeWrapper) ListResources(channel params.Channel, ids []*charm.URL) (map[string][]params.Resource, error) {
if channel == "stable" {
f.stableStub.AddCall("ListResources", channel, ids)
return f.ReturnListResourcesStable, nil
Expand Down
3 changes: 2 additions & 1 deletion resource/cmd/list_charm_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/juju/errors"
"gopkg.in/juju/charm.v6-unstable"
charmresource "gopkg.in/juju/charm.v6-unstable/resource"
csparams "gopkg.in/juju/charmrepo.v2-unstable/csclient/params"
"launchpad.net/gnuflag"

"github.com/juju/juju/charmstore"
Expand Down Expand Up @@ -121,7 +122,7 @@ func (c *ListCharmResourcesCommand) Run(ctx *cmd.Context) error {

charms := make([]charmstore.CharmID, len(charmURLs))
for i, id := range charmURLs {
charms[i] = charmstore.CharmID{URL: id, Channel: charm.Channel(c.channel)}
charms[i] = charmstore.CharmID{URL: id, Channel: csparams.Channel(c.channel)}
}

resources, err := apiclient.ListResources(charms)
Expand Down

0 comments on commit 6f1a83e

Please sign in to comment.