aboutsummaryrefslogtreecommitdiffstats
path: root/test/site
diff options
context:
space:
mode:
Diffstat (limited to 'test/site')
-rw-r--r--test/site/.gitignore1
-rw-r--r--test/site/configurations-example.yml11
-rw-r--r--test/site/disk_site_test.rb8
-rw-r--r--test/site/gcs_site_test.rb11
-rw-r--r--test/site/s3_site_test.rb11
-rw-r--r--test/site/shared_site_tests.rb63
6 files changed, 105 insertions, 0 deletions
diff --git a/test/site/.gitignore b/test/site/.gitignore
new file mode 100644
index 0000000000..c102131f3d
--- /dev/null
+++ b/test/site/.gitignore
@@ -0,0 +1 @@
+configurations.yml
diff --git a/test/site/configurations-example.yml b/test/site/configurations-example.yml
new file mode 100644
index 0000000000..031197342a
--- /dev/null
+++ b/test/site/configurations-example.yml
@@ -0,0 +1,11 @@
+# Copy this file to configurations.yml and edit the credentials to match your IAM test account and bucket
+s3:
+ access_key_id:
+ secret_access_key:
+ region:
+ bucket:
+
+gcs:
+ project:
+ keyfile:
+ bucket:
diff --git a/test/site/disk_site_test.rb b/test/site/disk_site_test.rb
new file mode 100644
index 0000000000..63f12ad335
--- /dev/null
+++ b/test/site/disk_site_test.rb
@@ -0,0 +1,8 @@
+require "tmpdir"
+require "site/shared_site_tests"
+
+class ActiveFile::Site::DiskSiteTest < ActiveSupport::TestCase
+ SITE = ActiveFile::Site.configure(:Disk, root: File.join(Dir.tmpdir, "active_file"))
+
+ include ActiveFile::Site::SharedSiteTests
+end
diff --git a/test/site/gcs_site_test.rb b/test/site/gcs_site_test.rb
new file mode 100644
index 0000000000..c5f32a0595
--- /dev/null
+++ b/test/site/gcs_site_test.rb
@@ -0,0 +1,11 @@
+require "site/shared_site_tests"
+
+if SITE_CONFIGURATIONS[:gcs]
+ class ActiveFile::Site::GCSSiteTest < ActiveSupport::TestCase
+ SITE = ActiveFile::Site.configure(:GCS, SITE_CONFIGURATIONS[:gcs])
+
+ include ActiveFile::Site::SharedSiteTests
+ end
+else
+ puts "Skipping GCS Site tests because no GCS configuration was supplied"
+end
diff --git a/test/site/s3_site_test.rb b/test/site/s3_site_test.rb
new file mode 100644
index 0000000000..7629b78ad5
--- /dev/null
+++ b/test/site/s3_site_test.rb
@@ -0,0 +1,11 @@
+require "site/shared_site_tests"
+
+if SITE_CONFIGURATIONS[:s3]
+ class ActiveFile::Site::S3SiteTest < ActiveSupport::TestCase
+ SITE = ActiveFile::Site.configure(:S3, SITE_CONFIGURATIONS[:s3])
+
+ include ActiveFile::Site::SharedSiteTests
+ end
+else
+ puts "Skipping S3 Site tests because no S3 configuration was supplied"
+end
diff --git a/test/site/shared_site_tests.rb b/test/site/shared_site_tests.rb
new file mode 100644
index 0000000000..de1a54b874
--- /dev/null
+++ b/test/site/shared_site_tests.rb
@@ -0,0 +1,63 @@
+require "test_helper"
+require "active_support/core_ext/securerandom"
+require "yaml"
+
+SITE_CONFIGURATIONS = begin
+ YAML.load_file(File.expand_path("../configurations.yml", __FILE__)).deep_symbolize_keys
+rescue Errno::ENOENT
+ puts "Missing site configuration file in test/sites/configurations.yml"
+end
+
+module ActiveFile::Site::SharedSiteTests
+ extend ActiveSupport::Concern
+
+ FIXTURE_KEY = SecureRandom.base58(24)
+ FIXTURE_FILE = StringIO.new("Hello world!")
+
+ included do
+ setup do
+ @site = self.class.const_get(:SITE)
+ @site.upload FIXTURE_KEY, FIXTURE_FILE
+ FIXTURE_FILE.rewind
+ end
+
+ teardown do
+ @site.delete FIXTURE_KEY
+ FIXTURE_FILE.rewind
+ end
+
+ test "uploading" do
+ begin
+ key = SecureRandom.base58(24)
+ data = "Something else entirely!"
+ @site.upload(key, StringIO.new(data))
+
+ assert_equal data, @site.download(key)
+ ensure
+ @site.delete key
+ end
+ end
+
+ test "downloading" do
+ assert_equal FIXTURE_FILE.read, @site.download(FIXTURE_KEY)
+ end
+
+ test "existing" do
+ assert @site.exist?(FIXTURE_KEY)
+ assert_not @site.exist?(FIXTURE_KEY + "nonsense")
+ end
+
+ test "deleting" do
+ @site.delete FIXTURE_KEY
+ assert_not @site.exist?(FIXTURE_KEY)
+ end
+
+ test "sizing" do
+ assert_equal FIXTURE_FILE.size, @site.byte_size(FIXTURE_KEY)
+ end
+
+ test "checksumming" do
+ assert_equal Digest::MD5.hexdigest(FIXTURE_FILE.read), @site.checksum(FIXTURE_KEY)
+ end
+ end
+end