Add size to all objects (#1491)

## Description
Add size to all objects. Not adding them to the output of details view.

## Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [x] 🐹 Trivial/Minor

## Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic
words" - "closes, fixes" to auto-close the Github issue. -->
* https://github.com/alcionai/corso/issues/1366

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Abin Simon 2022-11-15 17:34:25 +05:30 committed by GitHub
parent 44735d6044
commit 110684d5f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 30 additions and 15 deletions

View File

@ -9,7 +9,7 @@ import (
) )
// ContactInfo translate models.Contactable metadata into searchable content // ContactInfo translate models.Contactable metadata into searchable content
func ContactInfo(contact models.Contactable) *details.ExchangeInfo { func ContactInfo(contact models.Contactable, size int64) *details.ExchangeInfo {
name := "" name := ""
created := time.Time{} created := time.Time{}
modified := time.Time{} modified := time.Time{}
@ -31,5 +31,6 @@ func ContactInfo(contact models.Contactable) *details.ExchangeInfo {
ContactName: name, ContactName: name,
Created: created, Created: created,
Modified: modified, Modified: modified,
Size: size,
} }
} }

View File

@ -37,6 +37,7 @@ func (suite *ContactSuite) TestContactInfo() {
ItemType: details.ExchangeContact, ItemType: details.ExchangeContact,
Created: initial, Created: initial,
Modified: initial, Modified: initial,
Size: 10,
} }
return contact, i return contact, i
}, },
@ -53,6 +54,7 @@ func (suite *ContactSuite) TestContactInfo() {
ContactName: aPerson, ContactName: aPerson,
Created: initial, Created: initial,
Modified: initial, Modified: initial,
Size: 10,
} }
return contact, i return contact, i
}, },
@ -61,7 +63,7 @@ func (suite *ContactSuite) TestContactInfo() {
for _, test := range tests { for _, test := range tests {
suite.T().Run(test.name, func(t *testing.T) { suite.T().Run(test.name, func(t *testing.T) {
contact, expected := test.contactAndRP() contact, expected := test.contactAndRP()
assert.Equal(t, expected, ContactInfo(contact)) assert.Equal(t, expected, ContactInfo(contact, 10))
}) })
} }
} }

View File

@ -10,7 +10,7 @@ import (
) )
// EventInfo searchable metadata for stored event objects. // EventInfo searchable metadata for stored event objects.
func EventInfo(evt models.Eventable) *details.ExchangeInfo { func EventInfo(evt models.Eventable, size int64) *details.ExchangeInfo {
var ( var (
organizer, subject string organizer, subject string
recurs bool recurs bool
@ -77,5 +77,6 @@ func EventInfo(evt models.Eventable) *details.ExchangeInfo {
EventRecurs: recurs, EventRecurs: recurs,
Created: created, Created: created,
Modified: modified, Modified: modified,
Size: size,
} }
} }

View File

@ -134,6 +134,7 @@ func (suite *EventSuite) TestEventInfo() {
Organizer: organizer, Organizer: organizer,
EventStart: eventTime, EventStart: eventTime,
EventEnd: eventEndTime, EventEnd: eventEndTime,
Size: 10,
} }
}, },
}, },
@ -141,7 +142,7 @@ func (suite *EventSuite) TestEventInfo() {
for _, test := range tests { for _, test := range tests {
suite.T().Run(test.name, func(t *testing.T) { suite.T().Run(test.name, func(t *testing.T) {
event, expected := test.evtAndRP() event, expected := test.evtAndRP()
result := EventInfo(event) result := EventInfo(event, 10)
assert.Equal(t, expected.Subject, result.Subject, "subject") assert.Equal(t, expected.Subject, result.Subject, "subject")
assert.Equal(t, expected.Sender, result.Sender, "sender") assert.Equal(t, expected.Sender, result.Sender, "sender")

View File

@ -256,7 +256,7 @@ func eventToDataCollection(
} }
if len(byteArray) > 0 { if len(byteArray) > 0 {
dataChannel <- &Stream{id: *event.GetId(), message: byteArray, info: EventInfo(event)} dataChannel <- &Stream{id: *event.GetId(), message: byteArray, info: EventInfo(event, int64(len(byteArray)))}
} }
return len(byteArray), nil return len(byteArray), nil
@ -289,7 +289,7 @@ func contactToDataCollection(
} }
if len(byteArray) > 0 { if len(byteArray) > 0 {
dataChannel <- &Stream{id: *contact.GetId(), message: byteArray, info: ContactInfo(contact)} dataChannel <- &Stream{id: *contact.GetId(), message: byteArray, info: ContactInfo(contact, int64(len(byteArray)))}
} }
return len(byteArray), nil return len(byteArray), nil
@ -356,7 +356,7 @@ func messageToDataCollection(
return 0, support.SetNonRecoverableError(err) return 0, support.SetNonRecoverableError(err)
} }
dataChannel <- &Stream{id: *aMessage.GetId(), message: byteArray, info: MessageInfo(aMessage)} dataChannel <- &Stream{id: *aMessage.GetId(), message: byteArray, info: MessageInfo(aMessage, int64(len(byteArray)))}
return len(byteArray), nil return len(byteArray), nil
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/backup/details"
) )
func MessageInfo(msg models.Messageable) *details.ExchangeInfo { func MessageInfo(msg models.Messageable, size int64) *details.ExchangeInfo {
sender := "" sender := ""
subject := "" subject := ""
received := time.Time{} received := time.Time{}
@ -44,5 +44,6 @@ func MessageInfo(msg models.Messageable) *details.ExchangeInfo {
Received: received, Received: received,
Created: created, Created: created,
Modified: modified, Modified: modified,
Size: size,
} }
} }

View File

@ -36,6 +36,7 @@ func (suite *MessageSuite) TestMessageInfo() {
ItemType: details.ExchangeMail, ItemType: details.ExchangeMail,
Created: initial, Created: initial,
Modified: initial, Modified: initial,
Size: 10,
} }
return msg, i return msg, i
}, },
@ -57,6 +58,7 @@ func (suite *MessageSuite) TestMessageInfo() {
Sender: sender, Sender: sender,
Created: initial, Created: initial,
Modified: initial, Modified: initial,
Size: 10,
} }
return msg, i return msg, i
}, },
@ -74,6 +76,7 @@ func (suite *MessageSuite) TestMessageInfo() {
Subject: subject, Subject: subject,
Created: initial, Created: initial,
Modified: initial, Modified: initial,
Size: 10,
} }
return msg, i return msg, i
}, },
@ -91,6 +94,7 @@ func (suite *MessageSuite) TestMessageInfo() {
Received: now, Received: now,
Created: initial, Created: initial,
Modified: initial, Modified: initial,
Size: 10,
} }
return msg, i return msg, i
}, },
@ -118,6 +122,7 @@ func (suite *MessageSuite) TestMessageInfo() {
Received: now, Received: now,
Created: initial, Created: initial,
Modified: initial, Modified: initial,
Size: 10,
} }
return msg, i return msg, i
}, },
@ -126,7 +131,7 @@ func (suite *MessageSuite) TestMessageInfo() {
for _, tt := range tests { for _, tt := range tests {
suite.T().Run(tt.name, func(t *testing.T) { suite.T().Run(tt.name, func(t *testing.T) {
msg, expected := tt.msgAndRP() msg, expected := tt.msgAndRP()
suite.Equal(expected, MessageInfo(msg)) suite.Equal(expected, MessageInfo(msg, 10))
}) })
} }
} }

View File

@ -84,7 +84,7 @@ func RestoreExchangeContact(
return nil, errors.New("msgraph contact post fail: REST response not received") return nil, errors.New("msgraph contact post fail: REST response not received")
} }
return ContactInfo(contact), nil return ContactInfo(contact, int64(len(bits))), nil
} }
// RestoreExchangeEvent restores a contact to the @bits byte // RestoreExchangeEvent restores a contact to the @bits byte
@ -153,7 +153,7 @@ func RestoreExchangeEvent(
} }
} }
return EventInfo(event), errs return EventInfo(event, int64(len(bits))), errs
} }
// RestoreMailMessage utility function to place an exchange.Mail // RestoreMailMessage utility function to place an exchange.Mail
@ -215,7 +215,7 @@ func RestoreMailMessage(
} }
} }
return MessageInfo(clone), nil return MessageInfo(clone, int64(len(bits))), nil
} }
// attachmentBytes is a helper to retrieve the attachment content from a models.Attachmentable // attachmentBytes is a helper to retrieve the attachment content from a models.Attachmentable

View File

@ -71,7 +71,7 @@ func (suite *SharePointCollectionSuite) TestSharePointListCollection() {
col.data <- &Item{ col.data <- &Item{
id: testName, id: testName,
data: io.NopCloser(bytes.NewReader(byteArray)), data: io.NopCloser(bytes.NewReader(byteArray)),
info: sharePointListInfo(listing), info: sharePointListInfo(listing, int64(len(byteArray))),
} }
col.finishPopulation(ctx, 0, 0, nil) col.finishPopulation(ctx, 0, 0, nil)

View File

@ -10,7 +10,7 @@ import (
// sharePointListInfo translates models.Listable metadata into searchable content // sharePointListInfo translates models.Listable metadata into searchable content
// List Details: https://learn.microsoft.com/en-us/graph/api/resources/list?view=graph-rest-1.0 // List Details: https://learn.microsoft.com/en-us/graph/api/resources/list?view=graph-rest-1.0
func sharePointListInfo(lst models.Listable) *details.SharePointInfo { func sharePointListInfo(lst models.Listable, size int64) *details.SharePointInfo {
var ( var (
name, webURL string name, webURL string
created, modified time.Time created, modified time.Time
@ -38,5 +38,6 @@ func sharePointListInfo(lst models.Listable) *details.SharePointInfo {
Created: created, Created: created,
Modified: modified, Modified: modified,
WebURL: webURL, WebURL: webURL,
Size: size,
} }
} }

View File

@ -38,6 +38,7 @@ func (suite *SharePointInfoSuite) TestSharePointInfo() {
i := &details.SharePointInfo{ i := &details.SharePointInfo{
ItemType: details.SharePointItem, ItemType: details.SharePointItem,
ItemName: aTitle, ItemName: aTitle,
Size: 10,
} }
return listing, i return listing, i
}, },
@ -46,7 +47,7 @@ func (suite *SharePointInfoSuite) TestSharePointInfo() {
for _, test := range tests { for _, test := range tests {
suite.T().Run(test.name, func(t *testing.T) { suite.T().Run(test.name, func(t *testing.T) {
list, expected := test.listAndRP() list, expected := test.listAndRP()
info := sharePointListInfo(list) info := sharePointListInfo(list, 10)
assert.Equal(t, expected.ItemType, info.ItemType) assert.Equal(t, expected.ItemType, info.ItemType)
assert.Equal(t, expected.ItemName, info.ItemName) assert.Equal(t, expected.ItemName, info.ItemName)
assert.Equal(t, expected.WebURL, info.WebURL) assert.Equal(t, expected.WebURL, info.WebURL)

View File

@ -304,6 +304,7 @@ type ExchangeInfo struct {
EventRecurs bool `json:"eventRecurs,omitempty"` EventRecurs bool `json:"eventRecurs,omitempty"`
Created time.Time `json:"created,omitempty"` Created time.Time `json:"created,omitempty"`
Modified time.Time `json:"modified,omitempty"` Modified time.Time `json:"modified,omitempty"`
Size int64 `json:"size,omitempty"`
} }
// Headers returns the human-readable names of properties in an ExchangeInfo // Headers returns the human-readable names of properties in an ExchangeInfo
@ -356,6 +357,7 @@ type SharePointInfo struct {
Created time.Time `json:"created,omitempty"` Created time.Time `json:"created,omitempty"`
Modified time.Time `josn:"modified,omitempty"` Modified time.Time `josn:"modified,omitempty"`
WebURL string `json:"webUrl,omitempty"` WebURL string `json:"webUrl,omitempty"`
Size int64 `json:"size,omitempty"`
} }
// Headers returns the human-readable names of properties in a SharePointInfo // Headers returns the human-readable names of properties in a SharePointInfo