github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/cmd/jujud/agent/imagemetadataworker_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package agent 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 10 "github.com/juju/juju/api/imagemetadata" 11 "github.com/juju/juju/environs" 12 "github.com/juju/juju/environs/config" 13 "github.com/juju/juju/environs/simplestreams" 14 "github.com/juju/juju/state" 15 "github.com/juju/juju/worker" 16 ) 17 18 // MachineMockProviderSuite runs worker tests that depend 19 // on provider that has cloud region support. 20 type MachineMockProviderSuite struct { 21 commonMachineSuite 22 } 23 24 var _ = gc.Suite(&MachineMockProviderSuite{}) 25 26 func (s *MachineMockProviderSuite) SetUpTest(c *gc.C) { 27 // Change to environ that supports HasRegion 28 s.commonMachineSuite.SetUpTest(c) 29 } 30 31 func (s *MachineMockProviderSuite) TestMachineAgentRunsMetadataWorker(c *gc.C) { 32 // Patch out the worker func before starting the agent. 33 started := make(chan struct{}) 34 newWorker := func(cl *imagemetadata.Client) worker.Worker { 35 close(started) 36 return worker.NewNoOpWorker() 37 } 38 s.PatchValue(&newMetadataUpdater, newWorker) 39 s.PatchValue(&newEnvirons, func(config *config.Config) (environs.Environ, error) { 40 return &dummyEnviron{}, nil 41 }) 42 43 // Start the machine agent. 44 m, _, _ := s.primeAgent(c, state.JobManageModel) 45 a := s.newAgent(c, m) 46 go func() { c.Check(a.Run(nil), jc.ErrorIsNil) }() 47 defer func() { c.Check(a.Stop(), jc.ErrorIsNil) }() 48 49 s.assertChannelActive(c, started, "metadata update worker to start") 50 } 51 52 // dummyEnviron is an environment with region support. 53 type dummyEnviron struct { 54 environs.Environ 55 } 56 57 // Region is specified in the HasRegion interface. 58 func (e *dummyEnviron) Region() (simplestreams.CloudSpec, error) { 59 return simplestreams.CloudSpec{ 60 Region: "dummy_region", 61 Endpoint: "https://anywhere", 62 }, nil 63 }