func main() { log.Printf("Agent starting, use CTL-C to quit\n") defer log.Printf("Agent stopped\n") var debug bool flag.BoolVar(&debug, "debug", false, "Enable debug logging.") flag.Parse() if debug { emitter.DefaultEmitter = emitter.NewLoggingEmitter() } stopChan := make(chan struct{}) go func() { err := agent.Run(stopChan) if err != nil { log.Fatalf("failed to run agent: %v", err) } }() killChan := make(chan os.Signal, 2) signal.Notify(killChan, syscall.SIGINT, syscall.SIGTERM) for { select { case <-RegisterGoRoutineDumpSignalChannel(): DumpGoRoutine() case <-killChan: close(stopChan) return } } }
BeforeEach(func() { agent.UdpListeningPort.Set(0) agent.TcpListeningPort.Set(0) dataChan = make(chan []byte, 10) fakeEmitter = &FakeEmitter{dataChan} emitter.DefaultEmitter = fakeEmitter stopChan = make(chan struct{}) errChan = make(chan error) }) It("checks that there is a default emitter", func(done Done) { defer close(done) emitter.DefaultEmitter = nil err := agent.Run(nil) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(Equal("Could not start agent. No default emitter provided.")) }) It("listens for UDP packets and emits them", func(done Done) { defer close(done) go func() { defer close(errChan) err := agent.Run(stopChan) errChan <- err }() Eventually(agent.UdpListeningPort.Get).ShouldNot(BeZero())