61
61
c.Assert(err, gc.ErrorMatches, `controller foo not found`)
64
func (s *KillSuite) TestKillNonControllerEnvFails(c *gc.C) {
65
_, err := s.runKillCommand(c, "test2")
66
c.Assert(err, gc.ErrorMatches, "\"test2\" is not a controller; use juju destroy-model to destroy it")
69
64
func (s *KillSuite) TestKillCannotConnectToAPISucceeds(c *gc.C) {
70
65
s.apierror = errors.New("connection refused")
71
66
ctx, err := s.runKillCommand(c, "local.test1", "-y")
72
67
c.Assert(err, jc.ErrorIsNil)
73
68
c.Check(testing.Stderr(ctx), jc.Contains, "Unable to open API: connection refused")
74
checkControllerRemovedFromStore(c, "local.test1:test1", s.legacyStore)
69
checkControllerRemovedFromStore(c, "local.test1", s.store)
77
72
func (s *KillSuite) TestKillWithAPIConnection(c *gc.C) {
79
74
c.Assert(err, jc.ErrorIsNil)
80
75
c.Assert(s.api.destroyAll, jc.IsTrue)
81
76
c.Assert(s.clientapi.destroycalled, jc.IsFalse)
82
checkControllerRemovedFromStore(c, "local.test1:test1", s.legacyStore)
77
checkControllerRemovedFromStore(c, "local.test1", s.store)
85
80
func (s *KillSuite) TestKillEnvironmentGetFailsWithoutAPIConnection(c *gc.C) {
86
81
s.apierror = errors.New("connection refused")
87
82
s.api.err = errors.NotFoundf(`controller "test3"`)
88
83
_, err := s.runKillCommand(c, "test3", "-y")
89
c.Assert(err, gc.ErrorMatches, "cannot obtain bootstrap information: unable to get bootstrap information from API")
90
checkControllerExistsInStore(c, "test3:test3", s.legacyStore)
84
c.Assert(err, gc.ErrorMatches,
85
"getting controller environ: unable to get bootstrap information from client store or API",
87
checkControllerExistsInStore(c, "test3", s.store)
93
90
func (s *KillSuite) TestKillEnvironmentGetFailsWithAPIConnection(c *gc.C) {
94
91
s.api.err = errors.NotFoundf(`controller "test3"`)
95
92
_, err := s.runKillCommand(c, "test3", "-y")
96
c.Assert(err, gc.ErrorMatches, "cannot obtain bootstrap information: controller \"test3\" not found")
97
checkControllerExistsInStore(c, "test3:test3", s.legacyStore)
93
c.Assert(err, gc.ErrorMatches,
94
"getting controller environ: getting bootstrap config from API: controller \"test3\" not found",
96
checkControllerExistsInStore(c, "test3", s.store)
100
99
func (s *KillSuite) TestKillDestroysControllerWithAPIError(c *gc.C) {
103
102
c.Assert(err, jc.ErrorIsNil)
104
103
c.Check(testing.Stderr(ctx), jc.Contains, "Unable to destroy controller through the API: some destroy error. Destroying through provider.")
105
104
c.Assert(s.api.destroyAll, jc.IsTrue)
106
checkControllerRemovedFromStore(c, "local.test1:test1", s.legacyStore)
105
checkControllerRemovedFromStore(c, "local.test1", s.store)
109
108
func (s *KillSuite) TestKillCommandConfirmation(c *gc.C) {
123
122
c.Fatalf("command took too long")
125
124
c.Check(testing.Stdout(ctx), gc.Matches, "WARNING!.*local.test1(.|\n)*")
126
checkControllerExistsInStore(c, "local.test1:test1", s.legacyStore)
125
checkControllerExistsInStore(c, "local.test1", s.store)
129
128
func (s *KillSuite) TestKillCommandControllerAlias(c *gc.C) {
130
129
_, err := testing.RunCommand(c, s.newKillCommand(), "local.test1", "-y")
131
130
c.Assert(err, jc.ErrorIsNil)
132
checkControllerRemovedFromStore(c, "local.test1:test1", s.legacyStore)
131
checkControllerRemovedFromStore(c, "local.test1:test1", s.store)
135
134
func (s *KillSuite) TestKillAPIPermErrFails(c *gc.C) {
139
138
cmd := controller.NewKillCommandForTest(nil, nil, s.store, nil, clock.WallClock, modelcmd.OpenFunc(testDialer))
140
139
_, err := testing.RunCommand(c, cmd, "local.test1", "-y")
141
140
c.Assert(err, gc.ErrorMatches, "cannot destroy controller: permission denied")
142
checkControllerExistsInStore(c, "local.test1:test1", s.legacyStore)
141
checkControllerExistsInStore(c, "local.test1", s.store)
145
144
func (s *KillSuite) TestKillEarlyAPIConnectionTimeout(c *gc.C) {
156
155
ctx, err := testing.RunCommand(c, cmd, "local.test1", "-y")
157
156
c.Check(err, jc.ErrorIsNil)
158
157
c.Check(testing.Stderr(ctx), jc.Contains, "Unable to open API: open connection timed out")
159
checkControllerRemovedFromStore(c, "local.test1:test1", s.legacyStore)
158
checkControllerRemovedFromStore(c, "local.test1", s.store)
160
159
// Check that we were actually told to wait for 10s.
161
160
c.Assert(clock.wait, gc.Equals, 10*time.Second)