github.com/koko1123/flow-go-1@v0.29.6/module/util/log_test.go (about) 1 package util 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/rs/zerolog" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestLogProgress(t *testing.T) { 12 buf := bytes.NewBufferString("") 13 lg := zerolog.New(buf) 14 logger := LogProgress("test", 40, &lg) 15 for i := 0; i < 50; i++ { 16 logger(i) 17 } 18 19 expectedLogs := 20 `{"level":"info","message":"test completion percentage: 10 percent"} 21 {"level":"info","message":"test completion percentage: 20 percent"} 22 {"level":"info","message":"test completion percentage: 30 percent"} 23 {"level":"info","message":"test completion percentage: 40 percent"} 24 {"level":"info","message":"test completion percentage: 50 percent"} 25 {"level":"info","message":"test completion percentage: 60 percent"} 26 {"level":"info","message":"test completion percentage: 70 percent"} 27 {"level":"info","message":"test completion percentage: 80 percent"} 28 {"level":"info","message":"test completion percentage: 90 percent"} 29 {"level":"info","message":"test completion percentage: 100 percent"} 30 {"level":"info","message":"test completion percentage: 110 percent"} 31 {"level":"info","message":"test completion percentage: 120 percent"} 32 ` 33 require.Equal(t, expectedLogs, buf.String()) 34 }