~jameinel/juju-core/api-registry-tracks-type

« back to all changes in this revision

Viewing changes to state/state_test.go

  • Committer: Andrew Wilkins
  • Date: 2013-12-04 05:23:29 UTC
  • mto: This revision was merged to the branch mainline in revision 2131.
  • Revision ID: andrew.wilkins@canonical.com-20131204052329-i8z40nohlruppuf8
Permit environment-tag with environment name or UUID

And assorted review followups

Show diffs side-by-side

added added

removed removed

Lines of Context:
207
207
        check(m[1], "1", "blahblah", allJobs)
208
208
}
209
209
 
210
 
func (s *StateSuite) TestAddMachinesEnvironmentLife(c *gc.C) {
 
210
func (s *StateSuite) TestAddMachinesEnvironmentDying(c *gc.C) {
211
211
        _, err := s.State.AddMachine("quantal", state.JobHostUnits)
212
212
        c.Assert(err, gc.IsNil)
213
 
        // Check that machines cannot be added if the environment is Dying.
214
213
        env, err := s.State.Environment()
215
214
        c.Assert(err, gc.IsNil)
216
215
        err = env.Destroy()
217
216
        c.Assert(err, gc.IsNil)
 
217
        // Check that machines cannot be added if the environment is initially Dying.
 
218
        _, err = s.State.AddMachine("quantal", state.JobHostUnits)
 
219
        c.Assert(err, gc.ErrorMatches, "cannot add a new machine: environment is being destroyed")
 
220
}
 
221
 
 
222
func (s *StateSuite) TestAddMachinesEnvironmentDyingAfterInitial(c *gc.C) {
 
223
        _, err := s.State.AddMachine("quantal", state.JobHostUnits)
 
224
        c.Assert(err, gc.IsNil)
 
225
        env, err := s.State.Environment()
 
226
        c.Assert(err, gc.IsNil)
 
227
        // Check that machines cannot be added if the environment is initially
 
228
        // Alive but set to Dying immediately before the transaction is run.
 
229
        defer state.SetBeforeHooks(c, s.State, func() {
 
230
                c.Assert(env.Life(), gc.Equals, state.Alive)
 
231
                c.Assert(env.Destroy(), gc.IsNil)
 
232
        }).Check()
218
233
        _, err = s.State.AddMachine("quantal", state.JobHostUnits)
219
234
        c.Assert(err, gc.ErrorMatches, "cannot add a new machine: environment is being destroyed")
220
235
}
542
557
        c.Assert(ch.URL(), gc.DeepEquals, charm.URL())
543
558
}
544
559
 
545
 
func (s *StateSuite) TestAddServiceEnvironmentLife(c *gc.C) {
 
560
func (s *StateSuite) TestAddServiceEnvironmentDying(c *gc.C) {
546
561
        charm := s.AddTestingCharm(c, "dummy")
547
562
        _, err := s.State.AddService("s0", charm)
548
563
        c.Assert(err, gc.IsNil)
549
 
 
550
 
        // Check that services cannot be added if the environment is Dying.
 
564
        // Check that services cannot be added if the environment is initially Dying.
551
565
        env, err := s.State.Environment()
552
566
        c.Assert(err, gc.IsNil)
553
567
        err = env.Destroy()
556
570
        c.Assert(err, gc.ErrorMatches, `cannot add service "s1": environment is being destroyed`)
557
571
}
558
572
 
 
573
func (s *StateSuite) TestAddServiceEnvironmentDyingAfterInitial(c *gc.C) {
 
574
        charm := s.AddTestingCharm(c, "dummy")
 
575
        _, err := s.State.AddService("s0", charm)
 
576
        c.Assert(err, gc.IsNil)
 
577
        env, err := s.State.Environment()
 
578
        c.Assert(err, gc.IsNil)
 
579
        // Check that services cannot be added if the environment is initially
 
580
        // Alive but set to Dying immediately before the transaction is run.
 
581
        defer state.SetBeforeHooks(c, s.State, func() {
 
582
                c.Assert(env.Life(), gc.Equals, state.Alive)
 
583
                c.Assert(env.Destroy(), gc.IsNil)
 
584
        }).Check()
 
585
        _, err = s.State.AddService("s1", charm)
 
586
        c.Assert(err, gc.ErrorMatches, `cannot add service "s1": environment is being destroyed`)
 
587
}
 
588
 
559
589
func (s *StateSuite) TestServiceNotFound(c *gc.C) {
560
590
        _, err := s.State.Service("bummer")
561
591
        c.Assert(err, gc.ErrorMatches, `service "bummer" not found`)
1614
1644
        tag: "user-arble",
1615
1645
}, {
1616
1646
        tag: "environment-notauuid",
1617
 
        err: `"environment-notauuid" is not a valid environment tag`,
 
1647
        // TODO(axw) remove backwards compatibility for environment-tag; see lp:1257587
 
1648
        //err: `"environment-notauuid" is not a valid environment tag`,
1618
1649
}}
1619
1650
 
1620
1651
var entityTypes = map[string]interface{}{
1661
1692
                        kind, err := names.TagKind(test.tag)
1662
1693
                        c.Assert(err, gc.IsNil)
1663
1694
                        c.Assert(e, gc.FitsTypeOf, entityTypes[kind])
1664
 
                        c.Assert(e.Tag(), gc.Equals, test.tag)
 
1695
                        if kind == "environment" {
 
1696
                                // TODO(axw) remove backwards compatibility for environment-tag; see lp:1257587
 
1697
                                // We *should* only be able to get the entity with its tag, but
 
1698
                                // for backwards-compatibility we accept any non-UUID tag.
 
1699
                                c.Assert(e.Tag(), gc.Equals, env.Tag())
 
1700
                        } else {
 
1701
                                c.Assert(e.Tag(), gc.Equals, test.tag)
 
1702
                        }
1665
1703
                }
1666
1704
        }
1667
1705
}