forked from huandu/facebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params_test.go
59 lines (50 loc) · 1.53 KB
/
params_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
// 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"
"testing"
)
func TestParamsEncode(t *testing.T) {
var params Params
buf := &bytes.Buffer{}
if mime, err := params.Encode(buf); err != nil || mime != _MIME_FORM_URLENCODED || buf.Len() != 0 {
t.Fatalf("empty params must encode to an empty string. actual is [e:%v] [str:%v] [mime:%v]", err, buf.String(), mime)
}
buf.Reset()
params = Params{}
params["need_escape"] = "&=+"
expectedEncoding := "need_escape=%26%3D%2B"
if mime, err := params.Encode(buf); err != nil || mime != _MIME_FORM_URLENCODED || buf.String() != expectedEncoding {
t.Fatalf("wrong params encode result. expected is '%v'. actual is '%v'. [e:%v] [mime:%v]", expectedEncoding, buf.String(), err, mime)
}
buf.Reset()
data := ParamsStruct{
Foo: "hello, world!",
Bar: &ParamsNestedStruct{
AAA: 1234,
BBB: "bbb",
CCC: true,
},
}
params = MakeParams(data)
/* there is no easy way to compare two encoded maps. so i just write expect map here, not test it.
expectedParams := Params{
"foo": "hello, world!",
"bar": map[string]interface{}{
"aaa": 1234,
"bbb": "bbb",
"ccc": true,
},
}
*/
if params == nil {
t.Fatalf("make params error.")
}
mime, err := params.Encode(buf)
t.Logf("complex encode result is '%v'. [e:%v] [mime:%v]", buf.String(), err, mime)
}