From ea97e3b660ff11587c224c2be2938aa0aee01854 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:02:32 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`limit-p?= =?UTF-8?q?ages-ocr`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @icereed. * https://github.com/icereed/paperless-gpt/pull/102#issuecomment-2582999315 The following files were modified: * `main.go` * `paperless_test.go` --- main.go | 2 +- paperless_test.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 783fa7e..a29bd98 100644 --- a/main.go +++ b/main.go @@ -262,7 +262,7 @@ func isOcrEnabled() bool { return visionLlmModel != "" && visionLlmProvider != "" } -// validateOrDefaultEnvVars ensures all necessary environment variables are set +// validateOrDefaultEnvVars validates and sets default values for environment variables required by the application. It ensures that necessary configuration parameters are present and sets sensible defaults where possible. The function checks and configures tags for manual and automatic document processing, validates Paperless URL and API token, verifies LLM provider and model settings, and handles OCR page limit configuration. If any critical environment variables are missing, the function will terminate the application with a fatal error. func validateOrDefaultEnvVars() { if manualTag == "" { manualTag = "paperless-gpt" diff --git a/paperless_test.go b/paperless_test.go index 85e056a..f8a830a 100644 --- a/paperless_test.go +++ b/paperless_test.go @@ -363,7 +363,7 @@ func TestUrlEncode(t *testing.T) { assert.Equal(t, expected, result) } -// TestDownloadDocumentAsImages tests the DownloadDocumentAsImages method +// 4. The image file is successfully created on the filesystem func TestDownloadDocumentAsImages(t *testing.T) { env := newTestEnv(t) defer env.teardown() @@ -398,6 +398,9 @@ func TestDownloadDocumentAsImages(t *testing.T) { } } +// TestDownloadDocumentAsImages_ManyPages tests the DownloadDocumentAsImages method for a multi-page PDF document with a specified page limit. +// It verifies that the method correctly extracts a limited number of pages from a PDF, generates image files, and returns the correct image paths. +// The test ensures that exactly 50 pages are extracted from a 52-page document and that the image files are created in the expected location. func TestDownloadDocumentAsImages_ManyPages(t *testing.T) { env := newTestEnv(t) defer env.teardown()