Use leaf test instance for assertions (#1848)
## Description For tests that run subtests, make sure to use the subtest instance of testing.T so that the error trace in the output is easier to read. ## Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No ## Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [x] 🤖 Test - [ ] 💻 CI/Deployment - [x] 🐹 Trivial/Minor ## Issue(s) * closes #1846 ## Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
07506eba22
commit
7a5a8c077e
@ -315,24 +315,23 @@ func (suite *ExchangeServiceSuite) TestRestoreEvent() {
|
|||||||
|
|
||||||
// TestRestoreExchangeObject verifies path.Category usage for restored objects
|
// TestRestoreExchangeObject verifies path.Category usage for restored objects
|
||||||
func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
||||||
t := suite.T()
|
service := loadService(suite.T())
|
||||||
service := loadService(t)
|
|
||||||
|
|
||||||
userID := tester.M365UserID(t)
|
userID := tester.M365UserID(suite.T())
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
bytes []byte
|
bytes []byte
|
||||||
category path.CategoryType
|
category path.CategoryType
|
||||||
cleanupFunc func(context.Context, graph.Servicer, string, string) error
|
cleanupFunc func(context.Context, graph.Servicer, string, string) error
|
||||||
destination func(context.Context) string
|
destination func(*testing.T, context.Context) string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Test Mail",
|
name: "Test Mail",
|
||||||
bytes: mockconnector.GetMockMessageBytes("Restore Exchange Object"),
|
bytes: mockconnector.GetMockMessageBytes("Restore Exchange Object"),
|
||||||
category: path.EmailCategory,
|
category: path.EmailCategory,
|
||||||
cleanupFunc: DeleteMailFolder,
|
cleanupFunc: DeleteMailFolder,
|
||||||
destination: func(ctx context.Context) string {
|
destination: func(t *testing.T, ctx context.Context) string {
|
||||||
folderName := "TestRestoreMailObject: " + common.FormatSimpleDateTime(now)
|
folderName := "TestRestoreMailObject: " + common.FormatSimpleDateTime(now)
|
||||||
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
|
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -345,7 +344,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
|||||||
bytes: mockconnector.GetMockMessageWithDirectAttachment("Restore 1 Attachment"),
|
bytes: mockconnector.GetMockMessageWithDirectAttachment("Restore 1 Attachment"),
|
||||||
category: path.EmailCategory,
|
category: path.EmailCategory,
|
||||||
cleanupFunc: DeleteMailFolder,
|
cleanupFunc: DeleteMailFolder,
|
||||||
destination: func(ctx context.Context) string {
|
destination: func(t *testing.T, ctx context.Context) string {
|
||||||
folderName := "TestRestoreMailwithAttachment: " + common.FormatSimpleDateTime(now)
|
folderName := "TestRestoreMailwithAttachment: " + common.FormatSimpleDateTime(now)
|
||||||
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
|
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -358,7 +357,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
|||||||
bytes: mockconnector.GetMockMessageWithLargeAttachment("Restore Large Attachment"),
|
bytes: mockconnector.GetMockMessageWithLargeAttachment("Restore Large Attachment"),
|
||||||
category: path.EmailCategory,
|
category: path.EmailCategory,
|
||||||
cleanupFunc: DeleteMailFolder,
|
cleanupFunc: DeleteMailFolder,
|
||||||
destination: func(ctx context.Context) string {
|
destination: func(t *testing.T, ctx context.Context) string {
|
||||||
folderName := "TestRestoreMailwithLargeAttachment: " + common.FormatSimpleDateTime(now)
|
folderName := "TestRestoreMailwithLargeAttachment: " + common.FormatSimpleDateTime(now)
|
||||||
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
|
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -371,7 +370,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
|||||||
bytes: mockconnector.GetMockMessageWithTwoAttachments("Restore 2 Attachments"),
|
bytes: mockconnector.GetMockMessageWithTwoAttachments("Restore 2 Attachments"),
|
||||||
category: path.EmailCategory,
|
category: path.EmailCategory,
|
||||||
cleanupFunc: DeleteMailFolder,
|
cleanupFunc: DeleteMailFolder,
|
||||||
destination: func(ctx context.Context) string {
|
destination: func(t *testing.T, ctx context.Context) string {
|
||||||
folderName := "TestRestoreMailwithAttachments: " + common.FormatSimpleDateTime(now)
|
folderName := "TestRestoreMailwithAttachments: " + common.FormatSimpleDateTime(now)
|
||||||
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
|
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -384,7 +383,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
|||||||
bytes: mockconnector.GetMessageWithOneDriveAttachment("Restore Reference(OneDrive) Attachment"),
|
bytes: mockconnector.GetMessageWithOneDriveAttachment("Restore Reference(OneDrive) Attachment"),
|
||||||
category: path.EmailCategory,
|
category: path.EmailCategory,
|
||||||
cleanupFunc: DeleteMailFolder,
|
cleanupFunc: DeleteMailFolder,
|
||||||
destination: func(ctx context.Context) string {
|
destination: func(t *testing.T, ctx context.Context) string {
|
||||||
folderName := "TestRestoreMailwithReferenceAttachment: " + common.FormatSimpleDateTime(now)
|
folderName := "TestRestoreMailwithReferenceAttachment: " + common.FormatSimpleDateTime(now)
|
||||||
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
|
folder, err := CreateMailFolder(ctx, suite.es, userID, folderName)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -398,7 +397,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
|||||||
bytes: mockconnector.GetMockContactBytes("Test_Omega"),
|
bytes: mockconnector.GetMockContactBytes("Test_Omega"),
|
||||||
category: path.ContactsCategory,
|
category: path.ContactsCategory,
|
||||||
cleanupFunc: DeleteContactFolder,
|
cleanupFunc: DeleteContactFolder,
|
||||||
destination: func(ctx context.Context) string {
|
destination: func(t *testing.T, ctx context.Context) string {
|
||||||
folderName := "TestRestoreContactObject: " + common.FormatSimpleDateTime(now)
|
folderName := "TestRestoreContactObject: " + common.FormatSimpleDateTime(now)
|
||||||
folder, err := CreateContactFolder(ctx, suite.es, userID, folderName)
|
folder, err := CreateContactFolder(ctx, suite.es, userID, folderName)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -411,7 +410,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
|||||||
bytes: mockconnector.GetDefaultMockEventBytes("Restored Event Object"),
|
bytes: mockconnector.GetDefaultMockEventBytes("Restored Event Object"),
|
||||||
category: path.EventsCategory,
|
category: path.EventsCategory,
|
||||||
cleanupFunc: DeleteCalendar,
|
cleanupFunc: DeleteCalendar,
|
||||||
destination: func(ctx context.Context) string {
|
destination: func(t *testing.T, ctx context.Context) string {
|
||||||
calendarName := "TestRestoreEventObject: " + common.FormatSimpleDateTime(now)
|
calendarName := "TestRestoreEventObject: " + common.FormatSimpleDateTime(now)
|
||||||
calendar, err := CreateCalendar(ctx, suite.es, userID, calendarName)
|
calendar, err := CreateCalendar(ctx, suite.es, userID, calendarName)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -424,7 +423,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
|||||||
bytes: mockconnector.GetMockEventWithAttachment("Restored Event Attachment"),
|
bytes: mockconnector.GetMockEventWithAttachment("Restored Event Attachment"),
|
||||||
category: path.EventsCategory,
|
category: path.EventsCategory,
|
||||||
cleanupFunc: DeleteCalendar,
|
cleanupFunc: DeleteCalendar,
|
||||||
destination: func(ctx context.Context) string {
|
destination: func(t *testing.T, ctx context.Context) string {
|
||||||
calendarName := "TestRestoreEventObject_" + common.FormatSimpleDateTime(now)
|
calendarName := "TestRestoreEventObject_" + common.FormatSimpleDateTime(now)
|
||||||
calendar, err := CreateCalendar(ctx, suite.es, userID, calendarName)
|
calendar, err := CreateCalendar(ctx, suite.es, userID, calendarName)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -439,7 +438,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
|||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
destination := test.destination(ctx)
|
destination := test.destination(t, ctx)
|
||||||
info, err := RestoreExchangeObject(
|
info, err := RestoreExchangeObject(
|
||||||
ctx,
|
ctx,
|
||||||
test.bytes,
|
test.bytes,
|
||||||
@ -464,21 +463,20 @@ func (suite *ExchangeServiceSuite) TestGetContainerIDFromCache() {
|
|||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
t = suite.T()
|
user = tester.M365UserID(suite.T())
|
||||||
user = tester.M365UserID(t)
|
connector = loadService(suite.T())
|
||||||
connector = loadService(t)
|
|
||||||
directoryCaches = make(map[path.CategoryType]graph.ContainerResolver)
|
directoryCaches = make(map[path.CategoryType]graph.ContainerResolver)
|
||||||
folderName = tester.DefaultTestRestoreDestination().ContainerName
|
folderName = tester.DefaultTestRestoreDestination().ContainerName
|
||||||
tests = []struct {
|
tests = []struct {
|
||||||
name string
|
name string
|
||||||
pathFunc1 func() path.Path
|
pathFunc1 func(t *testing.T) path.Path
|
||||||
pathFunc2 func() path.Path
|
pathFunc2 func(t *testing.T) path.Path
|
||||||
category path.CategoryType
|
category path.CategoryType
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Mail Cache Test",
|
name: "Mail Cache Test",
|
||||||
category: path.EmailCategory,
|
category: path.EmailCategory,
|
||||||
pathFunc1: func() path.Path {
|
pathFunc1: func(t *testing.T) path.Path {
|
||||||
pth, err := path.Builder{}.Append("Griffindor").
|
pth, err := path.Builder{}.Append("Griffindor").
|
||||||
Append("Croix").ToDataLayerExchangePathForCategory(
|
Append("Croix").ToDataLayerExchangePathForCategory(
|
||||||
suite.es.credentials.AzureTenantID,
|
suite.es.credentials.AzureTenantID,
|
||||||
@ -487,10 +485,10 @@ func (suite *ExchangeServiceSuite) TestGetContainerIDFromCache() {
|
|||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
|
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(t, err)
|
||||||
return pth
|
return pth
|
||||||
},
|
},
|
||||||
pathFunc2: func() path.Path {
|
pathFunc2: func(t *testing.T) path.Path {
|
||||||
pth, err := path.Builder{}.Append("Griffindor").
|
pth, err := path.Builder{}.Append("Griffindor").
|
||||||
Append("Felicius").ToDataLayerExchangePathForCategory(
|
Append("Felicius").ToDataLayerExchangePathForCategory(
|
||||||
suite.es.credentials.AzureTenantID,
|
suite.es.credentials.AzureTenantID,
|
||||||
@ -499,14 +497,14 @@ func (suite *ExchangeServiceSuite) TestGetContainerIDFromCache() {
|
|||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
|
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(t, err)
|
||||||
return pth
|
return pth
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Contact Cache Test",
|
name: "Contact Cache Test",
|
||||||
category: path.ContactsCategory,
|
category: path.ContactsCategory,
|
||||||
pathFunc1: func() path.Path {
|
pathFunc1: func(t *testing.T) path.Path {
|
||||||
aPath, err := path.Builder{}.Append("HufflePuff").
|
aPath, err := path.Builder{}.Append("HufflePuff").
|
||||||
ToDataLayerExchangePathForCategory(
|
ToDataLayerExchangePathForCategory(
|
||||||
suite.es.credentials.AzureTenantID,
|
suite.es.credentials.AzureTenantID,
|
||||||
@ -515,10 +513,10 @@ func (suite *ExchangeServiceSuite) TestGetContainerIDFromCache() {
|
|||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
|
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(t, err)
|
||||||
return aPath
|
return aPath
|
||||||
},
|
},
|
||||||
pathFunc2: func() path.Path {
|
pathFunc2: func(t *testing.T) path.Path {
|
||||||
aPath, err := path.Builder{}.Append("Ravenclaw").
|
aPath, err := path.Builder{}.Append("Ravenclaw").
|
||||||
ToDataLayerExchangePathForCategory(
|
ToDataLayerExchangePathForCategory(
|
||||||
suite.es.credentials.AzureTenantID,
|
suite.es.credentials.AzureTenantID,
|
||||||
@ -527,14 +525,14 @@ func (suite *ExchangeServiceSuite) TestGetContainerIDFromCache() {
|
|||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
|
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(t, err)
|
||||||
return aPath
|
return aPath
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Event Cache Test",
|
name: "Event Cache Test",
|
||||||
category: path.EventsCategory,
|
category: path.EventsCategory,
|
||||||
pathFunc1: func() path.Path {
|
pathFunc1: func(t *testing.T) path.Path {
|
||||||
aPath, err := path.Builder{}.Append("Durmstrang").
|
aPath, err := path.Builder{}.Append("Durmstrang").
|
||||||
ToDataLayerExchangePathForCategory(
|
ToDataLayerExchangePathForCategory(
|
||||||
suite.es.credentials.AzureTenantID,
|
suite.es.credentials.AzureTenantID,
|
||||||
@ -542,10 +540,10 @@ func (suite *ExchangeServiceSuite) TestGetContainerIDFromCache() {
|
|||||||
path.EventsCategory,
|
path.EventsCategory,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(t, err)
|
||||||
return aPath
|
return aPath
|
||||||
},
|
},
|
||||||
pathFunc2: func() path.Path {
|
pathFunc2: func(t *testing.T) path.Path {
|
||||||
aPath, err := path.Builder{}.Append("Beauxbatons").
|
aPath, err := path.Builder{}.Append("Beauxbatons").
|
||||||
ToDataLayerExchangePathForCategory(
|
ToDataLayerExchangePathForCategory(
|
||||||
suite.es.credentials.AzureTenantID,
|
suite.es.credentials.AzureTenantID,
|
||||||
@ -553,7 +551,7 @@ func (suite *ExchangeServiceSuite) TestGetContainerIDFromCache() {
|
|||||||
path.EventsCategory,
|
path.EventsCategory,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(t, err)
|
||||||
return aPath
|
return aPath
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -565,7 +563,7 @@ func (suite *ExchangeServiceSuite) TestGetContainerIDFromCache() {
|
|||||||
folderID, err := GetContainerIDFromCache(
|
folderID, err := GetContainerIDFromCache(
|
||||||
ctx,
|
ctx,
|
||||||
connector,
|
connector,
|
||||||
test.pathFunc1(),
|
test.pathFunc1(t),
|
||||||
folderName,
|
folderName,
|
||||||
directoryCaches,
|
directoryCaches,
|
||||||
)
|
)
|
||||||
@ -578,7 +576,7 @@ func (suite *ExchangeServiceSuite) TestGetContainerIDFromCache() {
|
|||||||
secondID, err := GetContainerIDFromCache(
|
secondID, err := GetContainerIDFromCache(
|
||||||
ctx,
|
ctx,
|
||||||
connector,
|
connector,
|
||||||
test.pathFunc2(),
|
test.pathFunc2(t),
|
||||||
folderName,
|
folderName,
|
||||||
directoryCaches,
|
directoryCaches,
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user