Merge pull request #63 from nspcc-dev/more-test-case-for-cid-getter

More test case for cid getter
This commit is contained in:
Evgeniy Kulikov 2020-04-10 11:35:34 +03:00 committed by GitHub
commit 61ebc588fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View file

@ -125,14 +125,15 @@ func (m *GetResponse) NotFull() bool { return checkIsNotFull(m) }
func (m *PutRequest) NotFull() bool { return checkIsNotFull(m) } func (m *PutRequest) NotFull() bool { return checkIsNotFull(m) }
// CID returns container id value from object put request. // CID returns container id value from object put request.
func (m *PutRequest) CID() CID { func (m *PutRequest) CID() (cid CID) {
if header := m.GetHeader(); header != nil { if header := m.GetHeader(); header == nil {
if obj := header.GetObject(); obj != nil { return
} else if obj := header.GetObject(); obj == nil {
return
} else {
return obj.SystemHeader.CID return obj.SystemHeader.CID
} }
} }
return refs.CID{}
}
// CID returns container id value from object get request. // CID returns container id value from object get request.
func (m *GetRequest) CID() CID { return m.Address.CID } func (m *GetRequest) CID() CID { return m.Address.CID }

View file

@ -17,6 +17,7 @@ func TestRequest(t *testing.T) {
&GetRangeRequest{}, &GetRangeRequest{},
&GetRangeHashRequest{}, &GetRangeHashRequest{},
MakePutRequestHeader(nil, nil), MakePutRequestHeader(nil, nil),
MakePutRequestHeader(&Object{}, nil),
} }
types := []RequestType{ types := []RequestType{
@ -28,12 +29,13 @@ func TestRequest(t *testing.T) {
RequestRange, RequestRange,
RequestRangeHash, RequestRangeHash,
RequestPut, RequestPut,
RequestPut,
} }
for i := range cases { for i := range cases {
v := cases[i] v := cases[i]
t.Run(fmt.Sprintf("%T", v), func(t *testing.T) { t.Run(fmt.Sprintf("%T_%d", v, i), func(t *testing.T) {
require.NotPanics(t, func() { v.CID() }) require.NotPanics(t, func() { v.CID() })
require.Equal(t, types[i], v.Type()) require.Equal(t, types[i], v.Type())
}) })