github.com/blend/go-sdk@v1.20220411.3/logger/json_output_formatter_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 "context" 13 "testing" 14 15 "github.com/blend/go-sdk/assert" 16 ) 17 18 func TestJSONOutputFormatter(t *testing.T) { 19 assert := assert.New(t) 20 21 jf := NewJSONOutputFormatter( 22 OptJSONPretty(), 23 OptJSONPrettyPrefix(" "), 24 OptJSONPrettyIndent("\t\t"), 25 ) 26 assert.True(jf.Pretty) 27 assert.Equal(" ", jf.PrettyPrefixOrDefault()) 28 assert.Equal("\t\t", jf.PrettyIndentOrDefault()) 29 jf.Pretty = false 30 31 me := NewMessageEvent(Info, "this is a test") 32 33 buf := new(bytes.Buffer) 34 assert.Nil(jf.WriteFormat(context.Background(), buf, me)) 35 36 assert.Contains(buf.String(), "\"text\":\"this is a test\"") 37 38 jf.Pretty = true 39 jf.PrettyPrefix = "" 40 jf.PrettyIndent = "\t" 41 42 buf = new(bytes.Buffer) 43 assert.Nil(jf.WriteFormat(context.Background(), buf, me)) 44 assert.Contains(buf.String(), "\t\"text\": \"this is a test\"\n") 45 }