~rogpeppe/juju-core/256-more-status

« back to all changes in this revision

Viewing changes to state/state_test.go

  • Committer: Francesco Banconi
  • Date: 2013-03-08 21:36:52 UTC
  • mfrom: (956.7.22 annapi)
  • Revision ID: francesco.banconi@canonical.com-20130308213652-27h2uyu25olayaj7
Annotations API functionality

Annotations are now exposed through the API via 'GetAnnotations' and 
'SetAnnotation'.  These allow a user to set an annotation on an Entity (service,
'unit', 'machine', with environment coming in a future branch), and retrieve
all annotations on an entity.  Tests were added around the added functionality.
Note that now the service is an Entity, as suggested by Roger.

R=dimitern, rog
CC=
https://codereview.appspot.com/7526043

Show diffs side-by-side

added added

removed removed

Lines of Context:
1194
1194
        c.Assert(err, ErrorMatches, "no reachable servers")
1195
1195
}
1196
1196
 
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)
1200
1200
 
1317
1317
        c.Assert(err, IsNil)
1318
1318
}
1319
1319
 
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 ".*"`)
1326
1326
        }
1327
1327
 
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)
1332
1332
 
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)
1337
1337
 
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)
1342
1342
 
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)
1350
1350
 
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())
1355
1355
 
1356
1356
        svc, err := s.State.AddService("ser-vice1", s.AddTestingCharm(c, "dummy"))
1357
1357
        c.Assert(err, IsNil)
 
1358
 
 
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())
 
1363
 
1358
1364
        u, err := svc.AddUnit()
1359
1365
        c.Assert(err, IsNil)
1360
1366
 
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)
1368
1374
 
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())