@@ -20,6 +20,9 @@ func TestFetchAndStoreAttachment(t *testing.T) {
20
20
"http://mock.com/media/hello.jpg" : {
21
21
httpx .NewMockResponse (200 , nil , testJPG ),
22
22
},
23
+ "http://mock.com/media/hello2" : {
24
+ httpx .NewMockResponse (200 , map [string ]string {"Content-Type" : "image/jpeg" }, testJPG ),
25
+ },
23
26
"http://mock.com/media/hello.mp3" : {
24
27
httpx .NewMockResponse (502 , nil , []byte (`My gateways!` )),
25
28
},
@@ -53,15 +56,26 @@ func TestFetchAndStoreAttachment(t *testing.T) {
53
56
assert .Len (t , clog .HTTPLogs (), 1 )
54
57
assert .Equal (t , "http://mock.com/media/hello.jpg" , clog .HTTPLogs ()[0 ].URL )
55
58
59
+ att , err = courier .FetchAndStoreAttachment (ctx , mb , mockChannel , "http://mock.com/media/hello2" , clog )
60
+ assert .NoError (t , err )
61
+ assert .Equal (t , "image/jpeg" , att .ContentType )
62
+ assert .Equal (t , "https://backend.com/attachments/547deaf7-7620-4434-95b3-58675999c4b7.jpe" , att .URL )
63
+ assert .Equal (t , 17301 , att .Size )
64
+
65
+ assert .Len (t , mb .SavedAttachments (), 2 )
66
+ assert .Equal (t , & test.SavedAttachment {Channel : mockChannel , ContentType : "image/jpeg" , Data : testJPG , Extension : "jpg" }, mb .SavedAttachments ()[0 ])
67
+ assert .Len (t , clog .HTTPLogs (), 2 )
68
+ assert .Equal (t , "http://mock.com/media/hello2" , clog .HTTPLogs ()[1 ].URL )
69
+
56
70
// a non-200 response should return an unavailable attachment
57
71
att , err = courier .FetchAndStoreAttachment (ctx , mb , mockChannel , "http://mock.com/media/hello.mp3" , clog )
58
72
assert .NoError (t , err )
59
73
assert .Equal (t , & courier.Attachment {ContentType : "unavailable" , URL : "http://mock.com/media/hello.mp3" }, att )
60
74
61
75
// should have a logged HTTP request but no attachments will have been saved to storage
62
- assert .Len (t , clog .HTTPLogs (), 2 )
63
- assert .Equal (t , "http://mock.com/media/hello.mp3" , clog .HTTPLogs ()[1 ].URL )
64
- assert .Len (t , mb .SavedAttachments (), 1 )
76
+ assert .Len (t , clog .HTTPLogs (), 3 )
77
+ assert .Equal (t , "http://mock.com/media/hello.mp3" , clog .HTTPLogs ()[2 ].URL )
78
+ assert .Len (t , mb .SavedAttachments (), 2 )
65
79
66
80
// same for a connection error
67
81
att , err = courier .FetchAndStoreAttachment (ctx , mb , mockChannel , "http://mock.com/media/hello.pdf" , clog )
0 commit comments