Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pandeyabs committed Jan 30, 2024
1 parent 42c46fd commit da600dc
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/internal/m365/collection/groups/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ func (suite *ExportUnitSuite) TestStreamConversationPosts() {
},
expectItem: export.Item{
ID: "mir.data",
Name: "mir.eml",
Error: assert.AnError,
},
expectErr: assert.Error,
Expand Down Expand Up @@ -260,13 +259,13 @@ func (suite *ExportUnitSuite) TestStreamConversationPosts() {

test.expectErr(t, err, clues.ToCore(err))

assert.Equal(t, test.expectItem.ID, itm.ID, "item ID")
assert.Equal(t, test.expectItem.Name, itm.Name, "item name")

if err != nil {
return
}

assert.Equal(t, test.expectItem.ID, itm.ID, "item ID")
assert.Equal(t, test.expectItem.Name, itm.Name, "item name")

assert.NotNil(t, itm.Body, "body")

_, err = io.ReadAll(itm.Body)
Expand Down
83 changes: 83 additions & 0 deletions src/internal/m365/service/groups/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,86 @@ func (suite *ExportUnitSuite) TestExportRestoreCollections_libraries() {
expectedStats.UpdateResourceCount(path.FilesCategory)
assert.Equal(t, expectedStats.GetStats(), stats.GetStats(), "stats")
}

func (suite *ExportUnitSuite) TestExportRestoreCollections_ConversationPosts() {
t := suite.T()

ctx, flush := tester.NewContext(t)
defer flush()

var (
itemID = "itemID"
containerName = "convID"
content = groupMock.PostWithAttachments
body = io.NopCloser(bytes.NewBufferString(content))
exportCfg = control.ExportConfig{}
expectedPath = path.ConversationPostsCategory.HumanString() + "/" + containerName
expectedItems = []export.Item{
{
ID: itemID + ".data",
Name: itemID + ".eml",
// Body: body, not checked
},
}
)

p, err := path.Build("t", "pr", path.GroupsService, path.ConversationPostsCategory, false, containerName)
assert.NoError(t, err, "build path")

dcs := []data.RestoreCollection{
data.FetchRestoreCollection{
Collection: dataMock.Collection{
Path: p,
ItemData: []data.Item{
&dataMock.Item{
ItemID: itemID + ".data",
Reader: body,
},
},
},
FetchItemByNamer: finD{
id: itemID + ".meta",
key: "topic", name: itemID + ".meta",
},
},
}

stats := metrics.NewExportStats()

ecs, err := NewGroupsHandler(api.Client{}, nil).
ProduceExportCollections(
ctx,
int(version.Backup),
exportCfg,
dcs,
stats,
fault.New(true))
assert.NoError(t, err, "export collections error")
assert.Len(t, ecs, 1, "num of collections")

assert.Equal(t, expectedPath, ecs[0].BasePath(), "base dir")

fitems := []export.Item{}

size := 0

for item := range ecs[0].Items(ctx) {
b, err := io.ReadAll(item.Body)
assert.NoError(t, err, clues.ToCore(err))

// count up size for tests
size += len(b)

// have to nil out body, otherwise assert fails due to
// pointer memory location differences
item.Body = nil
fitems = append(fitems, item)
}

assert.Equal(t, expectedItems, fitems, "items")

expectedStats := metrics.NewExportStats()
expectedStats.UpdateBytes(path.ConversationPostsCategory, int64(size))
expectedStats.UpdateResourceCount(path.ConversationPostsCategory)
assert.Equal(t, expectedStats.GetStats(), stats.GetStats(), "stats")
}

0 comments on commit da600dc

Please sign in to comment.