~dave-cheney/juju-core/102-cmd-init-context

« back to all changes in this revision

Viewing changes to worker/uniter/uniter_test.go

  • Committer: Roger Peppe
  • Date: 2012-09-12 22:53:44 UTC
  • mfrom: (478.7.21 056-container-fix)
  • Revision ID: roger.peppe@canonical.com-20120912225344-ih1kx2hxv1uw1s8m
container: fix jujud arguments.

Unfortunately we can't test this properly until
we have something using container to do a deployment,
which won't happen until the uniter integration
branch (https://codereview.appspot.com/6497109/)
is merged.

We also add a Unit.AgentName method, meaning
that we can use the same logic in various places that
need to calculate an agent name from a unit.

We also change the path where unit data is stored
($vardir/agents/unit-agent-name) so that any other
agent data can have an entry in the agents directory too.

R=fwereade, niemeyer
CC=
https://codereview.appspot.com/6498117

Show diffs side-by-side

added added

removed removed

Lines of Context:
146
146
        ut(
147
147
                "unable to create directories",
148
148
                writeFile{"state", 0644},
 
149
                createCharm{},
 
150
                createServiceAndUnit{},
149
151
                startUniter{`failed to create uniter for unit "u/0": .*state must be a directory`},
150
152
        ), ut(
151
153
                "unknown unit",
258
260
}
259
261
 
260
262
func (s *UniterSuite) TestUniter(c *C) {
261
 
        unitDir := filepath.Join(s.dataDir, "units", "u-0")
 
263
        unitDir := filepath.Join(s.dataDir, "agents", "unit-u-0")
262
264
        for i, t := range uniterTests {
263
265
                if i != 0 {
264
266
                        s.Reset(c)
268
270
                }
269
271
                c.Logf("\ntest %d: %s\n", i, t.summary)
270
272
                ctx := &context{
 
273
                        st:      s.State,
271
274
                        id:      i,
272
275
                        path:    unitDir,
273
276
                        dataDir: s.dataDir,
274
 
                        st:      s.State,
275
277
                        charms:  coretesting.ResponseMap{},
276
278
                }
277
279
                for i, s := range t.steps {
329
331
 
330
332
type serveCharm struct{}
331
333
 
332
 
func (s serveCharm) step(c *C, ctx *context) {
 
334
func (serveCharm) step(c *C, ctx *context) {
333
335
        coretesting.Server.ResponseMap(1, ctx.charms)
334
336
}
335
337
 
336
 
type createUniter struct{}
 
338
type createServiceAndUnit struct{}
337
339
 
338
 
func (s createUniter) step(c *C, ctx *context) {
 
340
func (createServiceAndUnit) step(c *C, ctx *context) {
339
341
        cfg, err := config.New(map[string]interface{}{
340
342
                "name":            "testenv",
341
343
                "type":            "dummy",
353
355
        c.Assert(err, IsNil)
354
356
        ctx.svc = svc
355
357
        ctx.unit = unit
 
358
}
 
359
 
 
360
type createUniter struct{}
 
361
 
 
362
func (createUniter) step(c *C, ctx *context) {
 
363
        step(c, ctx, createServiceAndUnit{})
356
364
        step(c, ctx, startUniter{})
357
365
 
358
366
        // Poll for correct address settings (consequence of "dummy" env type).
362
370
                case <-timeout:
363
371
                        c.Fatalf("timed out waiting for unit addresses")
364
372
                case <-time.After(50 * time.Millisecond):
365
 
                        private, err := unit.PrivateAddress()
 
373
                        private, err := ctx.unit.PrivateAddress()
366
374
                        if err != nil || private != "private.dummy.address.example.com" {
367
375
                                continue
368
376
                        }
369
 
                        public, err := unit.PublicAddress()
 
377
                        public, err := ctx.unit.PublicAddress()
370
378
                        if err != nil || public != "public.dummy.address.example.com" {
371
379
                                continue
372
380
                        }
388
396
                c.Assert(err, IsNil)
389
397
                ctx.uniter = u
390
398
        } else {
391
 
                c.Assert(u, IsNil)
 
399
                c.Check(u, IsNil)
392
400
                c.Assert(err, ErrorMatches, s.err)
393
401
        }
394
402
}