package v1 import ( "bytes" "encoding/json" "fmt" "log" "math/rand" "net/http" "os" "strconv" "strings" "testing" "time" "github.com/joho/godotenv" "github.com/stretchr/testify/assert" "gopkg.in/h2non/gock.v1" ) const ( letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" letterIdxBits = 6 // 6 bits to represent a letter index letterIdxMask = 1<= 0; { if remain == 0 { cache, remain = src.Int63(), letterIdxMax } if idx := int(cache & letterIdxMask); idx < len(letterBytes) { b[i] = letterBytes[idx] i-- } cache >>= letterIdxBits remain-- } return string(b) } func TestMgClient_DebugNoLogger(t *testing.T) { c := client() c.Debug = true var buf bytes.Buffer log.SetOutput(&buf) defer func() { log.SetOutput(os.Stderr) }() c.writeLog("Test log string") assert.Contains(t, buf.String(), "Test log string") } func TestMgClient_DebugWithLogger(t *testing.T) { var buf bytes.Buffer logger := log.New(&buf, "Custom log prefix ", 0) c := client() c.Debug = true c.WithLogger(logger) c.writeLog("Test log string") assert.Contains(t, buf.String(), "Custom log prefix Test log string") }