templates_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package templates
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. func TestAll_SeedComplete(t *testing.T) {
  7. want := []string{
  8. "anthropic-official",
  9. "openrouter",
  10. "deepseek",
  11. "moonshot",
  12. "zhipu",
  13. "custom-base",
  14. }
  15. got := All()
  16. if len(got) != len(want) {
  17. t.Fatalf("template count: got %d, want %d", len(got), len(want))
  18. }
  19. have := map[string]bool{}
  20. for _, tpl := range got {
  21. if tpl.Description == "" {
  22. t.Errorf("%q: missing description", tpl.Name)
  23. }
  24. if len(tpl.Env) == 0 {
  25. t.Errorf("%q: empty env", tpl.Name)
  26. }
  27. for _, e := range tpl.Env {
  28. if e.Name == "" {
  29. t.Errorf("%q: empty env key name", tpl.Name)
  30. }
  31. }
  32. have[tpl.Name] = true
  33. }
  34. for _, n := range want {
  35. if !have[n] {
  36. t.Errorf("missing seed template %q", n)
  37. }
  38. }
  39. }
  40. func TestGet(t *testing.T) {
  41. tpl, ok := Get("openrouter")
  42. if !ok {
  43. t.Fatal("openrouter missing")
  44. }
  45. if tpl.Name != "openrouter" {
  46. t.Errorf("name: %q", tpl.Name)
  47. }
  48. if _, ok := Get("nonexistent"); ok {
  49. t.Error("nonexistent template should miss")
  50. }
  51. }
  52. func TestNamesSorted(t *testing.T) {
  53. got := Names()
  54. want := []string{
  55. "anthropic-official",
  56. "custom-base",
  57. "deepseek",
  58. "moonshot",
  59. "openrouter",
  60. "zhipu",
  61. }
  62. if !reflect.DeepEqual(got, want) {
  63. t.Errorf("sorted names: got %v want %v", got, want)
  64. }
  65. }
  66. func TestParseInvalid(t *testing.T) {
  67. cases := []string{
  68. `templates:
  69. - name: ""
  70. env:
  71. - name: K`,
  72. `templates:
  73. - name: ok
  74. env: []`,
  75. `templates:
  76. - name: ok
  77. env:
  78. - name: ""`,
  79. }
  80. for i, c := range cases {
  81. if _, err := Parse([]byte(c)); err == nil {
  82. t.Errorf("case %d: expected error, got nil", i)
  83. }
  84. }
  85. }