Add support for multiple providers
This commit is contained in:
@@ -4,22 +4,24 @@ import (
|
||||
"log/slog"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.chimeric.al/chimerical/odidere/internal/config"
|
||||
)
|
||||
|
||||
func TestConfigValidate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
config Config
|
||||
config config.JobConfig
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "empty config",
|
||||
config: Config{},
|
||||
config: config.JobConfig{},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "missing name",
|
||||
config: Config{
|
||||
config: config.JobConfig{
|
||||
Schedule: "0 9 * * *",
|
||||
Task: "do something",
|
||||
},
|
||||
@@ -27,7 +29,7 @@ func TestConfigValidate(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "missing task",
|
||||
config: Config{
|
||||
config: config.JobConfig{
|
||||
Name: "test",
|
||||
Schedule: "0 9 * * *",
|
||||
},
|
||||
@@ -35,7 +37,7 @@ func TestConfigValidate(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "missing schedule",
|
||||
config: Config{
|
||||
config: config.JobConfig{
|
||||
Name: "test",
|
||||
Task: "do something",
|
||||
},
|
||||
@@ -43,7 +45,7 @@ func TestConfigValidate(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "negative max iterations",
|
||||
config: Config{
|
||||
config: config.JobConfig{
|
||||
Name: "test",
|
||||
Task: "do something",
|
||||
Schedule: "0 9 * * *",
|
||||
@@ -53,7 +55,7 @@ func TestConfigValidate(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "minimal valid config",
|
||||
config: Config{
|
||||
config: config.JobConfig{
|
||||
Name: "test",
|
||||
Task: "do something",
|
||||
Schedule: "0 9 * * *",
|
||||
@@ -62,7 +64,7 @@ func TestConfigValidate(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "full valid config",
|
||||
config: Config{
|
||||
config: config.JobConfig{
|
||||
Name: "test",
|
||||
Task: "do something",
|
||||
Schedule: "0 9 * * *",
|
||||
@@ -84,31 +86,9 @@ func TestConfigValidate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigIsEnabled(t *testing.T) {
|
||||
// nil enabled → defaults to true
|
||||
cfg := Config{Name: "test"}
|
||||
if !cfg.IsEnabled() {
|
||||
t.Error("expected nil enabled to be true")
|
||||
}
|
||||
|
||||
// explicit true
|
||||
enabled := true
|
||||
cfg.Enabled = &enabled
|
||||
if !cfg.IsEnabled() {
|
||||
t.Error("expected explicit true")
|
||||
}
|
||||
|
||||
// explicit false
|
||||
disabled := false
|
||||
cfg.Enabled = &disabled
|
||||
if cfg.IsEnabled() {
|
||||
t.Error("expected explicit false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigMaxIterations(t *testing.T) {
|
||||
// Zero means unlimited
|
||||
cfg := Config{Name: "test"}
|
||||
cfg := config.JobConfig{Name: "test"}
|
||||
if got := cfg.MaxIterations; got != 0 {
|
||||
t.Errorf("default max iterations = %d, want 0", got)
|
||||
}
|
||||
@@ -126,7 +106,7 @@ func TestConfigMaxIterations(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConfigTimeout(t *testing.T) {
|
||||
cfg := Config{Name: "test"}
|
||||
cfg := config.JobConfig{Name: "test"}
|
||||
if cfg.Timeout != "" {
|
||||
t.Errorf("default timeout = %q, want empty", cfg.Timeout)
|
||||
}
|
||||
@@ -142,7 +122,7 @@ func TestConfigTimeout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
cfg := Config{
|
||||
cfg := config.JobConfig{
|
||||
Name: "test",
|
||||
Task: "do something",
|
||||
Schedule: "0 9 * * *",
|
||||
@@ -151,7 +131,7 @@ func TestNew(t *testing.T) {
|
||||
SystemMessage: "You are an assistant.",
|
||||
}
|
||||
|
||||
j, err := New(cfg, slog.Default(), nil)
|
||||
j, err := New(cfg, slog.Default(), nil, "test-model")
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
@@ -162,9 +142,6 @@ func TestNew(t *testing.T) {
|
||||
if j.Schedule() != "0 9 * * *" {
|
||||
t.Errorf("Schedule() = %q, want %q", j.Schedule(), "0 9 * * *")
|
||||
}
|
||||
if !j.IsEnabled() {
|
||||
t.Error("IsEnabled() = false, want true")
|
||||
}
|
||||
if j.SystemMessage() != "You are an assistant." {
|
||||
t.Errorf("SystemMessage() = %q, want %q", j.SystemMessage(), "You are an assistant.")
|
||||
}
|
||||
@@ -177,52 +154,36 @@ func TestNew(t *testing.T) {
|
||||
if j.MaxIterations() != 20 {
|
||||
t.Errorf("MaxIterations() = %d, want 20", j.MaxIterations())
|
||||
}
|
||||
if j.Model() != "test-model" {
|
||||
t.Errorf("Model() = %q, want %q", j.Model(), "test-model")
|
||||
}
|
||||
if j.Cron() == nil {
|
||||
t.Error("Cron() = nil, want non-nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNew_Disabled(t *testing.T) {
|
||||
disabled := false
|
||||
cfg := Config{
|
||||
Name: "test",
|
||||
Task: "do something",
|
||||
Schedule: "0 9 * * *",
|
||||
Enabled: &disabled,
|
||||
}
|
||||
|
||||
j, err := New(cfg, slog.Default(), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
|
||||
if j.IsEnabled() {
|
||||
t.Error("IsEnabled() = true, want false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNew_InvalidSchedule(t *testing.T) {
|
||||
cfg := Config{
|
||||
cfg := config.JobConfig{
|
||||
Name: "test",
|
||||
Task: "do something",
|
||||
Schedule: "not-a-cron",
|
||||
}
|
||||
|
||||
_, err := New(cfg, slog.Default(), nil)
|
||||
_, err := New(cfg, slog.Default(), nil, "test-model")
|
||||
if err == nil {
|
||||
t.Fatal("New() expected error for invalid schedule")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNew_InvalidTimeout(t *testing.T) {
|
||||
cfg := Config{
|
||||
cfg := config.JobConfig{
|
||||
Name: "test",
|
||||
Task: "do something",
|
||||
Schedule: "0 9 * * *",
|
||||
Timeout: "not-a-duration",
|
||||
}
|
||||
|
||||
_, err := New(cfg, slog.Default(), nil)
|
||||
_, err := New(cfg, slog.Default(), nil, "test-model")
|
||||
if err == nil {
|
||||
t.Fatal("New() expected error for invalid timeout")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user