예제 #1
0
func NewCliApp() *cli.App {
	config := config.New(persister.NewFilePersister(config_helpers.ConfigFileLocation(ltcConfigRoot())))

	signalChan := make(chan os.Signal)
	signal.Notify(signalChan, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM)
	exitHandler := exit_handler.New(signalChan, os.Exit)
	go exitHandler.Run()

	receptorClientCreator := receptor_client.ProxyAwareCreator{}

	return cli_app_factory.MakeCliApp(
		diegoVersion,
		latticeVersion,
		ltcConfigRoot(),
		exitHandler,
		config,
		logger(),
		receptorClientCreator,
		target_verifier.New(receptorClientCreator),
		os.Stdout,
	)
}
	var (
		buffer      *gbytes.Buffer
		exitFunc    func(int)
		signalChan  chan os.Signal
		exitHandler exit_handler.ExitHandler
	)

	BeforeEach(func() {
		buffer = gbytes.NewBuffer()

		exitFunc = func(code int) {
			buffer.Write([]byte(fmt.Sprintf("Exit-Code=%d", code)))
		}

		signalChan = make(chan os.Signal)
		exitHandler = exit_handler.New(signalChan, exitFunc)
		go exitHandler.Run()

		exitHandler.OnExit(func() {
			buffer.Write([]byte("handler1 "))
		})

		exitHandler.OnExit(func() {
			buffer.Write([]byte("handler2 "))
		})
	})

	Context("Signals", func() {
		It("Executes exit handlers on os.Interupts", func() {
			signalChan <- os.Interrupt
			Eventually(buffer).Should(gbytes.Say("handler1 handler2 Exit-Code=160"))