-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployer_iaas_test.go
120 lines (89 loc) · 3.11 KB
/
deployer_iaas_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2023 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package bootstrap
import (
"context"
"github.com/juju/errors"
jc "github.com/juju/testing/checkers"
gomock "go.uber.org/mock/gomock"
gc "gopkg.in/check.v1"
"github.com/juju/juju/agent"
corebase "github.com/juju/juju/core/base"
"github.com/juju/juju/core/network"
state "github.com/juju/juju/state"
)
type deployerIAASSuite struct {
baseSuite
machine *MockMachine
machineGetter *MockMachineGetter
}
var _ = gc.Suite(&deployerIAASSuite{})
func (s *deployerIAASSuite) TestValidate(c *gc.C) {
defer s.setupMocks(c).Finish()
cfg := s.newConfig(c)
err := cfg.Validate()
c.Assert(err, gc.IsNil)
cfg = s.newConfig(c)
cfg.MachineGetter = nil
err = cfg.Validate()
c.Assert(err, jc.ErrorIs, errors.NotValid)
}
func (s *deployerIAASSuite) TestControllerAddress(c *gc.C) {
defer s.setupMocks(c).Finish()
s.machine.EXPECT().PublicAddress().Return(network.NewSpaceAddress("10.0.0.1"), nil)
deployer := s.newDeployer(c)
address, err := deployer.ControllerAddress(context.Background())
c.Assert(err, jc.ErrorIsNil)
c.Assert(address, gc.Equals, "10.0.0.1")
}
func (s *deployerIAASSuite) TestControllerAddressWithNoAddress(c *gc.C) {
defer s.setupMocks(c).Finish()
s.machine.EXPECT().PublicAddress().Return(network.NewSpaceAddress(""), network.NoAddressError("private"))
deployer := s.newDeployer(c)
address, err := deployer.ControllerAddress(context.Background())
c.Assert(err, jc.ErrorIsNil)
c.Assert(address, gc.Equals, "")
}
func (s *deployerIAASSuite) TestControllerAddressWithErr(c *gc.C) {
defer s.setupMocks(c).Finish()
s.machine.EXPECT().PublicAddress().Return(network.NewSpaceAddress(""), errors.Errorf("boom"))
deployer := s.newDeployer(c)
_, err := deployer.ControllerAddress(context.Background())
c.Assert(err, gc.ErrorMatches, "boom")
}
func (s *deployerIAASSuite) TestControllerCharmBase(c *gc.C) {
defer s.setupMocks(c).Finish()
s.machine.EXPECT().Base().Return(state.Base{
OS: "ubuntu",
Channel: "22.04",
})
deployer := s.newDeployer(c)
base, err := deployer.ControllerCharmBase()
c.Assert(err, jc.ErrorIsNil)
c.Assert(base, gc.Equals, corebase.MakeDefaultBase("ubuntu", "22.04"))
}
func (s *deployerIAASSuite) TestCompleteProcess(c *gc.C) {
defer s.setupMocks(c).Finish()
s.unit.EXPECT().AssignToMachineRef(s.machine).Return(nil)
deployer := s.newDeployer(c)
err := deployer.CompleteProcess(context.Background(), s.unit)
c.Assert(err, jc.ErrorIsNil)
}
func (s *deployerIAASSuite) newDeployer(c *gc.C) *IAASDeployer {
deployer, err := NewIAASDeployer(s.newConfig(c))
c.Assert(err, gc.IsNil)
return deployer
}
func (s *deployerIAASSuite) setupMocks(c *gc.C) *gomock.Controller {
ctrl := s.baseSuite.setupMocks(c)
s.machine = NewMockMachine(ctrl)
s.machineGetter = NewMockMachineGetter(ctrl)
s.machineGetter.EXPECT().Machine(agent.BootstrapControllerId).Return(s.machine, nil).AnyTimes()
return ctrl
}
func (s *deployerIAASSuite) newConfig(c *gc.C) IAASDeployerConfig {
return IAASDeployerConfig{
BaseDeployerConfig: s.baseSuite.newConfig(c),
MachineGetter: s.machineGetter,
}
}