add new instance and provide multiple converting files close #2

This commit is contained in:
Adrian Zürcher
2025-12-24 12:05:59 +01:00
parent 870cca1cfd
commit 5985854092
3 changed files with 119 additions and 53 deletions

View File

@@ -1,12 +1,49 @@
package html2pdf
import "testing"
import (
"os"
"path/filepath"
"strings"
"testing"
"gitea.tecamino.com/paadi/html2pdf/converter"
)
func TestConvert(t *testing.T) {
t.Log("start test")
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 []converter.File
for _, f := range files {
ext := filepath.Ext(f.Name())
if ext != ".html" {
continue
}
input = append(input, converter.File{
Input: filepath.Join(rootPath, f.Name()),
Output: strings.Replace(f.Name(), ext, ".pdf", 1),
})
}
c := converter.NewConverter("./assets")
if err := c.Convert(input...); err != nil {
t.Fatal(err)
}
t.Log("test successfull")
}