Expose captured resource inspection through the engine
This commit is contained in:
45
resource_inspection_api_test.go
Normal file
45
resource_inspection_api_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package promptkit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestResourceInspectionSelections(t *testing.T) {
|
||||
engine, err := NewEngine(Config{Sources: ConfigurationSources{Main: &configkit.Input{Source: configkit.Mapping("resources", map[string]any{
|
||||
"backends": []any{map[string]any{"id": "local", "endpoint": "https://example.test/v1"}},
|
||||
"profiles": []any{map[string]any{"id": "partial", "backend": "local"}},
|
||||
"prompts": []any{map[string]any{"id": "prompt", "messages": []any{map[string]any{"role": "user", "content": "hello"}}, "output": map[string]any{"format": "text", "validation_mode": "basic"}}},
|
||||
})}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
if got, err := engine.InspectBackend(ctx, "local"); err != nil || got.BackendID != "local" {
|
||||
t.Fatalf("backend = %+v, %v", got, err)
|
||||
}
|
||||
if got, err := engine.InspectProfile(ctx, "partial"); err != nil || got.Backend == nil || *got.Backend != "local" || got.Endpoint != nil {
|
||||
t.Fatalf("profile = %+v, %v", got, err)
|
||||
}
|
||||
if got, err := engine.InspectPrompt(ctx, "prompt"); err != nil || got.Messages[0].Content != "hello" {
|
||||
t.Fatalf("prompt = %+v, %v", got, err)
|
||||
}
|
||||
if got, err := engine.InspectBackend(ctx, "missing"); got != nil || !errors.Is(err, ErrBackendNotFound) || errors.Is(err, ErrInvalidRequest) {
|
||||
t.Fatalf("missing = %+v, %v", got, err)
|
||||
}
|
||||
if _, err := engine.InspectBackend(ctx, "bad/id/extra"); !errors.Is(err, ErrInvalidRequest) {
|
||||
t.Fatalf("invalid ID = %v", err)
|
||||
}
|
||||
var nilEngine *Engine
|
||||
if _, err := nilEngine.InspectBackend(ctx, "local"); !errors.Is(err, ErrInvalidConfig) {
|
||||
t.Fatalf("nil engine = %v", err)
|
||||
}
|
||||
canceled, cancel := context.WithCancel(ctx)
|
||||
cancel()
|
||||
if _, err := engine.InspectBackend(canceled, "local"); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("canceled = %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user