- Refactored the Search method to support context-aware execution, allowing handlers to utilize context when performing searches. - Introduced a new SearchWithContext method in the handler interface to facilitate context-based search operations. - Updated the DB handler to implement the context-aware search, ensuring proper QueryDSL generation and execution. - Enhanced test cases to validate the new context requirements and scenarios for database searches, improving error handling and robustness. - Added scenario type support for QueryDSL generation, allowing for more complex query handling. - Updated documentation to reflect the new context handling and scenario features in search operations.
45 lines
1 KiB
Go
45 lines
1 KiB
Go
package testutils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
_ "github.com/yaoapp/gou/encoding"
|
|
_ "github.com/yaoapp/gou/text"
|
|
"github.com/yaoapp/yao/agent"
|
|
"github.com/yaoapp/yao/config"
|
|
"github.com/yaoapp/yao/kb"
|
|
"github.com/yaoapp/yao/query"
|
|
"github.com/yaoapp/yao/test"
|
|
)
|
|
|
|
// Prepare prepare the test environment with optional V8 mode configuration
|
|
// Usage:
|
|
//
|
|
// testutils.Prepare(t) // standard mode (default)
|
|
// testutils.Prepare(t, test.PrepareOption{V8Mode: "performance"}) // performance mode for benchmarks
|
|
func Prepare(t *testing.T, opts ...interface{}) {
|
|
test.Prepare(t, config.Conf, opts...)
|
|
|
|
// Load Query Engine (required for DB search)
|
|
err := query.Load(config.Conf)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Load KB (required for agent KB features)
|
|
_, err = kb.Load(config.Conf)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Load agent
|
|
err = agent.Load(config.Conf)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// Clean clean the test environment
|
|
func Clean(t *testing.T) {
|
|
test.Clean()
|
|
}
|