...
1 package runtime_test
2
3 import (
4 "bytes"
5 "testing"
6
7 "github.com/grpc-ecosystem/grpc-gateway/runtime"
8 "google.golang.org/genproto/googleapis/api/httpbody"
9 )
10
11 func TestHTTPBodyContentType(t *testing.T) {
12 m := runtime.HTTPBodyMarshaler{
13 &runtime.JSONPb{
14 OrigName: true,
15 },
16 }
17 expected := "CustomContentType"
18 message := &httpbody.HttpBody{
19 ContentType: expected,
20 }
21 res := m.ContentType()
22 if res != "application/json" {
23 t.Errorf("content type not equal (%q, %q)", res, expected)
24 }
25 res = m.ContentTypeFromMessage(message)
26 if res != expected {
27 t.Errorf("content type not equal (%q, %q)", res, expected)
28 }
29 }
30
31 func TestHTTPBodyMarshal(t *testing.T) {
32 m := runtime.HTTPBodyMarshaler{
33 &runtime.JSONPb{
34 OrigName: true,
35 },
36 }
37 expected := []byte("Some test")
38 message := &httpbody.HttpBody{
39 Data: expected,
40 }
41 res, err := m.Marshal(message)
42 if err != nil {
43 t.Errorf("m.Marshal(%#v) failed with %v; want success", message, err)
44 }
45 if !bytes.Equal(res, expected) {
46 t.Errorf("Marshalled data not equal (%q, %q)", res, expected)
47
48 }
49 }
50
View as plain text