add new instance and provide multiple converting files close #2
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user