-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
md_test.go
89 lines (72 loc) · 1.98 KB
/
md_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
79
80
81
82
83
84
85
86
87
88
89
package lark_docs_md_test
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
"github.com/chyroc/lark"
"github.com/chyroc/lark/larkext"
"github.com/chyroc/lark_docs_md"
"github.com/stretchr/testify/assert"
)
func TestDocMarkdown(t *testing.T) {
as := assert.New(t)
larkClient := lark.New(
lark.WithAppCredential(os.Getenv("LARK_CHYROC_HEYMAN_APP_ID"), os.Getenv("LARK_CHYROC_HEYMAN_APP_SECRET")),
lark.WithTimeout(time.Minute),
)
tests := []struct {
name string
}{
{"1"},
{"2"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
opt := &lark_docs_md.FormatOpt{
LarkClient: larkClient,
StaticDir: fmt.Sprintf("testdata/%s/static", tt.name),
FilePrefix: "static",
}
doc := loadDocContent(t, tt.name)
md := loadMarkdown(t, tt.name)
result := lark_docs_md.DocMarkdown(context.Background(), doc, opt)
as.Equal(md, result, tt.name)
})
}
}
func Test_FromDocToken(t *testing.T) {
t.Skip()
as := assert.New(t)
// https://rs6qnacjws.feishu.cn/docs/doccng7C51ULsOrHtbmWBa3a4Hf
larkClient := lark.New(
lark.WithAppCredential(os.Getenv("LARK_CHYROC_HEYMAN_APP_ID"), os.Getenv("LARK_CHYROC_HEYMAN_APP_SECRET")),
)
docToken := "doccng7C51ULsOrHtbmWBa3a4Hf"
doc, err := larkext.NewDoc(larkClient, docToken).Content(context.Background())
as.Nil(err)
result := lark_docs_md.DocMarkdown(context.Background(), doc, &lark_docs_md.FormatOpt{
LarkClient: larkClient,
// StaticDir: "/tmp/tmp-static",
// FilePrefix: "static",
StaticAsURL: true,
})
fmt.Println(result)
}
func loadDocContent(t *testing.T, testCase string) *lark.DocContent {
as := assert.New(t)
bs, err := ioutil.ReadFile(fmt.Sprintf("testdata/%s/data.json", testCase))
as.Nil(err)
doc := &lark.DocContent{}
as.Nil(json.Unmarshal(bs, doc))
return doc
}
func loadMarkdown(t *testing.T, testCase string) string {
as := assert.New(t)
bs, err := ioutil.ReadFile(fmt.Sprintf("testdata/%s/data.md", testCase))
as.Nil(err)
return string(bs)
}