object: add Token header case to CopyTo

This commit is contained in:
Leonard Lyubich 2020-05-08 15:05:33 +03:00
parent 87d0efaad2
commit dd2f568347
2 changed files with 27 additions and 0 deletions

View file

@ -251,6 +251,12 @@ func (m *Object) CopyTo(o *Object) {
HomoHash: v.HomoHash, HomoHash: v.HomoHash,
}, },
} }
case *Header_Token:
o.Headers[i] = Header{
Value: &Header_Token{
Token: v.Token,
},
}
default: default:
o.Headers[i] = *proto.Clone(&m.Headers[i]).(*Header) o.Headers[i] = *proto.Clone(&m.Headers[i]).(*Header)
} }

View file

@ -178,3 +178,24 @@ Object:
require.NoError(t, Stringify(buf, obj)) require.NoError(t, Stringify(buf, obj))
require.Equal(t, res, buf.String()) require.Equal(t, res, buf.String())
} }
func TestObject_Copy(t *testing.T) {
t.Run("token header", func(t *testing.T) {
token := new(Token)
token.SetID(service.TokenID{1, 2, 3})
obj := new(Object)
obj.AddHeader(&Header{
Value: &Header_Token{
Token: token,
},
})
cp := obj.Copy()
_, h := cp.LastHeader(HeaderType(TokenHdr))
require.NotNil(t, h)
require.Equal(t, token, h.GetValue().(*Header_Token).Token)
})
}