@@ -378,3 +378,37 @@ func TestNewGHDocWithDebug(t *testing.T) {
378
378
t .Error ("\n Got :" , got .String (), "\n Want:" , want )
379
379
}
380
380
}
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. \n Got :" , urlPath , "\n Want:" , 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. \n Got :" , urlPath , "\n Want:" , 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. \n Got :" , doc .html , "\n Want:" , htmlBody )
413
+ }
414
+ }
0 commit comments