diff --git a/object/service.go b/object/service.go index ab3bf5f6..45a8d4b1 100644 --- a/object/service.go +++ b/object/service.go @@ -125,13 +125,14 @@ func (m *GetResponse) NotFull() bool { return checkIsNotFull(m) } func (m *PutRequest) NotFull() bool { return checkIsNotFull(m) } // CID returns container id value from object put request. -func (m *PutRequest) CID() CID { - if header := m.GetHeader(); header != nil { - if obj := header.GetObject(); obj != nil { - return obj.SystemHeader.CID - } +func (m *PutRequest) CID() (cid CID) { + if header := m.GetHeader(); header == nil { + return + } else if obj := header.GetObject(); obj == nil { + return + } else { + return obj.SystemHeader.CID } - return refs.CID{} } // CID returns container id value from object get request. diff --git a/object/service_test.go b/object/service_test.go index f38e2ede..4b02b375 100644 --- a/object/service_test.go +++ b/object/service_test.go @@ -17,6 +17,7 @@ func TestRequest(t *testing.T) { &GetRangeRequest{}, &GetRangeHashRequest{}, MakePutRequestHeader(nil, nil), + MakePutRequestHeader(&Object{}, nil), } types := []RequestType{ @@ -28,12 +29,13 @@ func TestRequest(t *testing.T) { RequestRange, RequestRangeHash, RequestPut, + RequestPut, } for i := range cases { 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.Equal(t, types[i], v.Type()) })