Files
html2pdf/html2pdf_test.go
2025-12-29 17:15:52 +01:00

60 lines
1.1 KiB
Go

package html2pdf
import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"gitea.tecamino.com/paadi/html2pdf/converter"
"gitea.tecamino.com/paadi/html2pdf/models"
)
func TestConvert(t *testing.T) {
t.Log("start test convert one file")
err := Convert("./assets", "dst/test.html", "out.pdf")
if err != nil {
t.Fatal(err)
}
}
func TestConvertFiles(t *testing.T) {
t.Log("start test convert files")
rootPath := "dst"
files, err := os.ReadDir(rootPath)
if err != nil {
t.Fatal(err)
}
var input []models.File
for _, f := range files {
ext := filepath.Ext(f.Name())
if ext != ".html" {
continue
}
input = append(input, models.File{
Input: filepath.Join(rootPath, f.Name()),
Output: strings.Replace(f.Name(), ext, ".pdf", 1),
})
}
c, err := converter.NewConverter("assets/chrome-headless-shell/win64")
if err != nil {
t.Fatal(err)
}
defer c.Close()
c.SetProgressCallback(func(progress int) {
fmt.Println(progress)
})
if err := c.Convert(input...); err != nil {
t.Fatal(err)
}
t.Log("test successfull")
}