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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/agent/agent_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
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"
22
24
)
23
25
 
238
240
        c.Assert(err, jc.ErrorIsNil)
239
241
        c.Assert(rFlag, jc.IsFalse)
240
242
}
 
243
 
 
244
func (s *agentSuite) TestWatchCredentials(c *gc.C) {
 
245
        authorizer := apiservertesting.FakeAuthorizer{
 
246
                Tag:            names.NewMachineTag("0"),
 
247
                EnvironManager: true,
 
248
        }
 
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)
 
256
 
 
257
        w := s.resources.Get("1")
 
258
        defer statetesting.AssertStop(c, w)
 
259
 
 
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))
 
262
        wc.AssertNoChange()
 
263
 
 
264
        s.State.UpdateCloudCredential(tag, cloud.NewCredential(cloud.UserPassAuthType, nil))
 
265
        wc.AssertOneChange()
 
266
}
 
267
 
 
268
func (s *agentSuite) TestWatchAuthError(c *gc.C) {
 
269
        authorizer := apiservertesting.FakeAuthorizer{
 
270
                Tag:            names.NewMachineTag("1"),
 
271
                EnvironManager: false,
 
272
        }
 
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)
 
278
}