forked from pseudomuto/protoc-gen-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer_test.go
55 lines (45 loc) · 1.17 KB
/
renderer_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
package gendoc_test
import (
"os"
"testing"
. "github.com/pactus-project/protoc-gen-doc"
"github.com/pseudomuto/protokit"
"github.com/pseudomuto/protokit/utils"
"github.com/stretchr/testify/require"
)
func TestRenderers(t *testing.T) {
set, err := utils.LoadDescriptorSet("fixtures", "fileset.pb")
require.NoError(t, err)
os.Mkdir("./tmp", os.ModePerm)
req := utils.CreateGenRequest(set, "Booking.proto", "Vehicle.proto")
result := protokit.ParseCodeGenRequest(req)
template := NewTemplate(result)
for _, r := range []RenderType{
RenderTypeDocBook,
RenderTypeHTML,
RenderTypeJSON,
RenderTypeMarkdown,
} {
_, err := RenderTemplate(r, template, "")
require.NoError(t, err)
}
}
func TestNewRenderType(t *testing.T) {
expected := []RenderType{
RenderTypeDocBook,
RenderTypeHTML,
RenderTypeJSON,
RenderTypeMarkdown,
}
supplied := []string{"docbook", "html", "json", "markdown"}
for idx, input := range supplied {
rt, err := NewRenderType(input)
require.Nil(t, err)
require.Equal(t, expected[idx], rt)
}
}
func TestNewRenderTypeUnknown(t *testing.T) {
rt, err := NewRenderType("/some/template.tmpl")
require.Zero(t, rt)
require.Error(t, err)
}