79 lines
2.7 KiB
Go
79 lines
2.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
promptkitadapter "gitea.maximumdirect.net/eric/weatherreporter/internal/adapters/promptkit"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/config"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/promptexec"
|
|
)
|
|
|
|
func TestRunnerPromptExecutorMapsConfigurationOnce(t *testing.T) {
|
|
var calls int
|
|
var received PromptExecutorConfig
|
|
runner := Runner{ExecutorFactory: func(value PromptExecutorConfig) (promptexec.Executor, error) {
|
|
calls++
|
|
received = value
|
|
return factoryExecutor{}, nil
|
|
}}
|
|
executor, err := runner.promptExecutor(config.PromptkitConfig{
|
|
Profile: "selected-profile",
|
|
ProfileFile: "/etc/weatherreporter/profile.yml",
|
|
Timeout: 45 * time.Second,
|
|
Local: config.PromptkitLocalConfig{
|
|
Endpoint: "http://127.0.0.1:8080",
|
|
ConcurrencyLimit: 3,
|
|
},
|
|
})
|
|
if err != nil || executor == nil || calls != 1 {
|
|
t.Fatalf("executor/error/calls = %#v/%v/%d", executor, err, calls)
|
|
}
|
|
want := PromptExecutorConfig{
|
|
Profile: "selected-profile", ProfileFile: "/etc/weatherreporter/profile.yml", Timeout: 45 * time.Second,
|
|
LocalEndpoint: "http://127.0.0.1:8080", LocalConcurrencyLimit: 3,
|
|
}
|
|
if received != want {
|
|
t.Fatalf("factory config = %#v, want %#v", received, want)
|
|
}
|
|
}
|
|
|
|
func TestPromptExecutorConfigLeavesBlankLocalBackendUnregistered(t *testing.T) {
|
|
value := promptExecutorConfig(config.PromptkitConfig{
|
|
Timeout: 2 * time.Minute,
|
|
Local: config.PromptkitLocalConfig{ConcurrencyLimit: 1},
|
|
})
|
|
if value.LocalEndpoint != "" || value.LocalConcurrencyLimit != 0 {
|
|
t.Fatalf("executor config = %#v, want no local backend", value)
|
|
}
|
|
}
|
|
|
|
func TestPromptkitAdapterConfigMapsExecutorSettings(t *testing.T) {
|
|
adapterConfig := promptkitAdapterConfig(PromptExecutorConfig{
|
|
ProfileDirectory: "/etc/weatherreporter/profiles",
|
|
Timeout: 30 * time.Second, LocalEndpoint: "http://127.0.0.1:8080", LocalConcurrencyLimit: 2,
|
|
})
|
|
want := promptkitadapter.Config{
|
|
ProfileDirectory: "/etc/weatherreporter/profiles",
|
|
Timeout: 30 * time.Second, LocalEndpoint: "http://127.0.0.1:8080", LocalConcurrencyLimit: 2,
|
|
}
|
|
if adapterConfig != want {
|
|
t.Fatalf("adapter config = %#v, want %#v", adapterConfig, want)
|
|
}
|
|
}
|
|
|
|
type factoryExecutor struct{}
|
|
|
|
func (factoryExecutor) InspectPrompt(context.Context, string, string) (promptexec.PromptInspection, error) {
|
|
return promptexec.PromptInspection{}, nil
|
|
}
|
|
|
|
func (factoryExecutor) InspectProfile(context.Context, string) (promptexec.ProfileInspection, error) {
|
|
return promptexec.ProfileInspection{}, nil
|
|
}
|
|
|
|
func (factoryExecutor) Execute(context.Context, promptexec.ExecuteRequest, promptexec.PreparationCallback) (*promptexec.Execution, error) {
|
|
return nil, nil
|
|
}
|