github.com/yunabe/lgo@v0.0.0-20190709125917-42c42d410fdf/jupyter/gojupyterscaffold/logger_test.go (about)

     1  package gojupyterscaffold
     2  
     3  import (
     4  	"bytes"
     5  	"log"
     6  	"os"
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestLoggerInfo(t *testing.T) {
    12  	defer log.SetOutput(os.Stderr)
    13  	var buf bytes.Buffer
    14  	log.SetOutput(&buf)
    15  	logger.Info("a", "b", 10, 20)
    16  	suffix := "ab10 20\n"
    17  	got := buf.String()
    18  	if !strings.HasSuffix(got, suffix) {
    19  		t.Errorf("want %q suffix, got %q", suffix, got)
    20  	}
    21  }
    22  
    23  func TestLoggerInfof(t *testing.T) {
    24  	defer log.SetOutput(os.Stderr)
    25  	var buf bytes.Buffer
    26  	log.SetOutput(&buf)
    27  	logger.Infof("%05d", 123)
    28  	suffix := "00123\n"
    29  	got := buf.String()
    30  	if !strings.HasSuffix(got, suffix) {
    31  		t.Errorf("want %q suffix, got %q", suffix, got)
    32  	}
    33  }