bucketstorage_test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package storage
  2. import (
  3. "fmt"
  4. "os"
  5. "testing"
  6. )
  7. // This suite of integration tests is meant to validate if an implementation of Storage that relies on a could
  8. // bucket service properly implements the interface. To run these tests the env variable "TEST_BUCKET_CONFIG"
  9. // must be set with the path to a valid bucket config as defined in the NewBucketStorage() function.
  10. func createStorage(configPath string) (Storage, error) {
  11. bytes, err := os.ReadFile(configPath)
  12. if err != nil {
  13. return nil, fmt.Errorf("failed to read config file: %w", err)
  14. }
  15. store, err := NewBucketStorage(bytes)
  16. if err != nil {
  17. return nil, fmt.Errorf("failed to initialize storage: %w", err)
  18. }
  19. return store, nil
  20. }
  21. func TestBucketStorage_List(t *testing.T) {
  22. configPath := os.Getenv("TEST_BUCKET_CONFIG")
  23. if configPath == "" {
  24. t.Skip("skipping integration test, set environment variable TEST_BUCKET_CONFIG")
  25. }
  26. store, err := createStorage(configPath)
  27. if err != nil {
  28. t.Errorf("failed to create storage: %s", err.Error())
  29. return
  30. }
  31. TestStorageList(t, store)
  32. }
  33. func TestBucketStorage_ListDirectories(t *testing.T) {
  34. configPath := os.Getenv("TEST_BUCKET_CONFIG")
  35. if configPath == "" {
  36. t.Skip("skipping integration test, set environment variable TEST_BUCKET_CONFIG")
  37. }
  38. store, err := createStorage(configPath)
  39. if err != nil {
  40. t.Errorf("failed to create storage: %s", err.Error())
  41. return
  42. }
  43. TestStorageListDirectories(t, store)
  44. }
  45. func TestBucketStorage_Exists(t *testing.T) {
  46. configPath := os.Getenv("TEST_BUCKET_CONFIG")
  47. if configPath == "" {
  48. t.Skip("skipping integration test, set environment variable TEST_BUCKET_CONFIG")
  49. }
  50. store, err := createStorage(configPath)
  51. if err != nil {
  52. t.Errorf("failed to create storage: %s", err.Error())
  53. return
  54. }
  55. TestStorageExists(t, store)
  56. }
  57. func TestBucketStorage_Read(t *testing.T) {
  58. configPath := os.Getenv("TEST_BUCKET_CONFIG")
  59. if configPath == "" {
  60. t.Skip("skipping integration test, set environment variable TEST_BUCKET_CONFIG")
  61. }
  62. store, err := createStorage(configPath)
  63. if err != nil {
  64. t.Errorf("failed to create storage: %s", err.Error())
  65. return
  66. }
  67. TestStorageRead(t, store)
  68. }
  69. func TestBucketStorage_Stat(t *testing.T) {
  70. configPath := os.Getenv("TEST_BUCKET_CONFIG")
  71. if configPath == "" {
  72. t.Skip("skipping integration test, set environment variable TEST_BUCKET_CONFIG")
  73. }
  74. store, err := createStorage(configPath)
  75. if err != nil {
  76. t.Errorf("failed to create storage: %s", err.Error())
  77. return
  78. }
  79. TestStorageStat(t, store)
  80. }
  81. func TestBucketStorage_ReadToLocalFile(t *testing.T) {
  82. configPath := os.Getenv("TEST_BUCKET_CONFIG")
  83. if configPath == "" {
  84. t.Skip("skipping integration test, set environment variable TEST_BUCKET_CONFIG")
  85. }
  86. store, err := createStorage(configPath)
  87. if err != nil {
  88. t.Errorf("failed to create storage: %s", err.Error())
  89. return
  90. }
  91. TestStorageReadToLocalFile(t, store)
  92. }
  93. func TestBucketStorage_ReadStream(t *testing.T) {
  94. configPath := os.Getenv("TEST_BUCKET_CONFIG")
  95. if configPath == "" {
  96. t.Skip("skipping integration test, set environment variable TEST_BUCKET_CONFIG")
  97. }
  98. store, err := createStorage(configPath)
  99. if err != nil {
  100. t.Errorf("failed to create storage: %s", err.Error())
  101. return
  102. }
  103. TestStorageReadStream(t, store)
  104. }
  105. // We should be able to call validate function with and without write and delete check without any errors
  106. func TestBucketStorage_Validate(t *testing.T) {
  107. configPath := os.Getenv("TEST_BUCKET_CONFIG")
  108. if configPath == "" {
  109. t.Skip("skipping integration test, set environment variable TEST_BUCKET_CONFIG")
  110. }
  111. store, err := createStorage(configPath)
  112. if err != nil {
  113. t.Errorf("failed to create storage: %s", err.Error())
  114. return
  115. }
  116. // Validate BucketStorage with write and delete check
  117. err = Validate(store, true)
  118. if err != nil {
  119. t.Errorf("failed to validate storage: %s", err.Error())
  120. }
  121. // Validate BucketStorage without write and delete check (should not fail)
  122. err = Validate(store, false)
  123. if err != nil {
  124. t.Errorf("failed to validate storage: %s", err.Error())
  125. }
  126. }