mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-07 03:48:44 +08:00
### What problem does this PR solve? Package refactor and PDF post process. ### Type of change - [x] Refactoring --------- Co-authored-by: Claude <noreply@anthropic.com>
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
//go:build cgo
|
|
|
|
package parser
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
inf "ragflow/internal/deepdoc/parser/pdf/inference"
|
|
pdf "ragflow/internal/deepdoc/parser/pdf/type"
|
|
)
|
|
|
|
// ── Shared CGO test helpers ──────────────────────────────────────────────────
|
|
// These helpers were previously duplicated across multiple test files with
|
|
// different build tags (integration, manual). Consolidating them into one file
|
|
// with the //go:build cgo tag makes them available to all cgo-tagged tests.
|
|
|
|
// mustConnectInferenceClient returns a InferenceClient pointed at the OSS service;
|
|
// skips the test if the service reports a non-OSS model type.
|
|
func mustConnectInferenceClient(t *testing.T) *inf.InferenceClient {
|
|
t.Helper()
|
|
url := os.Getenv("OSSDEEPDOC_URL")
|
|
if url == "" {
|
|
url = "http://localhost:9390"
|
|
}
|
|
client, err := inf.NewInferenceClient(url)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !client.Health() {
|
|
t.Fatalf("OssDeepDoc not available at %s", url)
|
|
}
|
|
return client
|
|
}
|
|
|
|
// mustOpenEngine opens a PDF from testdata/pdfs/ and returns a pdf.PDFEngine.
|
|
func mustOpenEngine(t *testing.T, name string) pdf.PDFEngine {
|
|
t.Helper()
|
|
pdfPath := filepath.Join("testdata", "pdfs", name)
|
|
data, err := os.ReadFile(pdfPath)
|
|
if err != nil {
|
|
t.Fatalf("read fixture %s: %v", name, err)
|
|
}
|
|
eng, err := NewEngine(data)
|
|
if err != nil {
|
|
t.Fatalf("open engine %s: %v", name, err)
|
|
}
|
|
return eng
|
|
}
|