add new functions for zip and byte slices
This commit is contained in:
@@ -53,7 +53,7 @@ func TestConvertFiles(t *testing.T) {
|
||||
fmt.Println(progress)
|
||||
})
|
||||
|
||||
if err := c.Convert(input...); err != nil {
|
||||
if err := c.ConvertToPdf(input...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("test successfull")
|
||||
@@ -94,7 +94,7 @@ func TestConvertHtml(t *testing.T) {
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
err = c.ConvertHtmls(models.Html{Html: html, Output: outputPath})
|
||||
err = c.ConvertHtmlsToPdf(models.Html{Html: html, Output: outputPath})
|
||||
if err != nil {
|
||||
t.Fatalf("ConvertHtml failed: %v", err)
|
||||
}
|
||||
@@ -117,3 +117,71 @@ func TestConvertHtml(t *testing.T) {
|
||||
|
||||
t.Log("ConvertHtml test successful")
|
||||
}
|
||||
|
||||
func TestConvertHtmlsToPDFZip(t *testing.T) {
|
||||
t.Log("start test ConvertHtml")
|
||||
|
||||
// Skip in short mode (useful for CI)
|
||||
if testing.Short() {
|
||||
t.Skip("skipping ConvertHtml integration test in short mode")
|
||||
}
|
||||
|
||||
html := []byte(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test PDF</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; }
|
||||
h1 { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello PDF</h1>
|
||||
<p>This is a test.</p>
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
|
||||
outputPath := filepath.Join("test.pdf")
|
||||
|
||||
c, err := converter.NewConverter("assets/chrome-headless-shell/win64")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
b, err := c.ConvertHtmlsToZip(models.Html{Html: html, Output: outputPath})
|
||||
if err != nil {
|
||||
t.Fatalf("ConvertHtml failed: %v", err)
|
||||
}
|
||||
|
||||
f, err := os.Create("test.zip")
|
||||
if err != nil {
|
||||
t.Fatalf("create file: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = f.Write(b)
|
||||
if err != nil {
|
||||
t.Fatalf("write to file: %v", err)
|
||||
}
|
||||
|
||||
// // Assert PDF exists
|
||||
// data, err := os.ReadFile(outputPath)
|
||||
// if err != nil {
|
||||
// t.Fatalf("PDF not created: %v", err)
|
||||
// }
|
||||
|
||||
// // Assert non-empty
|
||||
// if len(data) == 0 {
|
||||
// t.Fatal("PDF file is empty")
|
||||
// }
|
||||
|
||||
// // Assert valid PDF header
|
||||
// if !bytes.HasPrefix(data, []byte("%PDF-")) {
|
||||
// t.Fatalf("output is not a valid PDF (missing %%PDF- header)")
|
||||
// }
|
||||
|
||||
t.Log("ConvertHtml test successful")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user