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

Commit

Permalink
GC: CI: Streamline Tests and Reduction (#1082)
Browse files Browse the repository at this point in the history
* Reduction of duplicated tests.  Removal of tests that are checked in other functions.
  • Loading branch information
Danny authored Oct 7, 2022
1 parent e63b31b commit 0724db9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 126 deletions.
84 changes: 29 additions & 55 deletions src/internal/connector/exchange/exchange_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand 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
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
71 changes: 0 additions & 71 deletions src/internal/connector/graph_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0724db9

Please sign in to comment.