GC: CI: Streamline Tests and Reduction (#1082)

* Reduction of duplicated tests.  Removal of tests that are checked in other functions.
This commit is contained in:
Danny 2022-10-07 13:01:37 -04:00 committed by GitHub
parent e63b31b651
commit 0724db938c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 126 deletions

View File

@ -368,61 +368,9 @@ func (suite *ExchangeServiceSuite) TestGetContainerID() {
}
}
//==========================
// Restore Functions
// TestRestoreMessages uses mock data to ensure GraphConnector
// is able to restore a several messageable item to a Mailbox.
// The result should be all successful items restored within the same folder.
func (suite *ExchangeServiceSuite) TestRestoreMessages() {
var (
ctx = context.Background()
userID = tester.M365UserID(suite.T())
now = time.Now()
folderName = "TestRestoreMessage: " + common.FormatSimpleDateTime(now)
)
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
require.NoError(suite.T(), err)
folderID := *folder.GetId()
defer func() {
// Remove the folder containing message prior to exiting test
err = DeleteMailFolder(ctx, suite.es, userID, folderID)
assert.NoError(suite.T(), err, "Failure during folder clean-up")
}()
tests := []struct {
name string
bytes []byte
}{
{
name: "Simple Message",
bytes: mockconnector.GetMockMessageBytes(folderName),
},
{
name: "One Direct Attachment",
bytes: mockconnector.GetMockMessageWithDirectAttachment(folderName),
},
{
name: "Two Attachments",
bytes: mockconnector.GetMockMessageWithTwoAttachments(folderName),
},
}
for _, test := range tests {
suite.T().Run(test.name, func(t *testing.T) {
info, err := RestoreMailMessage(context.Background(),
test.bytes,
suite.es,
control.Copy,
folderID,
userID,
)
assert.NoError(t, err, support.ConnectorStackErrorTrace(err))
assert.NotNil(t, info, "message item info")
})
}
}
//======================
// TestRestoreContact ensures contact object can be created, placed into
// the Corso Folder. The function handles test clean-up.
@ -553,7 +501,6 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
ctx := context.Background()
t := suite.T()
userID := tester.M365UserID(t)
service := loadService(t)
now := time.Now()
tests := []struct {
name string
@ -575,6 +522,32 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
return *folder.GetId()
},
},
{
name: "Test Mail: One Direct Attachment",
bytes: mockconnector.GetMockMessageWithDirectAttachment("Restore 1 Attachment"),
category: path.EmailCategory,
cleanupFunc: DeleteMailFolder,
destination: func() string {
folderName := "TestRestoreMailwithAttachment: " + common.FormatSimpleDateTime(now)
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
require.NoError(t, err)
return *folder.GetId()
},
},
{
name: "Test Mail: Two Attachments",
bytes: mockconnector.GetMockMessageWithTwoAttachments("Restore 2 Attachments"),
category: path.EmailCategory,
cleanupFunc: DeleteMailFolder,
destination: func() string {
folderName := "TestRestoreMailwithAttachments: " + common.FormatSimpleDateTime(now)
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
require.NoError(t, err)
return *folder.GetId()
},
},
// TODO: #884 - reinstate when able to specify root folder by name
// {
// name: "Test Contact",
@ -606,6 +579,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
for _, test := range tests {
suite.T().Run(test.name, func(t *testing.T) {
service := loadService(t)
destination := test.destination()
info, err := RestoreExchangeObject(
ctx,

View File

@ -4,13 +4,11 @@ import (
"bytes"
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/common"
"github.com/alcionai/corso/src/internal/connector/exchange"
"github.com/alcionai/corso/src/internal/connector/mockconnector"
"github.com/alcionai/corso/src/internal/connector/support"
@ -305,75 +303,6 @@ func (suite *GraphConnectorIntegrationSuite) TestAccessOfInboxAllUsers() {
// Exchange Functions
//-------------------------------------------------------
// TestCreateAndDeleteMailFolder ensures GraphConnector has the ability
// to create and remove folders within the tenant
func (suite *GraphConnectorIntegrationSuite) TestCreateAndDeleteMailFolder() {
ctx := context.Background()
t := suite.T()
now := time.Now()
folderName := "TestFolder: " + common.FormatSimpleDateTime(now)
aFolder, err := exchange.CreateMailFolder(ctx, suite.connector.Service(), suite.user, folderName)
assert.NoError(t, err, support.ConnectorStackErrorTrace(err))
if aFolder != nil {
secondFolder, err := exchange.CreateMailFolderWithParent(
ctx,
suite.connector.Service(),
suite.user,
"SubFolder",
*aFolder.GetId(),
)
assert.NoError(t, err)
assert.True(t, *secondFolder.GetParentFolderId() == *aFolder.GetId())
err = exchange.DeleteMailFolder(ctx, suite.connector.Service(), suite.user, *aFolder.GetId())
assert.NoError(t, err)
if err != nil {
t.Log(support.ConnectorStackErrorTrace(err))
}
}
}
// TestCreateAndDeleteContactFolder ensures GraphConnector has the ability
// to create and remove contact folders within the tenant
func (suite *GraphConnectorIntegrationSuite) TestCreateAndDeleteContactFolder() {
ctx := context.Background()
now := time.Now()
folderName := "TestContactFolder: " + common.FormatSimpleDateTime(now)
aFolder, err := exchange.CreateContactFolder(ctx, suite.connector.Service(), suite.user, folderName)
assert.NoError(suite.T(), err)
if aFolder != nil {
err = exchange.DeleteContactFolder(ctx, suite.connector.Service(), suite.user, *aFolder.GetId())
assert.NoError(suite.T(), err)
if err != nil {
suite.T().Log(support.ConnectorStackErrorTrace(err))
}
}
}
// TestCreateAndDeleteCalendar verifies GraphConnector has the ability to create and remove
// exchange.Event.Calendars within the tenant
func (suite *GraphConnectorIntegrationSuite) TestCreateAndDeleteCalendar() {
ctx := context.Background()
now := time.Now()
service := suite.connector.Service()
calendarName := "TestCalendar: " + common.FormatSimpleDateTime(now)
calendar, err := exchange.CreateCalendar(ctx, service, suite.user, calendarName)
assert.NoError(suite.T(), err)
if calendar != nil {
err = exchange.DeleteCalendar(ctx, service, suite.user, *calendar.GetId())
assert.NoError(suite.T(), err)
if err != nil {
suite.T().Log(support.ConnectorStackErrorTrace(err))
}
}
}
func (suite *GraphConnectorIntegrationSuite) TestEmptyCollections() {
dest := tester.DefaultTestRestoreDestination()
table := []struct {