14
14
"github.com/juju/juju/apiserver/common"
15
15
"github.com/juju/juju/apiserver/params"
16
16
apiservertesting "github.com/juju/juju/apiserver/testing"
17
"github.com/juju/juju/cloud"
17
18
"github.com/juju/juju/instance"
18
19
jujutesting "github.com/juju/juju/juju/testing"
19
20
"github.com/juju/juju/state"
20
21
"github.com/juju/juju/state/multiwatcher"
22
statetesting "github.com/juju/juju/state/testing"
21
23
coretesting "github.com/juju/juju/testing"
238
240
c.Assert(err, jc.ErrorIsNil)
239
241
c.Assert(rFlag, jc.IsFalse)
244
func (s *agentSuite) TestWatchCredentials(c *gc.C) {
245
authorizer := apiservertesting.FakeAuthorizer{
246
Tag: names.NewMachineTag("0"),
247
EnvironManager: true,
249
api, err := agent.NewAgentAPIV2(s.State, s.resources, authorizer)
250
c.Assert(err, jc.ErrorIsNil)
251
tag := names.NewCloudCredentialTag("dummy/fred/default")
252
result, err := api.WatchCredentials(params.Entities{Entities: []params.Entity{{Tag: tag.String()}}})
253
c.Assert(err, jc.ErrorIsNil)
254
c.Assert(result, jc.DeepEquals, params.NotifyWatchResults{Results: []params.NotifyWatchResult{{"1", nil}}})
255
c.Assert(s.resources.Count(), gc.Equals, 1)
257
w := s.resources.Get("1")
258
defer statetesting.AssertStop(c, w)
260
// Check that the Watch has consumed the initial events ("returned" in the Watch call)
261
wc := statetesting.NewNotifyWatcherC(c, s.State, w.(state.NotifyWatcher))
264
s.State.UpdateCloudCredential(tag, cloud.NewCredential(cloud.UserPassAuthType, nil))
268
func (s *agentSuite) TestWatchAuthError(c *gc.C) {
269
authorizer := apiservertesting.FakeAuthorizer{
270
Tag: names.NewMachineTag("1"),
271
EnvironManager: false,
273
api, err := agent.NewAgentAPIV2(s.State, s.resources, authorizer)
274
c.Assert(err, jc.ErrorIsNil)
275
_, err = api.WatchCredentials(params.Entities{})
276
c.Assert(err, gc.ErrorMatches, "permission denied")
277
c.Assert(s.resources.Count(), gc.Equals, 0)