package config import ( "os" "path/filepath" "testing" ) const validConfig = ` bot: admin_role: "123456789" logs_channel: "111" claim_channel: "222" convocation_category: "333" claim_reup_minutes: 15 panels: support_panel: embed_title: "Support" embed_description: "Choisis" embed_color: "#2b2d31" types: support: button_label: "Support" button_color: "primary" embed_color: "#5865f2" embed_title: "Ticket support" embed_text: "Décris ton problème." staff_role: "444" category: "555" ` func writeConfig(t *testing.T, content string) string { t.Helper() f := filepath.Join(t.TempDir(), "config.yaml") if err := os.WriteFile(f, []byte(content), 0644); err != nil { t.Fatal(err) } return f } func TestLoadValidConfig(t *testing.T) { cfg, err := Load(writeConfig(t, validConfig)) if err != nil { t.Fatalf("Load: %v", err) } if cfg.Bot.AdminRole != "123456789" { t.Errorf("admin_role = %q, want 123456789", cfg.Bot.AdminRole) } if cfg.Bot.ClaimReupMinutes != 15 { t.Errorf("claim_reup_minutes = %d, want 15", cfg.Bot.ClaimReupMinutes) } panel, ok := cfg.Panels["support_panel"] if !ok { t.Fatal("support_panel missing") } if _, ok := panel.Types["support"]; !ok { t.Fatal("support type missing") } } func TestLoadMissingAdminRole(t *testing.T) { f := writeConfig(t, "bot:\n logs_channel: \"111\"\n") _, err := Load(f) if err == nil { t.Fatal("expected error for missing admin_role") } } func TestDefaultReupMinutes(t *testing.T) { f := writeConfig(t, "bot:\n admin_role: \"123\"\n") cfg, err := Load(f) if err != nil { t.Fatal(err) } if cfg.Bot.ClaimReupMinutes != 30 { t.Errorf("default reup = %d, want 30", cfg.Bot.ClaimReupMinutes) } } func TestProviderSwap(t *testing.T) { cfg1 := &Config{Bot: Bot{AdminRole: "a"}} p := NewProvider(cfg1) if p.Get().Bot.AdminRole != "a" { t.Fatal("initial get failed") } cfg2 := &Config{Bot: Bot{AdminRole: "b"}} p.Swap(cfg2) if p.Get().Bot.AdminRole != "b" { t.Fatal("swap failed") } }