-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfiles_test.go
61 lines (45 loc) · 1.26 KB
/
files_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package mailosaur
import (
"fmt"
"log"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func init() {
apiKey := os.Getenv("MAILOSAUR_API_KEY")
baseUrl := os.Getenv("MAILOSAUR_BASE_URL")
server = os.Getenv("MAILOSAUR_SERVER")
if len(apiKey) == 0 || len(server) == 0 {
log.Fatal("Missing necessary environment variables - refer to README.md")
}
if len(baseUrl) == 0 {
baseUrl = "https://next.mailosaur.com/"
}
client = New(apiKey)
client.baseUrl = baseUrl
client.Messages.DeleteAll(server)
host := os.Getenv("MAILOSAUR_SMTP_HOST")
if len(host) == 0 {
host = "mailosaur.net"
}
testEmailAddress := fmt.Sprintf("wait_for_test@%s.%s", server, host)
sendEmail(client, server, testEmailAddress)
result, _ := client.Messages.Get(&MessageSearchParams{
Server: server,
}, &SearchCriteria{
SentTo: testEmailAddress,
})
email = result
}
// func TestFilesGetEmail(t *testing.T) {
// bytes, _ := client.Files.GetEmail(email.Id)
// assert.True(t, len(bytes) > 1)
// assert.True(t, strings.Contains(string(bytes), email.Subject))
// }
func TestFilesGetAttachment(t *testing.T) {
attachment := email.Attachments[0]
bytes, _ := client.Files.GetAttachment(attachment.Id)
assert.True(t, len(bytes) > 1)
assert.Equal(t, attachment.Length, len(bytes))
}