-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathrender_test.go
78 lines (60 loc) · 1.35 KB
/
render_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 base
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/qri-io/qfs"
)
func TestRender(t *testing.T) {
t.Skip("TODO (b5) - need to fix qfs / repo connection for this to work")
ctx := context.Background()
r := newTestRepo(t)
ref := addCitiesDataset(t, r)
ds, err := NewTestDatasetLoader(r.Filesystem(), r).LoadDataset(ctx, ref.String())
if err != nil {
t.Fatal(err)
}
_, err = Render(ctx, r, ds, nil)
if err != nil {
t.Error(err.Error())
}
}
func TestRenderReadme(t *testing.T) {
ctx := context.Background()
f := qfs.NewMemfileBytes("test.md", []byte(`# hi
three things:
* one
* two
* three`))
htmlBytes, err := RenderReadme(ctx, f)
if err != nil {
t.Fatal(err)
}
expectStr := `<h1>hi</h1>
<p>three things:</p>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
`
if diff := cmp.Diff(expectStr, string(htmlBytes)); diff != "" {
t.Errorf("body component (-want +got):\n%s", diff)
}
}
func TestRenderReadmeWithScriptTag(t *testing.T) {
ctx := context.Background()
f := qfs.NewMemfileBytes("test.md", []byte(`# a script
<script>alert('hi');</script>
done`))
htmlBytes, err := RenderReadme(ctx, f)
if err != nil {
t.Fatal(err)
}
expectStr := `<h1>a script</h1>
<p>done</p>
`
if diff := cmp.Diff(expectStr, string(htmlBytes)); diff != "" {
t.Errorf("body component (-want +got):\n%s", diff)
}
}