mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 16:17:03 +00:00
Simplify test cases
This commit is contained in:
@ -36,13 +36,33 @@ type recipient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type testData struct {
|
type testData struct {
|
||||||
|
emails []string
|
||||||
recipients []recipient
|
recipients []recipient
|
||||||
wantPackages []*MessagePackage
|
wantPackages []*MessagePackage
|
||||||
|
|
||||||
|
allRecipients map[string]recipient
|
||||||
|
allAddresses map[string]*MessageAddress
|
||||||
|
|
||||||
attKeys map[string]*crypto.SessionKey
|
attKeys map[string]*crypto.SessionKey
|
||||||
mimeBody, plainBody, richBody string
|
mimeBody, plainBody, richBody string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (td *testData) addRecipients() {
|
||||||
|
for _, email := range td.emails {
|
||||||
|
rcp := td.allRecipients[email]
|
||||||
|
rcp.email = email
|
||||||
|
td.recipients = append(td.recipients, rcpt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (td *testData) addAddresses() {
|
||||||
|
for i, wantPackage := range td.wantPackages {
|
||||||
|
for email := range wantPackage.Addresses {
|
||||||
|
td.wantPackages[i].Addresses[email] = td.allAddresses[email]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (td *testData) prepareAndCheck(t *testing.T) {
|
func (td *testData) prepareAndCheck(t *testing.T) {
|
||||||
r := require.New(t)
|
r := require.New(t)
|
||||||
|
|
||||||
@ -133,6 +153,43 @@ func TestSendReq(t *testing.T) {
|
|||||||
attKeyPackets := map[string]string{"attID": "not-empty"}
|
attKeyPackets := map[string]string{"attID": "not-empty"}
|
||||||
attAlgoKeys := map[string]AlgoKey{"attID": {"not-empty", "not-empty"}}
|
attAlgoKeys := map[string]AlgoKey{"attID": {"not-empty", "not-empty"}}
|
||||||
|
|
||||||
|
allRecipients := map[string]recipient{
|
||||||
|
"none@pm.me": {"", InternalPackage, testPublicKeyRing, SignatureDetached, "", true, nil},
|
||||||
|
"html@pm.me": {"", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil},
|
||||||
|
}
|
||||||
|
|
||||||
|
allAddresses := map[string]*MessageAddress{
|
||||||
|
"html@pm.me": {
|
||||||
|
Type: InternalPackage,
|
||||||
|
Signature: SignatureDetached,
|
||||||
|
EncryptedBodyKeyPacket: "not-empty",
|
||||||
|
EncryptedAttachmentKeyPackets: attKeyPackets,
|
||||||
|
},
|
||||||
|
"none@pm.me": {
|
||||||
|
Type: InternalPackage,
|
||||||
|
Signature: SignatureDetached,
|
||||||
|
EncryptedBodyKeyPacket: "not-empty",
|
||||||
|
EncryptedAttachmentKeyPackets: attKeyPackets,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
newTests := map[string]testData{
|
||||||
|
"SingleInternalHTML": {
|
||||||
|
emails: []string{"none@pm.me", "html@pm.me"},
|
||||||
|
wantPackages: []*MessagePackage{
|
||||||
|
{
|
||||||
|
Addresses: map[string]*MessageAddress{
|
||||||
|
"none@pm.me": nil,
|
||||||
|
"html@pm.me": nil,
|
||||||
|
},
|
||||||
|
Type: InternalPackage,
|
||||||
|
MIMEType: ContentTypeHTML,
|
||||||
|
EncryptedBody: "non-empty",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE naming
|
// NOTE naming
|
||||||
// Single: there should be one package
|
// Single: there should be one package
|
||||||
// Multiple: there should be more than one package
|
// Multiple: there should be more than one package
|
||||||
@ -710,10 +767,16 @@ func TestSendReq(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, test := range tests {
|
for name, test := range newTests {
|
||||||
test.mimeBody = "Mime body"
|
test.mimeBody = "Mime body"
|
||||||
test.plainBody = "Plain body"
|
test.plainBody = "Plain body"
|
||||||
test.richBody = "HTML body"
|
test.richBody = "HTML body"
|
||||||
|
test.allRecipients = allRecipients
|
||||||
|
test.allAddresses = allAddresses
|
||||||
|
|
||||||
|
test.addRecipients()
|
||||||
|
test.addAddresses()
|
||||||
|
|
||||||
t.Run("NoAtt"+name, test.prepareAndCheck)
|
t.Run("NoAtt"+name, test.prepareAndCheck)
|
||||||
test.attKeys = map[string]*crypto.SessionKey{"attID": attKey}
|
test.attKeys = map[string]*crypto.SessionKey{"attID": attKey}
|
||||||
t.Run("Att"+name, test.prepareAndCheck)
|
t.Run("Att"+name, test.prepareAndCheck)
|
||||||
|
|||||||
Reference in New Issue
Block a user