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