summaryrefslogtreecommitdiffstats
path: root/internal/compose/mime_test.go
blob: 6e8f0a025ad13f4ca2d87f4e7c0de1e7f7d62bff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package compose

import (
	"mime"
	"strings"
	"testing"
)

func TestBuildMixed(t *testing.T) {
	contentType, transfer, body, err := BuildMixed("ciao\nmondo", []Attachment{{Filename: "hello.txt", Data: []byte("hello")}})
	if err != nil {
		t.Fatal(err)
	}
	mediaType, params, err := mime.ParseMediaType(contentType)
	if err != nil || mediaType != "multipart/mixed" || params["boundary"] == "" || transfer != "7bit" {
		t.Fatalf("unexpected MIME metadata: %q, %q, %v", contentType, transfer, err)
	}
	if !strings.Contains(body, "Content-Disposition: attachment") || !strings.Contains(body, "aGVsbG8=") {
		t.Fatalf("attachment missing: %q", body)
	}
}