~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/api/firewaller/firewaller_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

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
        jc "github.com/juju/testing/checkers"
 
8
        "github.com/juju/utils"
 
9
        gc "gopkg.in/check.v1"
 
10
 
 
11
        "github.com/juju/juju/api"
 
12
        "github.com/juju/juju/api/firewaller"
 
13
        "github.com/juju/juju/juju/testing"
 
14
        "github.com/juju/juju/state"
 
15
)
 
16
 
 
17
// NOTE: This suite is intended for embedding into other suites,
 
18
// so common code can be reused. Do not add test cases to it,
 
19
// otherwise they'll be run by each other suite that embeds it.
 
20
type firewallerSuite struct {
 
21
        testing.JujuConnSuite
 
22
 
 
23
        st          api.Connection
 
24
        machines    []*state.Machine
 
25
        application *state.Application
 
26
        charm       *state.Charm
 
27
        units       []*state.Unit
 
28
 
 
29
        firewaller *firewaller.State
 
30
}
 
31
 
 
32
var _ = gc.Suite(&firewallerSuite{})
 
33
 
 
34
func (s *firewallerSuite) SetUpTest(c *gc.C) {
 
35
        s.JujuConnSuite.SetUpTest(c)
 
36
 
 
37
        // Reset previous machines and units (if any) and create 3
 
38
        // machines for the tests. The first one is a manager node.
 
39
        s.machines = make([]*state.Machine, 3)
 
40
        s.units = make([]*state.Unit, 3)
 
41
 
 
42
        var err error
 
43
        s.machines[0], err = s.State.AddMachine("quantal", state.JobManageModel, state.JobHostUnits)
 
44
        c.Assert(err, jc.ErrorIsNil)
 
45
        password, err := utils.RandomPassword()
 
46
        c.Assert(err, jc.ErrorIsNil)
 
47
        err = s.machines[0].SetPassword(password)
 
48
        c.Assert(err, jc.ErrorIsNil)
 
49
        err = s.machines[0].SetProvisioned("i-manager", "fake_nonce", nil)
 
50
        c.Assert(err, jc.ErrorIsNil)
 
51
        s.st = s.OpenAPIAsMachine(c, s.machines[0].Tag(), password, "fake_nonce")
 
52
        c.Assert(s.st, gc.NotNil)
 
53
 
 
54
        // Note that the specific machine ids allocated are assumed
 
55
        // to be numerically consecutive from zero.
 
56
        for i := 1; i <= 2; i++ {
 
57
                s.machines[i], err = s.State.AddMachine("quantal", state.JobHostUnits)
 
58
                c.Check(err, jc.ErrorIsNil)
 
59
        }
 
60
        // Create a service and three units for these machines.
 
61
        s.charm = s.AddTestingCharm(c, "wordpress")
 
62
        s.application = s.AddTestingService(c, "wordpress", s.charm)
 
63
        // Add the rest of the units and assign them.
 
64
        for i := 0; i <= 2; i++ {
 
65
                s.units[i], err = s.application.AddUnit()
 
66
                c.Check(err, jc.ErrorIsNil)
 
67
                err = s.units[i].AssignToMachine(s.machines[i])
 
68
                c.Check(err, jc.ErrorIsNil)
 
69
        }
 
70
 
 
71
        // Create the firewaller API facade.
 
72
        s.firewaller = firewaller.NewState(s.st)
 
73
        c.Assert(s.firewaller, gc.NotNil)
 
74
}