clusterstorage_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package storage
  2. import (
  3. "crypto/tls"
  4. "net/http"
  5. "strings"
  6. "testing"
  7. )
  8. // TestClusterStorage_scheme tests the scheme() method returns correct values based on TLS configuration
  9. func TestClusterStorage_scheme(t *testing.T) {
  10. tests := []struct {
  11. name string
  12. transport http.RoundTripper
  13. want string
  14. }{
  15. {
  16. name: "nil transport returns http",
  17. transport: nil,
  18. want: "http",
  19. },
  20. {
  21. name: "transport without TLS config returns http",
  22. transport: &http.Transport{},
  23. want: "http",
  24. },
  25. {
  26. name: "transport with TLS config returns https",
  27. transport: &http.Transport{
  28. TLSClientConfig: &tls.Config{},
  29. },
  30. want: "https",
  31. },
  32. {
  33. name: "transport with InsecureSkipVerify returns http",
  34. transport: &http.Transport{
  35. TLSClientConfig: &tls.Config{
  36. InsecureSkipVerify: true,
  37. },
  38. },
  39. want: "http",
  40. },
  41. }
  42. for _, tt := range tests {
  43. t.Run(tt.name, func(t *testing.T) {
  44. cs := &ClusterStorage{
  45. client: &http.Client{
  46. Transport: tt.transport,
  47. },
  48. }
  49. got := cs.scheme()
  50. if got != tt.want {
  51. t.Errorf("ClusterStorage.scheme() = %v, want %v", got, tt.want)
  52. }
  53. // Also test that strings.ToUpper(scheme()) works as expected in log statements
  54. gotUpper := strings.ToUpper(cs.scheme())
  55. wantUpper := strings.ToUpper(tt.want)
  56. if gotUpper != wantUpper {
  57. t.Errorf("strings.ToUpper(ClusterStorage.scheme()) = %v, want %v", gotUpper, wantUpper)
  58. }
  59. })
  60. }
  61. }