2
0

s3storage_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package storage
  2. import (
  3. "testing"
  4. "github.com/minio/minio-go/v7"
  5. )
  6. // TestS3Storage_protocol tests the protocol() method returns correct values based on insecure flag
  7. func TestS3Storage_protocol(t *testing.T) {
  8. tests := []struct {
  9. name string
  10. insecure bool
  11. want string
  12. }{
  13. {
  14. name: "secure connection returns HTTPS",
  15. insecure: false,
  16. want: "HTTPS",
  17. },
  18. {
  19. name: "insecure connection returns HTTP",
  20. insecure: true,
  21. want: "HTTP",
  22. },
  23. }
  24. for _, tt := range tests {
  25. t.Run(tt.name, func(t *testing.T) {
  26. s3 := &S3Storage{
  27. insecure: tt.insecure,
  28. }
  29. got := s3.protocol()
  30. if got != tt.want {
  31. t.Errorf("S3Storage.protocol() = %v, want %v", got, tt.want)
  32. }
  33. })
  34. }
  35. }
  36. func TestSetGetObjectRange(t *testing.T) {
  37. tests := []struct {
  38. name string
  39. off int64
  40. length int64
  41. expectErr bool
  42. }{
  43. {
  44. name: "full object range",
  45. off: 0,
  46. length: -1,
  47. expectErr: false,
  48. },
  49. {
  50. name: "offset to EOF range",
  51. off: 100,
  52. length: -1,
  53. expectErr: false,
  54. },
  55. {
  56. name: "bounded range",
  57. off: 128,
  58. length: 4096,
  59. expectErr: false,
  60. },
  61. {
  62. name: "negative offset rejected",
  63. off: -1,
  64. length: -1,
  65. expectErr: true,
  66. },
  67. {
  68. name: "zero length rejected",
  69. off: 0,
  70. length: 0,
  71. expectErr: true,
  72. },
  73. {
  74. name: "invalid negative length rejected",
  75. off: 0,
  76. length: -2,
  77. expectErr: true,
  78. },
  79. }
  80. for _, tt := range tests {
  81. t.Run(tt.name, func(t *testing.T) {
  82. opts := &minio.GetObjectOptions{}
  83. err := setGetObjectRange(opts, tt.off, tt.length)
  84. if tt.expectErr && err == nil {
  85. t.Fatalf("expected error, got nil")
  86. }
  87. if !tt.expectErr && err != nil {
  88. t.Fatalf("unexpected error: %v", err)
  89. }
  90. })
  91. }
  92. }