github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/cmd/jujud/agent/common_test.go (about) 1 package agent 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "time" 7 8 "github.com/juju/cmd" 9 "github.com/juju/names" 10 11 "github.com/juju/juju/agent" 12 coretesting "github.com/juju/juju/testing" 13 "github.com/juju/juju/worker" 14 ) 15 16 // This file contains bits of test infrastructure that are shared by 17 // the unit and machine agent tests. 18 19 type runner interface { 20 Run(*cmd.Context) error 21 Stop() error 22 } 23 24 // runWithTimeout runs an agent and waits 25 // for it to complete within a reasonable time. 26 func runWithTimeout(r runner) error { 27 done := make(chan error) 28 go func() { 29 done <- r.Run(nil) 30 }() 31 select { 32 case err := <-done: 33 return err 34 case <-time.After(coretesting.LongWait): 35 } 36 err := r.Stop() 37 return fmt.Errorf("timed out waiting for agent to finish; stop error: %v", err) 38 } 39 40 func newDummyWorker() worker.Worker { 41 return worker.NewSimpleWorker(func(stop <-chan struct{}) error { 42 <-stop 43 return nil 44 }) 45 } 46 47 type FakeConfig struct { 48 agent.Config 49 } 50 51 func (FakeConfig) LogDir() string { 52 return filepath.FromSlash("/var/log/juju/") 53 } 54 55 func (FakeConfig) Tag() names.Tag { 56 return names.NewMachineTag("42") 57 } 58 59 type FakeAgentConfig struct { 60 AgentConf 61 } 62 63 func (FakeAgentConfig) ReadConfig(string) error { return nil } 64 65 func (FakeAgentConfig) CurrentConfig() agent.Config { 66 return FakeConfig{} 67 } 68 69 func (FakeAgentConfig) CheckArgs([]string) error { return nil }