Files
fil/e2e/go/error_test.go

81 lines
2.6 KiB
Go
Raw Permalink Normal View History

2026-06-01 23:40:55 +02:00
// This file is auto-generated by alef — DO NOT EDIT.
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
// To regenerate: alef generate
// To verify freshness: alef verify --exit-code
// Issues & docs: https://github.com/kreuzberg-dev/alef
// E2e tests for category: error
package e2e_test
import (
"encoding/json"
"os"
"testing"
kreuzberg "github.com/kreuzberg-dev/kreuzberg/v5"
)
func Test_ErrorEmptyBytes(t *testing.T) {
// Graceful handling of empty bytes (should not error)
contentBytes, contentBytesErr := os.ReadFile(`text/empty.txt`)
if contentBytesErr != nil {
t.Fatalf("read fixture text/empty.txt: %v", contentBytesErr)
}
_, err := kreuzberg.ExtractBytesSync(contentBytes, `text/plain`, kreuzberg.ExtractionConfig{})
if err != nil {
t.Fatalf("call failed: %v", err)
}
}
func Test_ErrorEmptyMime(t *testing.T) {
// Error when extracting with empty MIME type
contentBytes, contentBytesErr := os.ReadFile(`text/plain.txt`)
if contentBytesErr != nil {
t.Fatalf("read fixture text/plain.txt: %v", contentBytesErr)
}
_, err := kreuzberg.ExtractBytesSync(contentBytes, ``, kreuzberg.ExtractionConfig{})
if err == nil {
t.Errorf("expected an error, but call succeeded")
}
}
func Test_ErrorExtractBytesConflictingOcr(t *testing.T) {
// extract_bytes force+disable OCR
contentBytes, contentBytesErr := os.ReadFile(`text/fake_text.txt`)
if contentBytesErr != nil {
t.Fatalf("read fixture text/fake_text.txt: %v", contentBytesErr)
}
var config kreuzberg.ExtractionConfig
if err := json.Unmarshal([]byte(`{"disable_ocr":true,"force_ocr":true}`), &config); err != nil {
t.Fatalf("config parse failed: %v", err)
}
_, err := kreuzberg.ExtractBytesSync(contentBytes, `text/plain`, config)
if err == nil {
t.Errorf("expected an error, but call succeeded")
}
}
func Test_ErrorInvalidMimeFormat(t *testing.T) {
// Error when extracting with invalid MIME type format
contentBytes, contentBytesErr := os.ReadFile(`text/plain.txt`)
if contentBytesErr != nil {
t.Fatalf("read fixture text/plain.txt: %v", contentBytesErr)
}
_, err := kreuzberg.ExtractBytesSync(contentBytes, `not-a-mime`, kreuzberg.ExtractionConfig{})
if err == nil {
t.Errorf("expected an error, but call succeeded")
}
}
func Test_ErrorUnsupportedMime(t *testing.T) {
// Error when extracting with unsupported MIME type
contentBytes, contentBytesErr := os.ReadFile(`text/plain.txt`)
if contentBytesErr != nil {
t.Fatalf("read fixture text/plain.txt: %v", contentBytesErr)
}
_, err := kreuzberg.ExtractBytesSync(contentBytes, `application/x-nonexistent`, kreuzberg.ExtractionConfig{})
if err == nil {
t.Errorf("expected an error, but call succeeded")
}
}