github.com/prebid/prebid-server/v2@v2.18.0/config/util/loggers_test.go (about) 1 package util 2 3 import ( 4 "bytes" 5 "fmt" 6 "math/rand" 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestLogRandomSample(t *testing.T) { 13 14 const expected string = `This is test line 2 15 This is test line 3 16 ` 17 18 myRand := rand.New(rand.NewSource(1337)) 19 var buf bytes.Buffer 20 21 mylogger := func(msg string, args ...interface{}) { 22 buf.WriteString(fmt.Sprintf(fmt.Sprintln(msg), args...)) 23 } 24 25 logRandomSampleImpl("This is test line 1", mylogger, 0.5, myRand.Float32) 26 logRandomSampleImpl("This is test line 2", mylogger, 0.5, myRand.Float32) 27 logRandomSampleImpl("This is test line 3", mylogger, 0.5, myRand.Float32) 28 logRandomSampleImpl("This is test line 4", mylogger, 0.5, myRand.Float32) 29 logRandomSampleImpl("This is test line 5", mylogger, 0.5, myRand.Float32) 30 31 assert.EqualValues(t, expected, buf.String()) 32 }