~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/controller/kill_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
        c.Assert(err, gc.ErrorMatches, `controller foo not found`)
62
62
}
63
63
 
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")
67
 
}
68
 
 
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)
75
70
}
76
71
 
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)
83
78
}
84
79
 
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",
 
86
        )
 
87
        checkControllerExistsInStore(c, "test3", s.store)
91
88
}
92
89
 
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",
 
95
        )
 
96
        checkControllerExistsInStore(c, "test3", s.store)
98
97
}
99
98
 
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)
107
106
}
108
107
 
109
108
func (s *KillSuite) TestKillCommandConfirmation(c *gc.C) {
123
122
                c.Fatalf("command took too long")
124
123
        }
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)
127
126
}
128
127
 
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)
133
132
}
134
133
 
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)
143
142
}
144
143
 
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)
162
161
}