fix(libreoffice): expect output paths tests

This commit is contained in:
Julien Neuhart
2024-02-18 12:00:37 +01:00
parent 770208024d
commit 5707ae027f

View File

@@ -4,7 +4,7 @@ import (
"context" "context"
"errors" "errors"
"net/http" "net/http"
"reflect" "slices"
"testing" "testing"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
@@ -23,7 +23,7 @@ func TestConvertRoute(t *testing.T) {
engine gotenberg.PdfEngine engine gotenberg.PdfEngine
expectOptions libreofficeapi.Options expectOptions libreofficeapi.Options
expectError bool expectError bool
expectFileNames []string expectOutpoutPaths []string
expectHttpError bool expectHttpError bool
expectHttpStatus int expectHttpStatus int
expectOutputPathsCount int expectOutputPathsCount int
@@ -220,7 +220,7 @@ func TestConvertRoute(t *testing.T) {
expectError: false, expectError: false,
expectHttpError: false, expectHttpError: false,
expectOutputPathsCount: 1, expectOutputPathsCount: 1,
expectFileNames: []string{"/document.docx.pdf"}, expectOutpoutPaths: []string{"/document.docx.pdf"},
}, },
{ {
scenario: "success (many files)", scenario: "success (many files)",
@@ -244,7 +244,7 @@ func TestConvertRoute(t *testing.T) {
expectError: false, expectError: false,
expectHttpError: false, expectHttpError: false,
expectOutputPathsCount: 3, expectOutputPathsCount: 3,
expectFileNames: []string{"/document.docx.pdf", "/document2.docx.pdf", "/document2.doc.pdf"}, expectOutpoutPaths: []string{"/document.docx.pdf", "/document2.docx.pdf", "/document2.doc.pdf"},
}, },
{ {
scenario: "success with non-native PDF/A & PDF/UA (many files)", scenario: "success with non-native PDF/A & PDF/UA (many files)",
@@ -283,7 +283,7 @@ func TestConvertRoute(t *testing.T) {
expectError: false, expectError: false,
expectHttpError: false, expectHttpError: false,
expectOutputPathsCount: 2, expectOutputPathsCount: 2,
expectFileNames: []string{"/document.docx.pdf", "/document2.docx.pdf"}, expectOutpoutPaths: []string{"/document.docx.pdf", "/document2.docx.pdf"},
}, },
{ {
scenario: "success with native PDF/A & PDF/UA (many files)", scenario: "success with native PDF/A & PDF/UA (many files)",
@@ -319,7 +319,7 @@ func TestConvertRoute(t *testing.T) {
expectError: false, expectError: false,
expectHttpError: false, expectHttpError: false,
expectOutputPathsCount: 2, expectOutputPathsCount: 2,
expectFileNames: []string{"/document.docx.pdf", "/document2.docx.pdf"}, expectOutpoutPaths: []string{"/document.docx.pdf", "/document2.docx.pdf"},
}, },
{ {
scenario: "merge error", scenario: "merge error",
@@ -627,9 +627,9 @@ func TestConvertRoute(t *testing.T) {
t.Errorf("expected %d output paths but got %d", tc.expectOutputPathsCount, len(tc.ctx.OutputPaths())) t.Errorf("expected %d output paths but got %d", tc.expectOutputPathsCount, len(tc.ctx.OutputPaths()))
} }
if len(tc.expectFileNames) != 0 { for _, path := range tc.expectOutpoutPaths {
if !reflect.DeepEqual(tc.ctx.OutputPaths(), tc.expectFileNames) { if !slices.Contains(tc.ctx.OutputPaths(), path) {
t.Errorf("expected output paths %v, got %v", tc.expectFileNames, tc.ctx.OutputPaths()) t.Errorf("expected '%s' in output paths %v", path, tc.ctx.OutputPaths())
} }
} }
}) })