store_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package config_test
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "testing"
  6. "github.com/TecharoHQ/anubis/lib/config"
  7. "github.com/TecharoHQ/anubis/lib/store/bbolt"
  8. "github.com/TecharoHQ/anubis/lib/store/valkey"
  9. )
  10. func TestStoreValid(t *testing.T) {
  11. for _, tt := range []struct {
  12. err error
  13. name string
  14. input config.Store
  15. }{
  16. {
  17. name: "no backend",
  18. input: config.Store{},
  19. err: config.ErrNoStoreBackend,
  20. },
  21. {
  22. name: "in-memory backend",
  23. input: config.Store{
  24. Backend: "memory",
  25. },
  26. },
  27. {
  28. name: "bbolt backend",
  29. input: config.Store{
  30. Backend: "bbolt",
  31. Parameters: json.RawMessage(`{"path": "/tmp/foo", "bucket": "bar"}`),
  32. },
  33. },
  34. {
  35. name: "valkey backend",
  36. input: config.Store{
  37. Backend: "valkey",
  38. Parameters: json.RawMessage(`{"url": "redis://valkey:6379/0"}`),
  39. },
  40. },
  41. {
  42. name: "valkey backend no URL",
  43. input: config.Store{
  44. Backend: "valkey",
  45. Parameters: json.RawMessage(`{}`),
  46. },
  47. err: valkey.ErrNoURL,
  48. },
  49. {
  50. name: "valkey backend bad URL",
  51. input: config.Store{
  52. Backend: "valkey",
  53. Parameters: json.RawMessage(`{"url": "http://anubis.techaro.lol"}`),
  54. },
  55. err: valkey.ErrBadURL,
  56. },
  57. {
  58. name: "bbolt backend no path",
  59. input: config.Store{
  60. Backend: "bbolt",
  61. Parameters: json.RawMessage(`{"path": "", "bucket": "bar"}`),
  62. },
  63. err: bbolt.ErrMissingPath,
  64. },
  65. {
  66. name: "unknown backend",
  67. input: config.Store{
  68. Backend: "taco salad",
  69. },
  70. err: config.ErrUnknownStoreBackend,
  71. },
  72. } {
  73. t.Run(tt.name, func(t *testing.T) {
  74. if err := tt.input.Valid(); !errors.Is(err, tt.err) {
  75. t.Logf("want: %v", tt.err)
  76. t.Logf("got: %v", err)
  77. t.Error("invalid error returned")
  78. }
  79. })
  80. }
  81. }