options_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package apiv1
  2. import (
  3. "testing"
  4. )
  5. func TestOptions_Validate(t *testing.T) {
  6. tests := []struct {
  7. name string
  8. options *Options
  9. wantErr bool
  10. }{
  11. {"nil", nil, false},
  12. {"softkms", &Options{Type: "softkms"}, false},
  13. {"cloudkms", &Options{Type: "cloudkms"}, false},
  14. {"awskms", &Options{Type: "awskms"}, false},
  15. {"sshagentkms", &Options{Type: "sshagentkms"}, false},
  16. {"pkcs11", &Options{Type: "pkcs11"}, false},
  17. {"unsupported", &Options{Type: "unsupported"}, true},
  18. }
  19. for _, tt := range tests {
  20. t.Run(tt.name, func(t *testing.T) {
  21. if err := tt.options.Validate(); (err != nil) != tt.wantErr {
  22. t.Errorf("Options.Validate() error = %v, wantErr %v", err, tt.wantErr)
  23. }
  24. })
  25. }
  26. }
  27. func TestErrNotImplemented_Error(t *testing.T) {
  28. type fields struct {
  29. msg string
  30. }
  31. tests := []struct {
  32. name string
  33. fields fields
  34. want string
  35. }{
  36. {"default", fields{}, "not implemented"},
  37. {"custom", fields{"custom message: not implemented"}, "custom message: not implemented"},
  38. }
  39. for _, tt := range tests {
  40. t.Run(tt.name, func(t *testing.T) {
  41. e := ErrNotImplemented{
  42. Message: tt.fields.msg,
  43. }
  44. if got := e.Error(); got != tt.want {
  45. t.Errorf("ErrNotImplemented.Error() = %v, want %v", got, tt.want)
  46. }
  47. })
  48. }
  49. }
  50. func TestErrAlreadyExists_Error(t *testing.T) {
  51. type fields struct {
  52. msg string
  53. }
  54. tests := []struct {
  55. name string
  56. fields fields
  57. want string
  58. }{
  59. {"default", fields{}, "key already exists"},
  60. {"custom", fields{"custom message: key already exists"}, "custom message: key already exists"},
  61. }
  62. for _, tt := range tests {
  63. t.Run(tt.name, func(t *testing.T) {
  64. e := ErrAlreadyExists{
  65. Message: tt.fields.msg,
  66. }
  67. if got := e.Error(); got != tt.want {
  68. t.Errorf("ErrAlreadyExists.Error() = %v, want %v", got, tt.want)
  69. }
  70. })
  71. }
  72. }