Skip to content

Commit 58787a3

Browse files
Add charmstore.ClientConfig and use it in charmstore.NewClient().
1 parent bce92ba commit 58787a3

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

apiserver/charmrevisionupdater/testing/suite.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ func (s *CharmSuite) SetUpTest(c *gc.C) {
6868
// Patch the charm repo initializer function: it is replaced with a charm
6969
// store repo pointing to the testing server.
7070
s.jcSuite.PatchValue(&charmrevisionupdater.NewCharmStoreClient, func() *jujucharmstore.Client {
71-
return jujucharmstore.NewClient(csclient.Params{
72-
URL: s.Server.URL,
73-
})
71+
var config jujucharmstore.ClientConfig
72+
config.URL = s.Server.URL
73+
return jujucharmstore.NewClient(config)
7474
})
7575
s.charms = make(map[string]*state.Charm)
7676
}

apiserver/charmrevisionupdater/updater_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ func (s *charmVersionSuite) TestEnvironmentUUIDUsed(c *gc.C) {
167167

168168
// Point the charm repo initializer to the testing server.
169169
s.PatchValue(&charmrevisionupdater.NewCharmStoreClient, func() *charmstore.Client {
170-
return charmstore.NewClient(csclient.Params{
171-
URL: srv.URL,
172-
})
170+
var config charmstore.ClientConfig
171+
config.URL = srv.URL
172+
return charmstore.NewClient(config)
173173
})
174174

175175
result, err := s.charmrevisionupdater.UpdateLatestRevisions()

charmstore/client.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ func (base baseClient) LatestRevisions(cURLs []*charm.URL) ([]charmrepo.CharmRev
9292
return repo.Latest(cURLs...)
9393
}
9494

95+
// ClientConfig holds the configuration of a charm store client.
96+
type ClientConfig struct {
97+
charmrepo.NewCharmStoreParams
98+
}
99+
100+
func (config ClientConfig) newCSClient() *csclient.Client {
101+
return csclient.New(csclient.Params{
102+
URL: config.URL,
103+
HTTPClient: config.HTTPClient,
104+
VisitWebPage: config.VisitWebPage,
105+
})
106+
}
107+
108+
func (config ClientConfig) newCSRepo() *charmrepo.CharmStore {
109+
return charmrepo.NewCharmStore(config.NewCharmStoreParams)
110+
}
111+
95112
// TODO(ericsnow) Factor out a metadataClient type that embeds "client",
96113
// and move the "meta" field there?
97114

@@ -106,16 +123,16 @@ type Client struct {
106123

107124
// NewClient returns a Juju charm store client for the given client
108125
// config.
109-
func NewClient(config csclient.Params) *Client {
110-
base := csclient.New(config)
126+
func NewClient(config ClientConfig) *Client {
127+
base := config.newCSClient()
111128
closer := ioutil.NopCloser(nil)
112129
return WrapBaseClient(base, closer)
113130
}
114131

115132
// NewDefaultClient returns a Juju charm store client using a default
116133
// client config.
117134
func NewDefaultClient() *Client {
118-
return NewClient(csclient.Params{})
135+
return NewClient(ClientConfig{})
119136
}
120137

121138
// WrapBaseClient returns a Juju charm store client that wraps

0 commit comments

Comments
 (0)