1194
1194
c.Assert(err, ErrorMatches, "no reachable servers")
1197
func testSetPassword(c *C, getEntity func() (state.AuthEntity, error)) {
1197
func testSetPassword(c *C, getEntity func() (state.Entity, error)) {
1198
1198
e, err := getEntity()
1199
1199
c.Assert(err, IsNil)
1317
1317
c.Assert(err, IsNil)
1320
func (s *StateSuite) TestAuthEntity(c *C) {
1321
bad := []string{"", "machine", "-foo", "foo-", "---", "machine-jim", "unit-123", "unit-foo"}
1320
func (s *StateSuite) TestEntity(c *C) {
1321
bad := []string{"", "machine", "-foo", "foo-", "---", "machine-jim", "unit-123", "unit-foo", "service-", "service-foo/bar"}
1322
1322
for _, name := range bad {
1323
e, err := s.State.AuthEntity(name)
1323
e, err := s.State.Entity(name)
1324
1324
c.Check(e, IsNil)
1325
1325
c.Assert(err, ErrorMatches, `invalid entity name ".*"`)
1328
e, err := s.State.AuthEntity("machine-1234")
1328
e, err := s.State.Entity("machine-1234")
1329
1329
c.Check(e, IsNil)
1330
1330
c.Assert(err, ErrorMatches, `machine 1234 not found`)
1331
1331
c.Assert(state.IsNotFound(err), Equals, true)
1333
e, err = s.State.AuthEntity("unit-foo-654")
1333
e, err = s.State.Entity("unit-foo-654")
1334
1334
c.Check(e, IsNil)
1335
1335
c.Assert(err, ErrorMatches, `unit "foo/654" not found`)
1336
1336
c.Assert(state.IsNotFound(err), Equals, true)
1338
e, err = s.State.AuthEntity("unit-foo-bar-654")
1338
e, err = s.State.Entity("unit-foo-bar-654")
1339
1339
c.Check(e, IsNil)
1340
1340
c.Assert(err, ErrorMatches, `unit "foo-bar/654" not found`)
1341
1341
c.Assert(state.IsNotFound(err), Equals, true)
1343
e, err = s.State.AuthEntity("user-arble")
1343
e, err = s.State.Entity("user-arble")
1344
1344
c.Check(e, IsNil)
1345
1345
c.Assert(err, ErrorMatches, `user "arble" not found`)
1346
1346
c.Assert(state.IsNotFound(err), Equals, true)
1348
1348
m, err := s.State.AddMachine("series", state.JobHostUnits)
1349
1349
c.Assert(err, IsNil)
1351
e, err = s.State.AuthEntity(m.EntityName())
1351
e, err = s.State.Entity(m.EntityName())
1352
1352
c.Assert(err, IsNil)
1353
1353
c.Assert(e, FitsTypeOf, m)
1354
1354
c.Assert(e.EntityName(), Equals, m.EntityName())
1356
1356
svc, err := s.State.AddService("ser-vice1", s.AddTestingCharm(c, "dummy"))
1357
1357
c.Assert(err, IsNil)
1359
service, err := s.State.Entity(svc.EntityName())
1360
c.Assert(err, IsNil)
1361
c.Assert(service, FitsTypeOf, svc)
1362
c.Assert(service.EntityName(), Equals, svc.EntityName())
1358
1364
u, err := svc.AddUnit()
1359
1365
c.Assert(err, IsNil)
1361
e, err = s.State.AuthEntity(u.EntityName())
1367
e, err = s.State.Entity(u.EntityName())
1362
1368
c.Assert(err, IsNil)
1363
1369
c.Assert(e, FitsTypeOf, u)
1364
1370
c.Assert(e.EntityName(), Equals, u.EntityName())
1366
1372
user, err := s.State.AddUser("arble", "pass")
1367
1373
c.Assert(err, IsNil)
1369
e, err = s.State.AuthEntity(user.EntityName())
1375
e, err = s.State.Entity(user.EntityName())
1370
1376
c.Assert(err, IsNil)
1371
1377
c.Assert(e, FitsTypeOf, user)
1372
1378
c.Assert(e.EntityName(), Equals, user.EntityName())