Skip to content

Commit

Permalink
add full protobuf rendering test
Browse files Browse the repository at this point in the history
  • Loading branch information
salamer committed Aug 18, 2018
1 parent 65a97e1 commit b6cb77e
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"strings"
"testing"

testdata "github.com/gin-gonic/gin/testdata/protoexample"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/ugorji/go/codec"
)
Expand Down Expand Up @@ -252,9 +254,6 @@ b:
assert.Equal(t, "application/x-yaml; charset=utf-8", w.Header().Get("Content-Type"))
}

func TestRenderProtoBuf(t *testing.T) {
}

type fail struct{}

// Hook MarshalYAML
Expand All @@ -268,6 +267,25 @@ func TestRenderYAMLFail(t *testing.T) {
assert.Error(t, err)
}

// test Protobuf rendering
func TestRenderProtoBuf(t *testing.T) {
w := httptest.NewRecorder()
reps := []int64{int64(1), int64(2)}
label := "test"
data := &testdata.Test{
Label: &label,
Reps: reps,
}

(ProtoBuf{data}).WriteContentType(w)
protoData, err := proto.Marshal(data)
assert.NoError(t, err)
(YAML{data}).WriteContentType(w)
assert.Equal(t, "application/x-yaml; charset=utf-8", w.Header().Get("Content-Type"))

assert.Equal(t, string(protoData[:]), w.Body.String())
}

func TestRenderXML(t *testing.T) {
w := httptest.NewRecorder()
data := xmlmap{
Expand Down

0 comments on commit b6cb77e

Please sign in to comment.