forked from pseudomuto/protoc-gen-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer_test.go
78 lines (60 loc) · 1.8 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package gendoc_test
import (
"github.com/pseudomuto/protokit"
"github.com/pseudomuto/protokit/utils"
"github.com/stretchr/testify/suite"
"os"
"testing"
"github.com/ajainc/protoc-gen-doc"
)
const tempTestDir = "./tmp"
var renderTemplate *gendoc.Template
type RendererTest struct {
suite.Suite
}
func TestRenderer(t *testing.T) {
suite.Run(t, new(RendererTest))
}
func (assert *RendererTest) SetupSuite() {
set, err := utils.LoadDescriptorSet("fixtures", "fileset.pb")
assert.NoError(err)
os.Mkdir(tempTestDir, os.ModePerm)
req := utils.CreateGenRequest(set, "Booking.proto", "Vehicle.proto")
result := protokit.ParseCodeGenRequest(req)
renderTemplate = gendoc.NewTemplate(result)
}
func (assert *RendererTest) TestDocBookRenderer() {
_, err := gendoc.RenderTemplate(gendoc.RenderTypeDocBook, renderTemplate, "")
assert.Nil(err)
}
func (assert *RendererTest) TestHtmlRenderer() {
_, err := gendoc.RenderTemplate(gendoc.RenderTypeHTML, renderTemplate, "")
assert.Nil(err)
}
func (assert *RendererTest) TestJsonRenderer() {
_, err := gendoc.RenderTemplate(gendoc.RenderTypeJSON, renderTemplate, "")
assert.Nil(err)
}
func (assert *RendererTest) TestMarkdownRenderer() {
_, err := gendoc.RenderTemplate(gendoc.RenderTypeMarkdown, renderTemplate, "")
assert.Nil(err)
}
func (assert *RendererTest) TestNewRenderType() {
expected := []gendoc.RenderType{
gendoc.RenderTypeDocBook,
gendoc.RenderTypeHTML,
gendoc.RenderTypeJSON,
gendoc.RenderTypeMarkdown,
}
supplied := []string{"docbook", "html", "json", "markdown"}
for idx, input := range supplied {
rt, err := gendoc.NewRenderType(input)
assert.Nil(err)
assert.Equal(expected[idx], rt)
}
}
func (assert *RendererTest) TestNewRenderTypeUnknown() {
rt, err := gendoc.NewRenderType("/some/template.tmpl")
assert.Zero(rt)
assert.NotNil(err)
}