TestConfig.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. const fs = require('fs')
  2. const Path = require('path')
  3. // use functions to get a fresh copy, not a reference, each time
  4. function s3Config() {
  5. return {
  6. key: process.env.AWS_ACCESS_KEY_ID,
  7. secret: process.env.AWS_SECRET_ACCESS_KEY,
  8. endpoint: process.env.AWS_S3_ENDPOINT,
  9. pathStyle: true,
  10. partSize: 100 * 1024 * 1024,
  11. }
  12. }
  13. function s3ConfigDefaultProviderCredentials() {
  14. return {
  15. endpoint: process.env.AWS_S3_ENDPOINT,
  16. pathStyle: true,
  17. partSize: 100 * 1024 * 1024,
  18. }
  19. }
  20. function s3Stores() {
  21. return {
  22. user_files: process.env.AWS_S3_USER_FILES_BUCKET_NAME,
  23. template_files: process.env.AWS_S3_TEMPLATE_FILES_BUCKET_NAME,
  24. }
  25. }
  26. function gcsConfig() {
  27. return {
  28. endpoint: {
  29. apiEndpoint: process.env.GCS_API_ENDPOINT,
  30. projectId: 'fake',
  31. },
  32. directoryKeyRegex: /^[0-9a-fA-F]{24}\/[0-9a-fA-F]{24}/,
  33. unlockBeforeDelete: false, // fake-gcs does not support this
  34. deletedBucketSuffix: '-deleted',
  35. }
  36. }
  37. function gcsStores() {
  38. return {
  39. user_files: process.env.GCS_USER_FILES_BUCKET_NAME,
  40. template_files: process.env.GCS_TEMPLATE_FILES_BUCKET_NAME,
  41. }
  42. }
  43. function fsStores() {
  44. return {
  45. user_files: Path.resolve(__dirname, '../../../user_files'),
  46. template_files: Path.resolve(__dirname, '../../../template_files'),
  47. }
  48. }
  49. function fallbackStores(primaryConfig, fallbackConfig) {
  50. return {
  51. [primaryConfig.user_files]: fallbackConfig.user_files,
  52. [primaryConfig.template_files]: fallbackConfig.template_files,
  53. }
  54. }
  55. module.exports = {
  56. SHARD_01_FSPersistor: {
  57. backend: 'fs',
  58. stores: fsStores(),
  59. },
  60. SHARD_01_S3Persistor: {
  61. backend: 's3',
  62. s3: s3Config(),
  63. stores: s3Stores(),
  64. },
  65. SHARD_01_S3PersistorDefaultProviderCredentials: {
  66. backend: 's3',
  67. s3: s3ConfigDefaultProviderCredentials(),
  68. stores: s3Stores(),
  69. },
  70. SHARD_01_GcsPersistor: {
  71. backend: 'gcs',
  72. gcs: gcsConfig(),
  73. stores: gcsStores(),
  74. },
  75. SHARD_02_FallbackS3ToFSPersistor: {
  76. backend: 's3',
  77. s3: s3Config(),
  78. stores: s3Stores(),
  79. fallback: {
  80. backend: 'fs',
  81. buckets: fallbackStores(s3Stores(), fsStores()),
  82. },
  83. },
  84. SHARD_02_FallbackFSToS3Persistor: {
  85. backend: 'fs',
  86. s3: s3Config(),
  87. stores: fsStores(),
  88. fallback: {
  89. backend: 's3',
  90. buckets: fallbackStores(fsStores(), s3Stores()),
  91. },
  92. },
  93. SHARD_03_FallbackGcsToS3Persistor: {
  94. backend: 'gcs',
  95. gcs: gcsConfig(),
  96. stores: gcsStores(),
  97. s3: s3Config(),
  98. fallback: {
  99. backend: 's3',
  100. buckets: fallbackStores(gcsStores(), s3Stores()),
  101. },
  102. },
  103. SHARD_03_FallbackS3ToGcsPersistor: {
  104. backend: 's3',
  105. // can use the same bucket names for gcs and s3 (in tests)
  106. stores: s3Stores(),
  107. s3: s3Config(),
  108. gcs: gcsConfig(),
  109. fallback: {
  110. backend: 'gcs',
  111. buckets: fallbackStores(s3Stores(), gcsStores()),
  112. },
  113. },
  114. }
  115. function checkForUnexpectedTestFile() {
  116. const awareOfSharding = [
  117. 'FilestoreApp.js',
  118. 'FilestoreTests.js',
  119. 'TestConfig.js',
  120. 'TestHelper.js',
  121. ]
  122. for (const file of fs.readdirSync(__dirname).sort()) {
  123. if (!awareOfSharding.includes(file)) {
  124. throw new Error(
  125. `Found new test file ${file}: All tests must be aware of the SHARD_ prefix.`
  126. )
  127. }
  128. }
  129. }
  130. checkForUnexpectedTestFile()