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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
package format
import (
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/onsi/gomega/format"
)
var _ = ginkgo.Describe("RenderMarkdown", func() {
format.CharactersAroundMismatchToInclude = 10
ginkgo.It("should render the expected output based on config reflection/tags", func() {
actual := testRenderTree(MarkdownTreeRenderer{HeaderPrefix: `### `}, &struct {
Name string `default:"notempty"`
Host string `url:"host"`
}{})
expected := `
### URL Fields
* __Host__ (**Required**)
URL part: <code class="service-url">mock://<strong>host</strong>/</code>
### Query/Param Props
* __Name__
Default: `[1:] + "`notempty`" + `
`
gomega.Expect(actual).To(gomega.Equal(expected))
})
ginkgo.It("should render url paths in sorted order", func() {
actual := testRenderTree(MarkdownTreeRenderer{HeaderPrefix: `### `}, &struct {
Host string `url:"host"`
Path1 string `url:"path1"`
Path3 string `url:"path3"`
Path2 string `url:"path2"`
}{})
expected := `
### URL Fields
* __Host__ (**Required**)
URL part: <code class="service-url">mock://<strong>host</strong>/path1/path2/path3</code>
* __Path1__ (**Required**)
URL part: <code class="service-url">mock://host/<strong>path1</strong>/path2/path3</code>
* __Path2__ (**Required**)
URL part: <code class="service-url">mock://host/path1/<strong>path2</strong>/path3</code>
* __Path3__ (**Required**)
URL part: <code class="service-url">mock://host/path1/path2/<strong>path3</strong></code>
### Query/Param Props
`[1:] // Remove initial newline
gomega.Expect(actual).To(gomega.Equal(expected))
})
ginkgo.It("should render prop aliases", func() {
actual := testRenderTree(MarkdownTreeRenderer{HeaderPrefix: `### `}, &struct {
Name string `key:"name,handle,title,target"`
}{})
expected := `
### URL Fields
### Query/Param Props
* __Name__ (**Required**)
Aliases: `[1:] + "`handle`, `title`, `target`" + `
`
gomega.Expect(actual).To(gomega.Equal(expected))
})
ginkgo.It("should render possible enum values", func() {
actual := testRenderTree(MarkdownTreeRenderer{HeaderPrefix: `### `}, &testEnummer{})
expected := `
### URL Fields
### Query/Param Props
* __Choice__
Default: `[1:] + "`Maybe`" + `
Possible values: ` + "`Yes`, `No`, `Maybe`" + `
`
gomega.Expect(actual).To(gomega.Equal(expected))
})
ginkgo.When("there are no query props", func() {
ginkgo.It("should prepend an empty-message instead of props description", func() {
actual := testRenderTree(MarkdownTreeRenderer{
HeaderPrefix: `### `,
PropsDescription: "Feel free to set these:",
PropsEmptyMessage: "There is nothing to set!",
}, &struct {
Host string `url:"host"`
}{})
expected := `
### URL Fields
* __Host__ (**Required**)
URL part: <code class="service-url">mock://<strong>host</strong>/</code>
### Query/Param Props
There is nothing to set!
`[1:] // Remove initial newline
gomega.Expect(actual).To(gomega.Equal(expected))
})
})
ginkgo.When("there are query props", func() {
ginkgo.It("should prepend the props description", func() {
actual := testRenderTree(MarkdownTreeRenderer{
HeaderPrefix: `### `,
PropsDescription: "Feel free to set these:",
PropsEmptyMessage: "There is nothing to set!",
}, &struct {
Host string `url:"host"`
CoolMode bool `key:"coolmode" optional:""`
}{})
expected := `
### URL Fields
* __Host__ (**Required**)
URL part: <code class="service-url">mock://<strong>host</strong>/</code>
### Query/Param Props
Feel free to set these:
* __CoolMode__
Default: *empty*
`[1:] // Remove initial newline
gomega.Expect(actual).To(gomega.Equal(expected))
})
})
})
|