From d750365ed9e733036471fb9f78cd04d24f8ffecc Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 10 Aug 2025 17:21:13 +0800 Subject: [PATCH] Add tests for Structured and Semantic schema retrieval - Introduced new test cases for Structured and Semantic providers to validate schema retrieval functionality. - Updated existing tests across various providers to ensure they check for non-nil schemas, enhancing error handling and test coverage. - Ensured consistency in error messages for schema validation across different provider tests. --- kb/providers/chunking_test.go | 22 ++++++++++++++++++++++ kb/providers/converters/mcp_test.go | 4 ++-- kb/providers/converters/ocr_test.go | 4 ++-- kb/providers/converters/office_test.go | 4 ++-- kb/providers/converters/utf8_test.go | 4 ++-- kb/providers/converters/video_test.go | 4 ++-- kb/providers/converters/vision_test.go | 4 ++-- kb/providers/converters/whisper_test.go | 4 ++-- kb/providers/embedding_test.go | 8 ++++---- kb/providers/extractor_test.go | 4 ++-- kb/providers/fetcher_test.go | 8 ++++---- 11 files changed, 46 insertions(+), 24 deletions(-) diff --git a/kb/providers/chunking_test.go b/kb/providers/chunking_test.go index 09ed6e95..945dbf48 100644 --- a/kb/providers/chunking_test.go +++ b/kb/providers/chunking_test.go @@ -400,3 +400,25 @@ func TestSemantic_Options(t *testing.T) { } }) } + +func TestStructured_Schema(t *testing.T) { + s := &Structured{} + schema, err := s.Schema(nil, "en") + if err != nil { + t.Errorf("Expected no error, got %v", err) + } + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") + } +} + +func TestSemantic_Schema(t *testing.T) { + s := &Semantic{} + schema, err := s.Schema(nil, "en") + if err != nil { + t.Errorf("Expected no error, got %v", err) + } + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") + } +} diff --git a/kb/providers/converters/mcp_test.go b/kb/providers/converters/mcp_test.go index e4f6858d..0f8b087e 100644 --- a/kb/providers/converters/mcp_test.go +++ b/kb/providers/converters/mcp_test.go @@ -224,7 +224,7 @@ func TestMCP_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } } diff --git a/kb/providers/converters/ocr_test.go b/kb/providers/converters/ocr_test.go index a82ec448..f51c1e55 100644 --- a/kb/providers/converters/ocr_test.go +++ b/kb/providers/converters/ocr_test.go @@ -401,7 +401,7 @@ func TestOCR_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } } diff --git a/kb/providers/converters/office_test.go b/kb/providers/converters/office_test.go index 22505ed3..8dc40e5c 100644 --- a/kb/providers/converters/office_test.go +++ b/kb/providers/converters/office_test.go @@ -307,7 +307,7 @@ func TestOffice_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } } diff --git a/kb/providers/converters/utf8_test.go b/kb/providers/converters/utf8_test.go index e7241839..06424089 100644 --- a/kb/providers/converters/utf8_test.go +++ b/kb/providers/converters/utf8_test.go @@ -125,7 +125,7 @@ func TestUTF8_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } } diff --git a/kb/providers/converters/video_test.go b/kb/providers/converters/video_test.go index dbc16022..a370489a 100644 --- a/kb/providers/converters/video_test.go +++ b/kb/providers/converters/video_test.go @@ -248,7 +248,7 @@ func TestVideo_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } } diff --git a/kb/providers/converters/vision_test.go b/kb/providers/converters/vision_test.go index 7c853645..74d5faba 100644 --- a/kb/providers/converters/vision_test.go +++ b/kb/providers/converters/vision_test.go @@ -186,7 +186,7 @@ func TestVision_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } } diff --git a/kb/providers/converters/whisper_test.go b/kb/providers/converters/whisper_test.go index 1d29c775..38afd3b0 100644 --- a/kb/providers/converters/whisper_test.go +++ b/kb/providers/converters/whisper_test.go @@ -217,7 +217,7 @@ func TestWhisper_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } } diff --git a/kb/providers/embedding_test.go b/kb/providers/embedding_test.go index 249163bd..fcc77c83 100644 --- a/kb/providers/embedding_test.go +++ b/kb/providers/embedding_test.go @@ -126,8 +126,8 @@ func TestOpenAI_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } } @@ -287,7 +287,7 @@ func TestFastembed_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } } diff --git a/kb/providers/extractor_test.go b/kb/providers/extractor_test.go index 1d32f908..e688f32e 100644 --- a/kb/providers/extractor_test.go +++ b/kb/providers/extractor_test.go @@ -283,7 +283,7 @@ func TestExtractorOpenAI_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } } diff --git a/kb/providers/fetcher_test.go b/kb/providers/fetcher_test.go index c34fa819..1bdce576 100644 --- a/kb/providers/fetcher_test.go +++ b/kb/providers/fetcher_test.go @@ -187,8 +187,8 @@ func TestFetcherHTTP_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } } @@ -445,7 +445,7 @@ func TestFetcherMCP_Schema(t *testing.T) { if err != nil { t.Errorf("Expected no error, got %v", err) } - if schema != nil { - t.Error("Expected nil schema") + if schema == nil { + t.Error("Expected non-nil schema from factory.GetSchemaFromBindata") } }