Skip to content

Commit 5a0c028

Browse files
Add tests for deployer add-charmhub charm
1 parent 22f8ea4 commit 5a0c028

File tree

6 files changed

+489
-39
lines changed

6 files changed

+489
-39
lines changed

internal/bootstrap/bootstrap_mock_test.go

Lines changed: 110 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/bootstrap/charm_mock_test.go

Lines changed: 153 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/bootstrap/deployer.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ type Application interface {
120120
// Charm is the interface that is used to get information about a charm.
121121
type Charm interface {
122122
Meta() *charm.Meta
123+
Manifest() *charm.Manifest
124+
URL() string
123125
}
124126

125127
// Model is the interface that is used to get information about a model.
@@ -270,7 +272,7 @@ func (b *baseDeployer) DeployLocalCharm(ctx context.Context, arch string, base c
270272
func (b *baseDeployer) DeployCharmhubCharm(ctx context.Context, arch string, base corebase.Base) (string, *corecharm.Origin, error) {
271273
model, err := b.stateBackend.Model()
272274
if err != nil {
273-
return "", nil, err
275+
return "", nil, errors.Trace(err)
274276
}
275277

276278
charmRepo, err := b.newCharmRepo(services.CharmRepoFactoryConfig{
@@ -280,7 +282,7 @@ func (b *baseDeployer) DeployCharmhubCharm(ctx context.Context, arch string, bas
280282
ModelBackend: model,
281283
})
282284
if err != nil {
283-
return "", nil, err
285+
return "", nil, errors.Trace(err)
284286
}
285287

286288
var curl *charm.URL
@@ -290,10 +292,11 @@ func (b *baseDeployer) DeployCharmhubCharm(ctx context.Context, arch string, bas
290292
curl = charm.MustParseURL(b.charmhubURL)
291293
}
292294
if err != nil {
293-
return "", nil, err
295+
return "", nil, errors.Trace(err)
294296
}
295297
origin := corecharm.Origin{
296298
Source: corecharm.CharmHub,
299+
Type: "charm",
297300
Channel: &b.channel,
298301
Platform: corecharm.Platform{
299302
Architecture: arch,
@@ -325,11 +328,11 @@ func (b *baseDeployer) DeployCharmhubCharm(ctx context.Context, arch string, bas
325328
ModelBackend: model,
326329
})
327330
if err != nil {
328-
return "", nil, err
331+
return "", nil, errors.Trace(err)
329332
}
330333
resOrigin, err := charmDownloader.DownloadAndStore(ctx, curl, origin, false)
331334
if err != nil {
332-
return "", nil, err
335+
return "", nil, errors.Trace(err)
333336
}
334337

335338
b.logger.Debugf("Successfully deployed charmhub Juju controller charm")
@@ -339,7 +342,7 @@ func (b *baseDeployer) DeployCharmhubCharm(ctx context.Context, arch string, bas
339342

340343
// AddControllerApplication adds the controller application.
341344
func (b *baseDeployer) AddControllerApplication(ctx context.Context, curl string, origin corecharm.Origin, controllerAddress string) (Unit, error) {
342-
_, err := b.stateBackend.Charm(curl)
345+
ch, err := b.stateBackend.Charm(curl)
343346
if err != nil {
344347
return nil, errors.Trace(err)
345348
}
@@ -368,8 +371,8 @@ func (b *baseDeployer) AddControllerApplication(ctx context.Context, curl string
368371
}
369372

370373
app, err := b.stateBackend.AddApplication(state.AddApplicationArgs{
371-
Name: bootstrap.ControllerApplicationName,
372-
//Charm: ch,
374+
Name: bootstrap.ControllerApplicationName,
375+
Charm: ch,
373376
CharmOrigin: stateOrigin,
374377
CharmConfig: cfg,
375378
Constraints: b.constraints,

0 commit comments

Comments
 (0)