Skip to content

Commit 694a7f4

Browse files
committed
Add TestGHDocConvert2HTML
1 parent 92ed8d0 commit 694a7f4

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

ghdoc_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,37 @@ func TestNewGHDocWithDebug(t *testing.T) {
378378
t.Error("\nGot :", got.String(), "\nWant:", want)
379379
}
380380
}
381+
382+
func TestGHDocConvert2HTML(t *testing.T) {
383+
remotePath := "https://github.com/some/readme.md"
384+
token := "some-gh-token"
385+
doc := NewGHDoc(remotePath, true, 0, 0,
386+
true, token, 4, false)
387+
388+
// mock for getting remote raw README text
389+
htmlResponse := []byte("raw md text")
390+
doc.httpGetter = func(urlPath string) ([]byte, string, error) {
391+
if urlPath != remotePath {
392+
t.Error("Wrong urlPath. \nGot :", urlPath, "\nWant:", remotePath)
393+
}
394+
return htmlResponse, "text/plain;utf-8", nil
395+
}
396+
397+
// mock for converting md to txt
398+
ghURL := "https://api.github.com/markdown/raw"
399+
htmlBody := `<h1>header></h1>some text`
400+
doc.httpPoster = func(urlPath, filePath, token string) (string, error) {
401+
if urlPath != ghURL {
402+
if urlPath != remotePath {
403+
t.Error("Wrong urlPath. \nGot :", urlPath, "\nWant:", ghURL)
404+
}
405+
}
406+
return htmlBody, nil
407+
}
408+
if err := doc.Convert2HTML(); err != nil {
409+
t.Error("Got error:", err)
410+
}
411+
if doc.html != htmlBody {
412+
t.Error("Wrong html. \nGot :", doc.html, "\nWant:", htmlBody)
413+
}
414+
}

0 commit comments

Comments
 (0)