From 2c571718d06d635f1cb5ca7f8bcb134a222f5357 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 18 May 2020 12:47:13 +0300 Subject: [PATCH] object: add unit test of HeadRequest.ReadSignedData method --- object/sign_test.go | 26 ++++++++++++++++++++++++++ object/types.go | 5 +++++ 2 files changed, 31 insertions(+) diff --git a/object/sign_test.go b/object/sign_test.go index 4df1c2b..fb57baa 100644 --- a/object/sign_test.go +++ b/object/sign_test.go @@ -187,3 +187,29 @@ func TestSignVerifyRequests(t *testing.T) { } } } + +func TestHeadRequest_ReadSignedData(t *testing.T) { + t.Run("full headers", func(t *testing.T) { + req := new(HeadRequest) + + // allocate buffer for reading + buf := make([]byte, req.SignedDataSize()) + buf[0] = 2 + + // set FullHeaders option + req.SetFullHeaders(true) + + _, err := req.ReadSignedData(buf) + require.NoError(t, err) + + require.Equal(t, byte(1), buf[0]) + + // unset FullHeaders option + req.SetFullHeaders(false) + + _, err = req.ReadSignedData(buf) + require.NoError(t, err) + + require.Equal(t, byte(0), buf[0]) + }) +} diff --git a/object/types.go b/object/types.go index c8d3f25..4edf5f4 100644 --- a/object/types.go +++ b/object/types.go @@ -386,3 +386,8 @@ func Stringify(dst io.Writer, obj *Object) error { return nil } + +// SetFullHeaders is a FullHeaders field setter. +func (m *HeadRequest) SetFullHeaders(v bool) { + m.FullHeaders = v +}