forked from TrueCloudLab/frostfs-http-gw
[#219] Use zaptest.Logger
Use zaptest to get logs which get printed only if a test fails or if you ran go test -v. Dont use zaptest.Logger for fuzz otherwise ngfuzz/libfuzz crashes Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
f9c5dc5260
commit
a651b5823f
3 changed files with 14 additions and 24 deletions
|
@ -21,6 +21,7 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
go_fuzz_utils "github.com/trailofbits/go-fuzz-utils"
|
||||
"github.com/valyala/fasthttp"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -125,7 +126,7 @@ func maybeFillRandom(tp *go_fuzz_utils.TypeProvider, initValue string) (string,
|
|||
}
|
||||
|
||||
func upload(tp *go_fuzz_utils.TypeProvider) (context.Context, *handlerContext, cid.ID, *fasthttp.RequestCtx, string, string, string, error) {
|
||||
hc, err := prepareHandlerContext()
|
||||
hc, err := prepareHandlerContextBase(zap.NewExample())
|
||||
if err != nil {
|
||||
return nil, nil, cid.ID{}, nil, "", "", "", err
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"github.com/valyala/fasthttp"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
||||
type treeServiceMock struct {
|
||||
|
@ -112,12 +113,13 @@ func (hc *handlerContext) Handler() *Handler {
|
|||
return hc.h
|
||||
}
|
||||
|
||||
func prepareHandlerContext() (*handlerContext, error) {
|
||||
logger, err := zap.NewDevelopment()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func prepareHandlerContext(t *testing.T) *handlerContext {
|
||||
hc, err := prepareHandlerContextBase(zaptest.NewLogger(t))
|
||||
require.NoError(t, err)
|
||||
return hc
|
||||
}
|
||||
|
||||
func prepareHandlerContextBase(logger *zap.Logger) (*handlerContext, error) {
|
||||
key, err := keys.NewPrivateKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -196,8 +198,7 @@ func (hc *handlerContext) prepareContainer(name string, basicACL acl.Basic) (cid
|
|||
}
|
||||
|
||||
func TestBasic(t *testing.T) {
|
||||
hc, err := prepareHandlerContext()
|
||||
require.NoError(t, err)
|
||||
hc := prepareHandlerContext(t)
|
||||
|
||||
bktName := "bucket"
|
||||
cnrID, cnr, err := hc.prepareContainer(bktName, acl.PublicRWExtended)
|
||||
|
@ -279,8 +280,7 @@ func TestBasic(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindObjectByAttribute(t *testing.T) {
|
||||
hc, err := prepareHandlerContext()
|
||||
require.NoError(t, err)
|
||||
hc := prepareHandlerContext(t)
|
||||
hc.cfg.additionalSearch = true
|
||||
|
||||
bktName := "bucket"
|
||||
|
@ -377,8 +377,7 @@ func TestFindObjectByAttribute(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNeedSearchByFileName(t *testing.T) {
|
||||
hc, err := prepareHandlerContext()
|
||||
require.NoError(t, err)
|
||||
hc := prepareHandlerContext(t)
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
|
|
|
@ -60,12 +60,7 @@ func BenchmarkAll(b *testing.B) {
|
|||
func defaultMultipart(filename string) error {
|
||||
r, bound := multipartFile(filename)
|
||||
|
||||
logger, err := zap.NewProduction()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := fetchMultipartFileDefault(logger, r, bound)
|
||||
file, err := fetchMultipartFileDefault(zap.NewNop(), r, bound)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -87,12 +82,7 @@ func TestName(t *testing.T) {
|
|||
func customMultipart(filename string) error {
|
||||
r, bound := multipartFile(filename)
|
||||
|
||||
logger, err := zap.NewProduction()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := fetchMultipartFile(logger, r, bound)
|
||||
file, err := fetchMultipartFile(zap.NewNop(), r, bound)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue