From 11e1ba3882beb56b9e154915f82db39885a1fc67 Mon Sep 17 00:00:00 2001 From: salamer Date: Sat, 18 Aug 2018 11:07:33 +0800 Subject: [PATCH] add protobuf render test --- context_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/context_test.go b/context_test.go index 945b083f..3cd0fe87 100644 --- a/context_test.go +++ b/context_test.go @@ -21,8 +21,11 @@ import ( "github.com/gin-contrib/sse" "github.com/gin-gonic/gin/binding" + "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" "golang.org/x/net/context" + + testdata "github.com/gin-gonic/gin/testdata/protoexample" ) var _ context.Context = &Context{} @@ -958,6 +961,24 @@ func TestContextRenderYAML(t *testing.T) { // and Content-Type is set to application/x-protobuf // and we just use the example protobuf to check if the response is correct func TestContextRenderProtoBuf(t *testing.T) { + w := httptest.NewRecorder() + c, _ := CreateTestContext(w) + + reps := []int64{int64(1), int64(2)} + + data := &testdata.Test{ + label: "test", + reps: resp, + } + + c.ProtoBuf(201, data) + + data, err := proto.Marshal(test) + assert.NoError(t, err) + + assert.Equal(t, 201, w.Code) + assert.Equal(t, data, w.Body.String()) + assert.Equal(t, "application/x-protobuf", w.HeaderMap.Get("Content-Type")) } func TestContextHeaders(t *testing.T) {