~rogpeppe/juju-core/themue-058-debug-log-api

« back to all changes in this revision

Viewing changes to state/api/firewaller/firewaller_test.go

  • Committer: Frank Mueller
  • Date: 2014-01-23 14:14:49 UTC
  • mfrom: (2152.1.95 juju-core)
  • Revision ID: frank.mueller@canonical.com-20140123141449-b30l57y7gs3wjkpw
debugger: merged trunk and fixed permission and interface problems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package firewaller_test
 
5
 
 
6
import (
 
7
        stdtesting "testing"
 
8
 
 
9
        gc "launchpad.net/gocheck"
 
10
 
 
11
        "launchpad.net/juju-core/juju/testing"
 
12
        "launchpad.net/juju-core/state"
 
13
        "launchpad.net/juju-core/state/api"
 
14
        "launchpad.net/juju-core/state/api/firewaller"
 
15
        coretesting "launchpad.net/juju-core/testing"
 
16
        "launchpad.net/juju-core/utils"
 
17
)
 
18
 
 
19
// NOTE: This suite is intended for embedding into other suites,
 
20
// so common code can be reused. Do not add test cases to it,
 
21
// otherwise they'll be run by each other suite that embeds it.
 
22
type firewallerSuite struct {
 
23
        testing.JujuConnSuite
 
24
 
 
25
        st       *api.State
 
26
        machines []*state.Machine
 
27
        service  *state.Service
 
28
        charm    *state.Charm
 
29
        units    []*state.Unit
 
30
 
 
31
        firewaller *firewaller.State
 
32
}
 
33
 
 
34
var _ = gc.Suite(&firewallerSuite{})
 
35
 
 
36
func TestAll(t *stdtesting.T) {
 
37
        coretesting.MgoTestPackage(t)
 
38
}
 
39
 
 
40
func (s *firewallerSuite) SetUpTest(c *gc.C) {
 
41
        s.JujuConnSuite.SetUpTest(c)
 
42
 
 
43
        // Reset previous machines and units (if any) and create 3
 
44
        // machines for the tests. The first one is a manager node.
 
45
        s.machines = make([]*state.Machine, 3)
 
46
        s.units = make([]*state.Unit, 3)
 
47
 
 
48
        var err error
 
49
        s.machines[0], err = s.State.AddMachine("quantal", state.JobManageEnviron, state.JobHostUnits)
 
50
        c.Assert(err, gc.IsNil)
 
51
        password, err := utils.RandomPassword()
 
52
        c.Assert(err, gc.IsNil)
 
53
        err = s.machines[0].SetPassword(password)
 
54
        c.Assert(err, gc.IsNil)
 
55
        err = s.machines[0].SetProvisioned("i-manager", "fake_nonce", nil)
 
56
        c.Assert(err, gc.IsNil)
 
57
        s.st = s.OpenAPIAsMachine(c, s.machines[0].Tag(), password, "fake_nonce")
 
58
        c.Assert(s.st, gc.NotNil)
 
59
 
 
60
        // Note that the specific machine ids allocated are assumed
 
61
        // to be numerically consecutive from zero.
 
62
        for i := 1; i <= 2; i++ {
 
63
                s.machines[i], err = s.State.AddMachine("quantal", state.JobHostUnits)
 
64
                c.Check(err, gc.IsNil)
 
65
        }
 
66
        // Create a service and three units for these machines.
 
67
        s.charm = s.AddTestingCharm(c, "wordpress")
 
68
        s.service = s.AddTestingService(c, "wordpress", s.charm)
 
69
        // Add the rest of the units and assign them.
 
70
        for i := 0; i <= 2; i++ {
 
71
                s.units[i], err = s.service.AddUnit()
 
72
                c.Check(err, gc.IsNil)
 
73
                err = s.units[i].AssignToMachine(s.machines[i])
 
74
                c.Check(err, gc.IsNil)
 
75
        }
 
76
 
 
77
        // Create the firewaller API facade.
 
78
        s.firewaller = s.st.Firewaller()
 
79
        c.Assert(s.firewaller, gc.NotNil)
 
80
}