bucketstorage_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. // We should be able to call validate function with and without write and delete check without any errors
  82. func TestBucketStorage_Validate(t *testing.T) {
  83. configPath := os.Getenv("TEST_BUCKET_CONFIG")
  84. if configPath == "" {
  85. t.Skip("skipping integration test, set environment variable TEST_BUCKET_CONFIG")
  86. }
  87. store, err := createStorage(configPath)
  88. if err != nil {
  89. t.Errorf("failed to create storage: %s", err.Error())
  90. return
  91. }
  92. // Validate BucketStorage with write and delete check
  93. err = Validate(store, true)
  94. if err != nil {
  95. t.Errorf("failed to validate storage: %s", err.Error())
  96. }
  97. // Validate BucketStorage without write and delete check (should not fail)
  98. err = Validate(store, false)
  99. if err != nil {
  100. t.Errorf("failed to validate storage: %s", err.Error())
  101. }
  102. }