Esempio n. 1
0
func TestMain(t *testing.T) {
	testWriter := bufio.NewWriter(ioutil.Discard)
	logger = logging.NewLoggerWithWriter(testWriter, logging.INFO)
	cronlogger = logging.NewLoggerWithWriter(testWriter, logging.INFO)

	// 標準のlogも出力先をDiscardにする
	log.SetOutput(ioutil.Discard)
}
Esempio n. 2
0
func TestStart(t *testing.T) {
	buffer := &bytes.Buffer{}
	logger = logging.NewLoggerWithWriter(buffer, logging.DEBUG)

	server, err := NewWebApiServer(":16777", nil)
	if err != nil {
		t.Error(err)
		return
	}
	wc := make(chan os.Signal)
	wsc := make(chan error)
	signal.Notify(wc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
	err = server.Start(wc, wsc)
	if err != nil {
		t.Error(err)
		return
	}

	// 自分自身にSIGTERMを投げる
	pid := os.Getpid()
	syscall.Kill(pid, syscall.SIGTERM)
	err = <-wsc
	if err.Error() != "accept tcp [::]:16777: use of closed network connection" {
		t.Error(err)
	}

	// terminatedを出力している事を確認
	output := buffer.String()
	if !strings.Contains(output, "terminated") {
		t.Errorf("(exptected) terminated != %s", output)
	}
}
Esempio n. 3
0
func SetLoggerWithWriter(writer io.Writer, level logging.Level) {
	if logger != nil {
		logger.Close()
	}
	logger = logging.NewLoggerWithWriter(writer, level)
}