-
Notifications
You must be signed in to change notification settings - Fork 514
/
filedata_test.go
35 lines (29 loc) · 1.26 KB
/
filedata_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
// A facebook graph api client in go.
// https://github.com/huandu/facebook/
//
// Copyright 2012, Huan Du
// Licensed under the MIT license
// https://github.com/huandu/facebook/blob/master/LICENSE
package facebook
import (
"bytes"
"strings"
"testing"
)
func TestBinaryParamsEncode(t *testing.T) {
buf := &bytes.Buffer{}
params := Params{}
params["attachment"] = FileAlias("image.jpg", "LICENSE")
contentTypeImage := "Content-Type: image/jpeg"
if mime, err := params.Encode(buf); err != nil || !strings.Contains(mime, mimeFormData) || !strings.Contains(buf.String(), contentTypeImage) {
t.Fatalf("wrong binary params encode result. expected content type is '%v'. actual is '%v'. [e:%v] [mime:%v]", contentTypeImage, buf.String(), err, mime)
}
// Fallback for unknown content types
// should be application/octet-stream
buf.Reset()
params = Params{"attachment": FileAlias("image.unknown", "LICENSE")}
contentTypeOctet := "Content-Type: application/octet-stream"
if mime, err := params.Encode(buf); err != nil || !strings.Contains(mime, mimeFormData) || !strings.Contains(buf.String(), contentTypeOctet) {
t.Fatalf("wrong binary params encode result. expected content type is '%v'. actual is '%v'. [e:%v] [mime:%v]", contentTypeOctet, buf.String(), err, mime)
}
}