Ejemplo n.º 1
0
// TestAttachments checks that attachments are being added properly.
func TestAttachments(t *testing.T) {
	e := testutils.TestEmail()

	attachment := testutils.TestAttachment(t)
	e.Attachments = append(e.Attachments, attachment)

	params, err := b.paramsForEmail(e)
	if err != nil {
		t.FailNow()
	}

	// the sendgrid backend will have read the contents of the reader,
	// so we need to seek back to the beginning
	offset, err := attachment.Data.(io.ReadSeeker).Seek(0, 0)
	if err != nil {
		t.FailNow()
	} else if offset != int64(0) {
		t.FailNow()
	}

	// check that the file data is there
	fileData, err := ioutil.ReadAll(attachment.Data)
	if err != nil {
		t.FailNow()
	}
	if params.Get(fmt.Sprintf("files[%v]", e.Attachments[0].Name)) != string(fileData) {
		t.FailNow()
	}
}
Ejemplo n.º 2
0
// TestAttachments checks that the attachments are added correctly
func TestAttachments(t *testing.T) {
	e := testutils.TestEmail()

	attachment := testutils.TestAttachment(t)
	e.Attachments = append(e.Attachments, attachment)

	wrapper, err := b.mandrillWrapperForEmail(e)
	if err != nil {
		t.FailNow()
	}

	me := wrapper.Message

	if len(me.Attachments) != len(e.Attachments) {
		t.FailNow()
	}

	mAttachment := me.Attachments[0]

	if attachment.Name != mAttachment.Name {
		t.FailNow()
	}

	if attachment.Mimetype != mAttachment.Type {
		t.FailNow()
	}

	// the mandrill backend will have read the contents of the reader,
	// so we need to seek back to the beginning
	offset, err := attachment.Data.(io.ReadSeeker).Seek(0, 0)
	if err != nil {
		t.FailNow()
	} else if offset != int64(0) {
		t.FailNow()
	}

	// check that the file data is there
	fileData, err := ioutil.ReadAll(attachment.Data)
	if err != nil {
		t.FailNow()
	}

	if base64.StdEncoding.EncodeToString(fileData) != mAttachment.Content {
		t.FailNow()
	}
}
Ejemplo n.º 3
0
// TestAttachments checks that attachments are added correctly
func TestAttachments(t *testing.T) {
	e := testutils.TestEmail()

	attachment := testutils.TestAttachment(t)
	e.Attachments = append(e.Attachments, attachment)

	wrapper, err := b.wrapperForEmail(e)
	if err != nil {
		t.Fatal(err)
	}

	paAttachment, ok := wrapper.Arguments.Attachments[attachment.Name]
	if !ok {
		t.FailNow()
	}

	if paAttachment.ContentType != attachment.Mimetype {
		t.FailNow()
	}

	// the postageapp backend will have read the contents of the reader,
	// so we need to seek back to the beginning
	offset, err := attachment.Data.(io.ReadSeeker).Seek(0, 0)
	if err != nil {
		t.FailNow()
	} else if offset != int64(0) {
		t.FailNow()
	}

	// check that the file data is there
	fileData, err := ioutil.ReadAll(attachment.Data)
	if err != nil {
		t.FailNow()
	}

	if paAttachment.Content != base64.StdEncoding.EncodeToString(fileData) {
		t.FailNow()
	}
}