Add Upsert store tests

This commit is contained in:
Jože Fortun
2020-09-24 11:08:40 +02:00
parent 2bfa26ff9c
commit fa3220388a
10 changed files with 385 additions and 73 deletions
+27 -10
View File
@@ -42,8 +42,7 @@ func testApplications(t *testing.T, s store.Applications) {
})
t.Run("lookup by ID", func(t *testing.T) {
application := makeNew("look up by id")
req.NoError(s.CreateApplication(ctx, application))
req, application := truncAndCreate(t)
fetched, err := s.LookupApplicationByID(ctx, application.ID)
req.NoError(err)
req.Equal(application.Name, fetched.Name)
@@ -54,15 +53,9 @@ func testApplications(t *testing.T, s store.Applications) {
})
t.Run("update", func(t *testing.T) {
application := makeNew("update me")
req.NoError(s.CreateApplication(ctx, application))
req, application := truncAndCreate(t)
application.Name = "ApplicationCRUD+2"
application = &types.Application{
ID: application.ID,
CreatedAt: application.CreatedAt,
Name: "ApplicationCRUD+2",
Unify: application.Unify,
}
req.NoError(s.UpdateApplication(ctx, application))
updated, err := s.LookupApplicationByID(ctx, application.ID)
@@ -70,6 +63,30 @@ func testApplications(t *testing.T, s store.Applications) {
req.Equal(application.Name, updated.Name)
})
t.Run("upsert", func(t *testing.T) {
t.Run("existing", func(t *testing.T) {
req, application := truncAndCreate(t)
application.Name = "ApplicationCRUD+2"
req.NoError(s.UpsertApplication(ctx, application))
updated, err := s.LookupApplicationByID(ctx, application.ID)
req.NoError(err)
req.Equal(application.Name, updated.Name)
})
t.Run("new", func(t *testing.T) {
application := makeNew("upsert me")
application.Name = "ComposeChartCRUD+2"
req.NoError(s.UpsertApplication(ctx, application))
upserted, err := s.LookupApplicationByID(ctx, application.ID)
req.NoError(err)
req.Equal(application.Name, upserted.Name)
})
})
t.Run("delete", func(t *testing.T) {
t.Run("by Application", func(t *testing.T) {
req, application := truncAndCreate(t)
+34 -12
View File
@@ -58,7 +58,6 @@ func testAttachment(t *testing.T, s store.Attachments) {
t.Run("lookup by ID", func(t *testing.T) {
req, att := truncAndCreate(t)
fetched, err := s.LookupAttachmentByID(ctx, att.ID)
req.NoError(err)
req.Equal(att.ID, fetched.ID)
@@ -77,6 +76,29 @@ func testAttachment(t *testing.T, s store.Attachments) {
req.Equal("url", fetched.Url)
})
t.Run("upsert", func(t *testing.T) {
t.Run("existing", func(t *testing.T) {
req, att := truncAndCreate(t)
att.Url = "url"
req.NoError(s.UpsertAttachment(ctx, att))
upserted, err := s.LookupAttachmentByID(ctx, att.ID)
req.NoError(err)
req.Equal(att.Name, upserted.Name)
})
t.Run("new", func(t *testing.T) {
att := makeNew("upsert me", "upsert-me")
req.NoError(s.UpsertAttachment(ctx, att))
upserted, err := s.LookupAttachmentByID(ctx, att.ID)
req.NoError(err)
req.Equal(att.Name, upserted.Name)
})
})
t.Run("delete", func(t *testing.T) {
t.Run("by Attachment", func(t *testing.T) {
req, att := truncAndCreate(t)
@@ -103,19 +125,19 @@ func testAttachment(t *testing.T, s store.Attachments) {
req.Len(set, 1)
})
// t.Run("with check", func(t *testing.T) {
// req, prefill := truncAndFill(t, 5)
t.Run("with check", func(t *testing.T) {
req, prefill := truncAndFill(t, 5)
// set, _, err := s.SearchAttachments(ctx, types.AttachmentFilter{
// Check: func(attachment *types.Attachment) (bool, error) {
// return attachment.Kind == prefill[0].Kind, nil
// },
// })
set, _, err := s.SearchAttachments(ctx, types.AttachmentFilter{
Check: func(attachment *types.Attachment) (bool, error) {
return attachment.Kind == prefill[0].Kind, nil
},
})
// req.NoError(err)
// req.Len(set, 1)
// req.Equal(prefill[0].Kind, set[0].Kind)
// })
req.NoError(err)
req.Len(set, 1)
req.Equal(prefill[0].Kind, set[0].Kind)
})
})
t.Run("ordered search", func(t *testing.T) {
+24 -5
View File
@@ -76,12 +76,8 @@ func testComposeCharts(t *testing.T, s store.Storer) {
t.Run("update", func(t *testing.T) {
req, composeChart := truncAndCreate(t)
composeChart.Name = "ComposeChartCRUD+2"
composeChart = &types.Chart{
ID: composeChart.ID,
CreatedAt: composeChart.CreatedAt,
Name: "ComposeChartCRUD+2",
}
req.NoError(s.UpdateComposeChart(ctx, composeChart))
updated, err := s.LookupComposeChartByID(ctx, composeChart.ID)
@@ -93,6 +89,29 @@ func testComposeCharts(t *testing.T, s store.Storer) {
t.Skip("not implemented")
})
t.Run("upsert", func(t *testing.T) {
t.Run("existing", func(t *testing.T) {
req, composeChart := truncAndCreate(t)
composeChart.Name = "ComposeChartCRUD+2"
req.NoError(s.UpsertComposeChart(ctx, composeChart))
upserted, err := s.LookupComposeChartByID(ctx, composeChart.ID)
req.NoError(err)
req.Equal(composeChart.Name, upserted.Name)
})
t.Run("new", func(t *testing.T) {
composeChart := makeNew("upsert me", "upsert-me")
composeChart.Name = "ComposeChartCRUD+2"
req.NoError(s.UpsertComposeChart(ctx, composeChart))
upserted, err := s.LookupComposeChartByID(ctx, composeChart.ID)
req.NoError(err)
req.Equal(composeChart.Name, upserted.Name)
})
})
t.Run("delete", func(t *testing.T) {
t.Run("by Chart", func(t *testing.T) {
+41 -8
View File
@@ -14,6 +14,7 @@ import (
func testComposeModuleFields(t *testing.T, s store.ComposeModuleFields) {
var (
ctx = context.Background()
req = require.New(t)
moduleID = id.Next()
@@ -50,23 +51,55 @@ func testComposeModuleFields(t *testing.T, s store.ComposeModuleFields) {
t.Skip("not implemented")
})
t.Run("lookup by Module ID, Name", func(t *testing.T) {
req, composeModuleField := truncAndCreate(t)
fetched, err := s.LookupComposeModuleFieldByModuleIDName(ctx, composeModuleField.ModuleID, composeModuleField.Name)
req.NoError(err)
req.Equal(composeModuleField.Name, fetched.Name)
req.Equal(composeModuleField.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
})
t.Run("update", func(t *testing.T) {
req := require.New(t)
composeModuleField := makeNew("update me", "update-me")
req.NoError(s.CreateComposeModuleField(ctx, composeModuleField))
req, composeModuleField := truncAndCreate(t)
composeModuleField.Name = "ComposeModuleFieldCRUD+2"
composeModuleField = &types.ModuleField{
ID: composeModuleField.ID,
CreatedAt: composeModuleField.CreatedAt,
Name: "ComposeModuleFieldCRUD+2",
}
req.NoError(s.UpdateComposeModuleField(ctx, composeModuleField))
updated, err := s.LookupComposeModuleFieldByModuleIDName(ctx, composeModuleField.ModuleID, composeModuleField.Name)
req.NoError(err)
req.Equal(composeModuleField.Name, updated.Name)
})
t.Run("update with duplicate handle", func(t *testing.T) {
t.Skip("not implemented")
})
t.Run("upsert", func(t *testing.T) {
t.Run("existing", func(t *testing.T) {
req, composeModuleField := truncAndCreate(t)
composeModuleField.Name = "ComposeModuleFieldCRUD+2"
req.NoError(s.UpsertComposeModuleField(ctx, composeModuleField))
upserted, err := s.LookupComposeModuleFieldByModuleIDName(ctx, composeModuleField.ModuleID, composeModuleField.Name)
req.NoError(err)
req.Equal(composeModuleField.Name, upserted.Name)
})
t.Run("new", func(t *testing.T) {
composeModuleField := makeNew("upsert me", "upsert-me")
composeModuleField.Name = "ComposeModuleFieldCRUD+3"
req.NoError(s.UpsertComposeModuleField(ctx, composeModuleField))
upserted, err := s.LookupComposeModuleFieldByModuleIDName(ctx, composeModuleField.ModuleID, composeModuleField.Name)
req.NoError(err)
req.Equal(composeModuleField.Name, upserted.Name)
})
})
t.Run("delete", func(t *testing.T) {
t.Run("by Field", func(t *testing.T) {
+62 -17
View File
@@ -48,27 +48,48 @@ func testComposeModules(t *testing.T, s store.ComposeModules) {
t.Skip("not implemented")
})
t.Run("lookup by ID", func(t *testing.T) {
composeModule := makeNew("look up by id", "look-up-by-id")
req.NoError(s.CreateComposeModule(ctx, composeModule))
fetched, err := s.LookupComposeModuleByID(ctx, composeModule.ID)
req.NoError(err)
req.Equal(composeModule.Name, fetched.Name)
req.Equal(composeModule.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
t.Run("lookup", func(t *testing.T) {
t.Run("by ID", func(t *testing.T) {
composeModule := makeNew("look up by id", "look-up-by-id")
req.NoError(s.CreateComposeModule(ctx, composeModule))
fetched, err := s.LookupComposeModuleByID(ctx, composeModule.ID)
req.NoError(err)
req.Equal(composeModule.Name, fetched.Name)
req.Equal(composeModule.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
})
t.Run("by NamespaceID, Name", func(t *testing.T) {
composeModule := makeNew("look up by namespaceIDName", "look-up-by-namespaceIDName")
req.NoError(s.CreateComposeModule(ctx, composeModule))
fetched, err := s.LookupComposeModuleByNamespaceIDName(ctx, composeModule.NamespaceID, composeModule.Name)
req.NoError(err)
req.Equal(composeModule.Name, fetched.Name)
req.Equal(composeModule.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
})
t.Run("by Handle", func(t *testing.T) {
composeModule := makeNew("look up by namespaceIDHandle", "look-up-by-namespaceIDHandle")
req.NoError(s.CreateComposeModule(ctx, composeModule))
fetched, err := s.LookupComposeModuleByNamespaceIDHandle(ctx, composeModule.NamespaceID, composeModule.Handle)
req.NoError(err)
req.Equal(composeModule.Name, fetched.Name)
req.Equal(composeModule.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
})
})
t.Run("update", func(t *testing.T) {
composeModule := makeNew("update me", "update-me")
req.NoError(s.CreateComposeModule(ctx, composeModule))
req, composeModule := truncAndCreate(t)
composeModule.Name = "ComposeModuleCRUD+2"
composeModule = &types.Module{
ID: composeModule.ID,
CreatedAt: composeModule.CreatedAt,
Name: "ComposeModuleCRUD+2",
}
req.NoError(s.UpdateComposeModule(ctx, composeModule))
updated, err := s.LookupComposeModuleByID(ctx, composeModule.ID)
@@ -80,6 +101,30 @@ func testComposeModules(t *testing.T, s store.ComposeModules) {
t.Skip("not implemented")
})
t.Run("upsert", func(t *testing.T) {
t.Run("existing", func(t *testing.T) {
req, composeModule := truncAndCreate(t)
composeModule.Name = "ComposeModuleCRUD+2"
req.NoError(s.UpsertComposeModule(ctx, composeModule))
updated, err := s.LookupComposeModuleByID(ctx, composeModule.ID)
req.NoError(err)
req.Equal(composeModule.Name, updated.Name)
})
t.Run("new", func(t *testing.T) {
composeModule := makeNew("upsert me", "upsert-me")
composeModule.Name = "ComposeChartCRUD+2"
req.NoError(s.UpsertComposeModule(ctx, composeModule))
upserted, err := s.LookupComposeModuleByID(ctx, composeModule.ID)
req.NoError(err)
req.Equal(composeModule.Name, upserted.Name)
})
})
t.Run("delete", func(t *testing.T) {
t.Run("by Module", func(t *testing.T) {
req, composeModule := truncAndCreate(t)
+46 -10
View File
@@ -45,16 +45,28 @@ func testComposeNamespaces(t *testing.T, s store.ComposeNamespaces) {
t.Skip("not implemented")
})
t.Run("lookup by ID", func(t *testing.T) {
composeNamespace := makeNew("look up by id", "look-up-by-id")
req.NoError(s.CreateComposeNamespace(ctx, composeNamespace))
fetched, err := s.LookupComposeNamespaceByID(ctx, composeNamespace.ID)
req.NoError(err)
req.Equal(composeNamespace.Name, fetched.Name)
req.Equal(composeNamespace.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
t.Run("lookup", func(t *testing.T) {
t.Run("by ID", func(t *testing.T) {
req, composeNamespace := truncAndCreate(t)
fetched, err := s.LookupComposeNamespaceByID(ctx, composeNamespace.ID)
req.NoError(err)
req.Equal(composeNamespace.Name, fetched.Name)
req.Equal(composeNamespace.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
})
t.Run("by Slug", func(t *testing.T) {
req, composeNamespace := truncAndCreate(t)
fetched, err := s.LookupComposeNamespaceBySlug(ctx, composeNamespace.Slug)
req.NoError(err)
req.Equal(composeNamespace.Name, fetched.Name)
req.Equal(composeNamespace.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
})
})
t.Run("update", func(t *testing.T) {
@@ -77,6 +89,30 @@ func testComposeNamespaces(t *testing.T, s store.ComposeNamespaces) {
t.Skip("not implemented")
})
t.Run("upsert", func(t *testing.T) {
t.Run("existing", func(t *testing.T) {
req, composeNamespace := truncAndCreate(t)
composeNamespace.Name = "ComposeNamespaceCRUD+2"
req.NoError(s.UpsertComposeNamespace(ctx, composeNamespace))
upserted, err := s.LookupComposeNamespaceByID(ctx, composeNamespace.ID)
req.NoError(err)
req.Equal(composeNamespace.Name, upserted.Name)
})
t.Run("new", func(t *testing.T) {
composeNamespace := makeNew("upsert me", "upsert-me")
composeNamespace.Name = "ComposeNamespaceCRUD+3"
req.NoError(s.UpsertComposeNamespace(ctx, composeNamespace))
upserted, err := s.LookupComposeNamespaceByID(ctx, composeNamespace.ID)
req.NoError(err)
req.Equal(composeNamespace.Name, upserted.Name)
})
})
t.Run("delete", func(t *testing.T) {
t.Run("by Namespace", func(t *testing.T) {
req, composeNamespace := truncAndCreate(t)
+59 -10
View File
@@ -18,12 +18,14 @@ func testComposePages(t *testing.T, s store.ComposePages) {
req = require.New(t)
namespaceID = id.Next()
moduleID = id.Next()
makeNew = func(title, handle string) *types.Page {
// minimum data set for new composePage
return &types.Page{
ID: id.Next(),
NamespaceID: namespaceID,
ModuleID: moduleID,
CreatedAt: time.Now(),
Title: title,
Handle: handle,
@@ -48,16 +50,39 @@ func testComposePages(t *testing.T, s store.ComposePages) {
t.Skip("not implemented")
})
t.Run("lookup by ID", func(t *testing.T) {
composePage := makeNew("look up by id", "look-up-by-id")
req.NoError(s.CreateComposePage(ctx, composePage))
fetched, err := s.LookupComposePageByID(ctx, composePage.ID)
req.NoError(err)
req.Equal(composePage.Title, fetched.Title)
req.Equal(composePage.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
t.Run("lookup", func(t *testing.T) {
t.Run("lookup by ID", func(t *testing.T) {
req, composePage := truncAndCreate(t)
fetched, err := s.LookupComposePageByID(ctx, composePage.ID)
req.NoError(err)
req.Equal(composePage.Title, fetched.Title)
req.Equal(composePage.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
})
t.Run("lookup by NamespaceID, ModuleID", func(t *testing.T) {
req, composePage := truncAndCreate(t)
fetched, err := s.LookupComposePageByNamespaceIDModuleID(ctx, composePage.NamespaceID, composePage.ModuleID)
req.NoError(err)
req.Equal(composePage.Title, fetched.Title)
req.Equal(composePage.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
})
t.Run("lookup by NamespaceID, Handle", func(t *testing.T) {
req, composePage := truncAndCreate(t)
fetched, err := s.LookupComposePageByNamespaceIDHandle(ctx, composePage.NamespaceID, composePage.Handle)
req.NoError(err)
req.Equal(composePage.Title, fetched.Title)
req.Equal(composePage.ID, fetched.ID)
req.NotNil(fetched.CreatedAt)
req.Nil(fetched.UpdatedAt)
req.Nil(fetched.DeletedAt)
})
})
t.Run("update", func(t *testing.T) {
@@ -80,6 +105,30 @@ func testComposePages(t *testing.T, s store.ComposePages) {
t.Skip("not implemented")
})
t.Run("upsert", func(t *testing.T) {
t.Run("existing", func(t *testing.T) {
req, composePage := truncAndCreate(t)
composePage.Title = "ComposePageCRUD+2"
req.NoError(s.UpsertComposePage(ctx, composePage))
upserted, err := s.LookupComposePageByID(ctx, composePage.ID)
req.NoError(err)
req.Equal(composePage.Title, upserted.Title)
})
t.Run("new", func(t *testing.T) {
composePage := makeNew("upsert me", "upsert-me")
composePage.Title = "ComposePageCRUD+2"
req.NoError(s.UpsertComposePage(ctx, composePage))
upserted, err := s.LookupComposePageByID(ctx, composePage.ID)
req.NoError(err)
req.Equal(composePage.Title, upserted.Title)
})
})
t.Run("delete", func(t *testing.T) {
t.Run("by Page", func(t *testing.T) {
req, composePage := truncAndCreate(t)
+24 -1
View File
@@ -14,6 +14,7 @@ import (
func testMessagingAttachments(t *testing.T, s store.MessagingAttachments) {
var (
ctx = context.Background()
req = require.New(t)
makeNew = func(nn ...string) *types.Attachment {
// minimum data set for new attachment
@@ -45,7 +46,6 @@ func testMessagingAttachments(t *testing.T, s store.MessagingAttachments) {
t.Run("lookup by ID", func(t *testing.T) {
req, att := truncAndCreate(t)
fetched, err := s.LookupMessagingAttachmentByID(ctx, att.ID)
req.NoError(err)
req.Equal(att.ID, fetched.ID)
@@ -62,7 +62,30 @@ func testMessagingAttachments(t *testing.T, s store.MessagingAttachments) {
req.NoError(err)
req.Equal(att.ID, fetched.ID)
req.Equal("url", fetched.Url)
})
t.Run("upsert", func(t *testing.T) {
t.Run("existing", func(t *testing.T) {
req, att := truncAndCreate(t)
att.Name = "MessagingAttachmentCRUD+2"
req.NoError(s.UpsertMessagingAttachment(ctx, att))
upserted, err := s.LookupMessagingAttachmentByID(ctx, att.ID)
req.NoError(err)
req.Equal(att.Name, upserted.Name)
})
t.Run("new", func(t *testing.T) {
att := makeNew("upsert me", "upsert-me")
att.Name = "MessagingAttachmentCRUD+2"
req.NoError(s.UpsertMessagingAttachment(ctx, att))
upserted, err := s.LookupMessagingAttachmentByID(ctx, att.ID)
req.NoError(err)
req.Equal(att.Name, upserted.Name)
})
})
t.Run("delete", func(t *testing.T) {
@@ -13,6 +13,7 @@ import (
func testMessagingChannelMembers(t *testing.T, s store.MessagingChannelMembers) {
var (
ctx = context.Background()
req = require.New(t)
channelID = id.Next()
userID = id.Next()
@@ -46,6 +47,42 @@ func testMessagingChannelMembers(t *testing.T, s store.MessagingChannelMembers)
req.NoError(s.CreateMessagingChannelMember(ctx, messagingChannelMember))
})
t.Run("update", func(t *testing.T) {
req, messagingChannelMember := truncAndCreate(t)
messagingChannelMember.Type = types.ChannelMembershipType("member")
req.NoError(s.UpdateMessagingChannelMember(ctx, messagingChannelMember))
set, _, err := s.SearchMessagingChannelMembers(ctx, types.ChannelMemberFilter{ChannelID: []uint64{messagingChannelMember.ChannelID}, MemberID: []uint64{messagingChannelMember.UserID}})
req.NoError(err)
req.Equal(types.ChannelMembershipType("member"), set[0].Type)
})
t.Run("upsert", func(t *testing.T) {
t.Run("existing", func(t *testing.T) {
req, messagingChannelMember := truncAndCreate(t)
messagingChannelMember.Type = types.ChannelMembershipType("member")
req.NoError(s.UpsertMessagingChannelMember(ctx, messagingChannelMember))
set, _, err := s.SearchMessagingChannelMembers(ctx, types.ChannelMemberFilter{ChannelID: []uint64{messagingChannelMember.ChannelID}, MemberID: []uint64{messagingChannelMember.UserID}})
req.NoError(err)
req.Equal(types.ChannelMembershipType("member"), set[0].Type)
})
t.Run("new", func(t *testing.T) {
messagingChannelMember := makeNew(id.Next(), id.Next())
messagingChannelMember.Type = types.ChannelMembershipType("member")
req.NoError(s.UpsertMessagingChannelMember(ctx, messagingChannelMember))
set, _, err := s.SearchMessagingChannelMembers(ctx, types.ChannelMemberFilter{ChannelID: []uint64{messagingChannelMember.ChannelID}, MemberID: []uint64{messagingChannelMember.UserID}})
req.NoError(err)
req.Equal(types.ChannelMembershipType("member"), set[0].Type)
})
})
t.Run("delete", func(t *testing.T) {
t.Run("by ChannelMember", func(t *testing.T) {
req, messagingChannelMember := truncAndCreate(t)
@@ -13,6 +13,7 @@ import (
func testMessagingMessageAttachments(t *testing.T, s store.MessagingMessageAttachments) {
var (
ctx = context.Background()
req = require.New(t)
makeNew = func() *types.MessageAttachment {
// minimum data set for new messageAttachment
@@ -40,6 +41,36 @@ func testMessagingMessageAttachments(t *testing.T, s store.MessagingMessageAttac
req.NoError(s.CreateMessagingMessageAttachment(ctx, mma))
})
t.Run("update", func(t *testing.T) {
req, att := truncAndCreate(t)
att.AttachmentID = id.Next()
req.NoError(s.UpdateMessagingMessageAttachment(ctx, att))
fetched, err := s.LookupMessagingMessageAttachmentByMessageID(ctx, att.MessageID)
req.NoError(err)
req.Equal(att.AttachmentID, fetched.AttachmentID)
})
t.Run("upsert", func(t *testing.T) {
t.Run("existing", func(t *testing.T) {
req, att := truncAndCreate(t)
att.AttachmentID = id.Next()
req.NoError(s.UpsertMessagingMessageAttachment(ctx, att))
fetched, err := s.LookupMessagingMessageAttachmentByMessageID(ctx, att.MessageID)
req.NoError(err)
req.Equal(att.AttachmentID, fetched.AttachmentID)
})
t.Run("new", func(t *testing.T) {
att := makeNew()
att.AttachmentID = id.Next()
req.NoError(s.UpsertMessagingMessageAttachment(ctx, att))
upserted, err := s.LookupMessagingMessageAttachmentByMessageID(ctx, att.MessageID)
req.NoError(err)
req.Equal(att.AttachmentID, upserted.AttachmentID)
})
})
t.Run("delete", func(t *testing.T) {
t.Run("by MessageAttachment", func(t *testing.T) {
req, mma := truncAndCreate(t)