diff --git a/pdf/internal/e2etest/allobjects_test.go b/pdf/internal/e2etest/allobjects_test.go index cece5f3e..cecbb31e 100644 --- a/pdf/internal/e2etest/allobjects_test.go +++ b/pdf/internal/e2etest/allobjects_test.go @@ -56,7 +56,6 @@ func probeAllObjectsSinglePdf(inputPath string) error { if err != nil { return err } - defer f.Close() pdfReader, err := model.NewPdfReader(f) diff --git a/pdf/internal/e2etest/passthrough_test.go b/pdf/internal/e2etest/passthrough_test.go index 63c50c39..e018168b 100644 --- a/pdf/internal/e2etest/passthrough_test.go +++ b/pdf/internal/e2etest/passthrough_test.go @@ -20,7 +20,7 @@ import ( // Set environment variables: // UNIDOC_E2E_FORCE_TESTS to "1" to force the tests to execute. // UNIDOC_PASSTHROUGH_TESTDATA to the path of the corpus folder. -// UNIDOC_GS_BIN_PATH to the path of the ghosccript binary (gs). +// UNIDOC_GS_BIN_PATH to the path of the ghostscript binary (gs). var ( forceTest = os.Getenv("UNIDOC_E2E_FORCE_TESTS") == "1" passthroughCorpusFolder = os.Getenv("UNIDOC_PASSTHROUGH_TESTDATA") @@ -55,7 +55,7 @@ func TestPassthrough(t *testing.T) { params := passthroughParams{ inputPath: fpath, outPath: filepath.Join(tempdir, "1.pdf"), - gsValidation: false, + gsValidation: len(ghostscriptBinPath) > 0, } err := passthroughSinglePdf(params) if err != nil { diff --git a/pdf/internal/e2etest/validate.go b/pdf/internal/e2etest/validate.go index 48ef9b04..c6889079 100644 --- a/pdf/internal/e2etest/validate.go +++ b/pdf/internal/e2etest/validate.go @@ -18,7 +18,7 @@ import ( // To enable ghostscript validation, the path to the binary needs to be specified. // Set environment variable: -// UNIDOC_GS_BIN_PATH to the path of the ghosccript binary (gs). +// UNIDOC_GS_BIN_PATH to the path of the ghostscript binary (gs). var ( ghostscriptBinPath = os.Getenv("UNIDOC_GS_BIN_PATH") ) @@ -32,16 +32,17 @@ func validatePdf(path string, password string) (int, error) { } common.Log.Debug("Validating: %s", path) - var cmd *exec.Cmd + params := []string{"-dBATCH", "-dNODISPLAY", "-dNOPAUSE"} if len(password) > 0 { - option := fmt.Sprintf("-sPDFPassword=%s", password) - cmd = exec.Command(ghostscriptBinPath, "-dBATCH", "-dNODISPLAY", "-dNOPAUSE", option, path) - } else { - cmd = exec.Command(ghostscriptBinPath, "-dBATCH", "-dNODISPLAY", "-dNOPAUSE", path) + params = append(params, fmt.Sprintf("-sPDFPassword=%s", password)) } + params = append(params, path) - var out bytes.Buffer - var errOut bytes.Buffer + var ( + out bytes.Buffer + errOut bytes.Buffer + ) + cmd := exec.Command(ghostscriptBinPath, params...) cmd.Stdout = &out cmd.Stderr = &errOut