github.com/blend/go-sdk@v1.20220411.3/logger/shim_writer_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package logger
     9  
    10  import (
    11  	"bytes"
    12  	"fmt"
    13  	"testing"
    14  
    15  	"github.com/blend/go-sdk/assert"
    16  )
    17  
    18  func TestShimLogger(t *testing.T) {
    19  	assert := assert.New(t)
    20  
    21  	buf := new(bytes.Buffer)
    22  	log, err := New(
    23  		OptOutput(buf),
    24  		OptAll(),
    25  		OptText(OptTextHideTimestamp(), OptTextNoColor()),
    26  	)
    27  	assert.Nil(err)
    28  	defer log.Close()
    29  
    30  	sw := NewShimWriter(log,
    31  		OptShimWriterEventProvider(
    32  			ShimWriterMessageEventProvider("shim"),
    33  		),
    34  	)
    35  	fmt.Fprintln(sw, "this is a test")
    36  	fmt.Fprintln(sw, "this is also a test")
    37  
    38  	assert.NotEmpty(buf.String())
    39  	assert.Equal("[shim] this is a test\n[shim] this is also a test\n", buf.String())
    40  }