github.com/blend/go-sdk@v1.20220411.3/r2/opt_log_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 r2 9 10 import ( 11 "bytes" 12 "fmt" 13 "net/http" 14 "net/http/httptest" 15 "testing" 16 17 "github.com/blend/go-sdk/assert" 18 "github.com/blend/go-sdk/logger" 19 ) 20 21 func TestOptLog(t *testing.T) { 22 assert := assert.New(t) 23 24 buf := new(bytes.Buffer) 25 log, err := logger.New(logger.OptOutput(buf), logger.OptAll()) 26 assert.Nil(err) 27 28 server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { 29 rw.WriteHeader(http.StatusOK) 30 fmt.Fprintf(rw, "OK!\n") 31 })) 32 defer server.Close() 33 34 _, err = New(server.URL, OptLog(log)).Discard() 35 assert.Nil(err) 36 assert.NotEmpty(buf.String()) 37 }