Repository navigation
Expand file tree
/
Copy pathexample_report_output_test.go
More file actions
69 lines (61 loc) · 1.72 KB
/
Copy pathexample_report_output_test.go
File metadata and controls
69 lines (61 loc) · 1.72 KB
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
package mark_test
import (
"bytes"
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/kovetskiy/mark/v17"
"github.com/kovetskiy/mark/v17/confluence/confluencetest"
"github.com/kovetskiy/mark/v17/report"
)
// A json report written to a writer of its own leaves the page URLs where they
// always are, so neither has to be rebuilt from the other.
func ExampleReportConfig_output() {
server := confluencetest.Start()
defer server.Close()
home := server.AddPage("DOCS", "Home", "page", "")
server.SetHomepage("DOCS", home.ID)
dir, err := os.MkdirTemp("", "mark-example")
if err != nil {
fmt.Println(err)
return
}
defer os.RemoveAll(dir)
doc := "<!-- Space: DOCS -->\n<!-- Title: Guide -->\n\nA guide.\n"
if err := os.WriteFile(filepath.Join(dir, "guide.md"), []byte(doc), 0o600); err != nil {
fmt.Println(err)
return
}
var urls, reportJSON bytes.Buffer
err = mark.Run(context.Background(), mark.Config{
PublishConfig: mark.PublishConfig{
Rendering: mark.RenderingConfig{Features: []string{"none"}},
Output: &urls,
},
Files: filepath.Join(dir, "*.md"),
Connection: mark.ConnectionConfig{BaseURL: server.URL, Username: "user", Password: "token"},
Report: mark.ReportConfig{
OutputFormat: report.FormatJSON,
Output: &reportJSON,
},
})
if err != nil {
fmt.Println(err)
return
}
fmt.Print(strings.ReplaceAll(urls.String(), server.URL, "https://confluence.example"))
var result report.Report
if err := json.Unmarshal(reportJSON.Bytes(), &result); err != nil {
fmt.Println(err)
return
}
for _, page := range result.Pages {
fmt.Printf("%s: %s\n", page.Title, page.Status)
}
// Output:
// https://confluence.example/display/DOCS/1003
// Guide: published
}