Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/jujuPublic

Commite475efd

Browse files
committed
test(deployapplication): add simple tests for DeployApplication
1 parent6950b52 commite475efd

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright 2024 Canonical Ltd.
2+
// Licensed under the AGPLv3, see LICENCE file for details.
3+
4+
package application
5+
6+
import (
7+
"testing"
8+
9+
"github.com/juju/clock"
10+
"github.com/juju/tc"
11+
gomock"go.uber.org/mock/gomock"
12+
13+
"github.com/juju/juju/core/application"
14+
"github.com/juju/juju/core/model"
15+
"github.com/juju/juju/internal/charm"
16+
)
17+
18+
typedeploySuitestruct {
19+
baseSuite
20+
}
21+
22+
funcTestDeploySuite(t*testing.T) {
23+
tc.Run(t,&deploySuite{})
24+
}
25+
26+
func (s*deploySuite)TestDeployIAASApplication(c*tc.C) {
27+
defers.setupMocks(c).Finish()
28+
29+
// Arrange
30+
args:=DeployApplicationParams{
31+
Charm:&domainCharm{
32+
charm:s.charm,
33+
},
34+
ApplicationName:"myapp",
35+
}
36+
s.charm.EXPECT().
37+
Meta().Return(&charm.Meta{}).AnyTimes()
38+
s.applicationService.EXPECT().
39+
CreateIAASApplication(gomock.Any(),gomock.Any(),gomock.Any(),gomock.Any(),gomock.Any()).
40+
Return(tc.Must(c,application.NewUUID),nil)
41+
42+
// Act
43+
err:=DeployApplication(c.Context(),
44+
model.IAAS,
45+
s.applicationService,
46+
s.storageService,
47+
s.objectStore,
48+
args,
49+
nil,
50+
clock.WallClock,
51+
)
52+
// Assert
53+
c.Assert(err,tc.IsNil)
54+
}
55+
56+
func (s*deploySuite)TestDeployCAASApplication(c*tc.C) {
57+
defers.setupMocks(c).Finish()
58+
59+
// Arrange
60+
args:=DeployApplicationParams{
61+
Charm:&domainCharm{
62+
charm:s.charm,
63+
},
64+
ApplicationName:"myapp-caas",
65+
}
66+
s.charm.EXPECT().
67+
Meta().Return(&charm.Meta{}).AnyTimes()
68+
69+
s.charm.EXPECT().
70+
Manifest().Return(&charm.Manifest{
71+
Bases: []charm.Base{
72+
{
73+
Name:"ubuntu",
74+
Channel: charm.Channel{
75+
Risk:charm.Stable,
76+
},
77+
Architectures: []string{"amd64"},
78+
},
79+
},
80+
}).AnyTimes()
81+
s.applicationService.EXPECT().
82+
CreateCAASApplication(gomock.Any(),gomock.Any(),gomock.Any(),gomock.Any(),gomock.Any()).
83+
Return(tc.Must(c,application.NewUUID),nil)
84+
85+
// Act
86+
err:=DeployApplication(c.Context(),
87+
model.CAAS,
88+
s.applicationService,
89+
s.storageService,
90+
s.objectStore,
91+
args,
92+
nil,
93+
clock.WallClock,
94+
)
95+
// Assert
96+
c.Assert(err,tc.IsNil)
97+
}

‎apiserver/facades/client/application/package_test.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type baseSuite struct {
5151
resourceService*MockResourceService
5252
statusService*MockStatusService
5353
storageService*MockStorageService
54+
charm*MockCharm
5455

5556
charmRepository*MockRepository
5657
charmRepositoryFactory*MockRepositoryFactory
@@ -92,6 +93,8 @@ func (s *baseSuite) setupMocks(c *tc.C) *gomock.Controller {
9293
s.controllerUUID=tc.Must(c,uuid.NewUUID).String()
9394
s.modelUUID=modeltesting.GenModelUUID(c)
9495

96+
s.charm=NewMockCharm(ctrl)
97+
9598
returnctrl
9699
}
97100

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp