forked from grpc-ecosystem/grpc-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
marshal_httpbodyproto_test.go
49 lines (44 loc) · 1.04 KB
/
marshal_httpbodyproto_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
package runtime_test
import (
"bytes"
"testing"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/genproto/googleapis/api/httpbody"
)
func TestHTTPBodyContentType(t *testing.T) {
m := runtime.HTTPBodyMarshaler{
&runtime.JSONPb{
OrigName: true,
},
}
expected := "CustomContentType"
message := &httpbody.HttpBody{
ContentType: expected,
}
res := m.ContentType()
if res != "application/json" {
t.Errorf("content type not equal (%q, %q)", res, expected)
}
res = m.ContentTypeFromMessage(message)
if res != expected {
t.Errorf("content type not equal (%q, %q)", res, expected)
}
}
func TestHTTPBodyMarshal(t *testing.T) {
m := runtime.HTTPBodyMarshaler{
&runtime.JSONPb{
OrigName: true,
},
}
expected := []byte("Some test")
message := &httpbody.HttpBody{
Data: expected,
}
res, err := m.Marshal(message)
if err != nil {
t.Errorf("m.Marshal(%#v) failed with %v; want success", message, err)
}
if !bytes.Equal(res, expected) {
t.Errorf("Marshalled data not equal (%q, %q)", res, expected)
}
}