test_s3fs.py 962 B

123456789101112131415161718192021222324252627282930313233
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import tempfile
  5. # Import Salt libs
  6. import salt.fileserver.s3fs as s3fs
  7. # Import Salt Testing libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.runtests import RUNTIME_VARS
  10. from tests.support.unit import TestCase
  11. class S3fsFileTest(TestCase, LoaderModuleMockMixin):
  12. def setup_loader_modules(self):
  13. opts = {
  14. "cachedir": self.tmp_cachedir,
  15. }
  16. return {s3fs: {"__opts__": opts}}
  17. @classmethod
  18. def setUpClass(cls):
  19. cls.tmp_cachedir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  20. def test_cache_round_trip(self):
  21. metadata = {"foo": "bar"}
  22. cache_file = s3fs._get_cached_file_name("base", "fake_bucket", "some_file")
  23. s3fs._write_buckets_cache_file(metadata, cache_file)
  24. assert s3fs._read_buckets_cache_file(cache_file) == metadata