pax_global_header00006660000000000000000000000064147670770110014524gustar00rootroot0000000000000052 comment=754958125ed4152005f9cc72b031c041a2bd6fb1 fog-local-0.9.0/000077500000000000000000000000001476707701100133755ustar00rootroot00000000000000fog-local-0.9.0/.github/000077500000000000000000000000001476707701100147355ustar00rootroot00000000000000fog-local-0.9.0/.github/dependabot.yml000066400000000000000000000003171476707701100175660ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: "bundler" directory: "/" schedule: interval: "daily" - package-ecosystem: "github-actions" directory: "/" schedule: interval: "daily" fog-local-0.9.0/.github/workflows/000077500000000000000000000000001476707701100167725ustar00rootroot00000000000000fog-local-0.9.0/.github/workflows/ci.yml000066400000000000000000000010521476707701100201060ustar00rootroot00000000000000# This workflow uses actions that are not certified by GitHub. # They are provided by a third-party and are governed by # separate terms of service, privacy policy, and support # documentation. # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby name: Ruby on: push: branches: [ master ] pull_request: branches: [ master ] jobs: test: uses: fog/.github/.github/workflows/ci.yml@v1.5.0 fog-local-0.9.0/.github/workflows/stale.yml000066400000000000000000000002331476707701100206230ustar00rootroot00000000000000name: Mark stale issues and pull requests on: schedule: - cron: "30 1 * * *" jobs: stale: uses: fog/.github/.github/workflows/stale.yml@v1.5.0 fog-local-0.9.0/.gitignore000066400000000000000000000002011476707701100153560ustar00rootroot00000000000000/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ *.bundle *.so *.o *.a mkmf.log tests/.fog fog-local-0.9.0/.ruby-gemset000066400000000000000000000000121476707701100156320ustar00rootroot00000000000000fog-local fog-local-0.9.0/CONTRIBUTING.md000066400000000000000000000014711476707701100156310ustar00rootroot00000000000000## Getting Involved New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another. ### Coding * Pick a task: * Offer feedback on open [pull requests](https://github.com/fog/fog/pulls). * Review open [issues](https://github.com/fog/fog/issues) for things to help on. * [Create an issue](https://github.com/fog/fog/issues/new) to start a discussion on additions or features. * Fork the project, add your changes and tests to cover them in a topic branch. * Commit your changes and rebase against `fog/fog` to ensure everything is up to date. * [Submit a pull request](https://github.com/fog/fog/compare/). ### Non-Coding * Offer feedback on open [issues](https://github.com/fog/fog/issues). * Organize or volunteer at events. fog-local-0.9.0/CONTRIBUTORS.md000066400000000000000000000013121476707701100156510ustar00rootroot00000000000000* geemus * Lance Ivy * Paul Thornthwaite * Benjamin Manns * Sjoerd Andringa * Juris Galang * Paul Thornthwaite * Jamie Paton * Thomas Wright * Wesley Beary * Karl Freeman * Andy Lindeman * Athir Nuaimi * Brian D. Burns * Jade Tucker * James Herdman * Adam Tanner * Mark Yen * Kevin Deisz fog-local-0.9.0/Gemfile000066400000000000000000000001361476707701100146700ustar00rootroot00000000000000source 'https://rubygems.org' # Specify your gem's dependencies in fog-local.gemspec gemspec fog-local-0.9.0/LICENSE.md000066400000000000000000000021641476707701100150040ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 [CONTRIBUTORS.md](https://github.com/fog/fog/blob/master/CONTRIBUTORS.md) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fog-local-0.9.0/README.md000066400000000000000000000017741476707701100146650ustar00rootroot00000000000000# Fog::Local ![Gem Version](https://badge.fury.io/rb/fog-local.svg) [![Build Status](https://github.com/fog/fog-local/actions/workflows/ci.yml/badge.svg)](https://github.com/fog/fog-local/actions/workflows/ci.yml) ## Installation Add this line to your application's Gemfile: ```ruby gem 'fog-local' ``` And then execute: $ bundle Or install it yourself as: $ gem install fog-local ## Usage Initialise a `Fog::Local::Storage` object: ```ruby storage = Fog::Local::Storage.new(local_root: '~/fog') ``` This can then be used like any other [Fog storage](https://fog.github.io/storage/). ```ruby directory = storage.directories.create(key: 'data') directory.files.create(body: 'Hello World!', key: 'hello_world.txt') ``` ## Contributing 1. Fork it ( https://github.com/fog/fog-local/fork) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request fog-local-0.9.0/Rakefile000066400000000000000000000002631476707701100150430ustar00rootroot00000000000000require "bundler/gem_tasks" task :default => :test mock = ENV['FOG_MOCK'] || 'false' desc "Run tests" task :test do sh("export FOG_MOCK=#{mock} && bundle exec shindont") end fog-local-0.9.0/fog-local.gemspec000066400000000000000000000021571476707701100166120ustar00rootroot00000000000000# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'fog/local/version' Gem::Specification.new do |spec| spec.name = "fog-local" spec.version = Fog::Local::VERSION spec.authors = ["Wesley Beary", "Ville Lautanala"] spec.email = ["geemus@gmail.com", "lautis@gmail.com"] spec.summary = %q{Module for the 'fog' gem to support local filesystem storage.} spec.description = %q{This library can be used as a module for `fog` or as standalone provider to use local filesystem storage.} spec.homepage = "https://github.com/fog/fog-local" spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_development_dependency 'bundler' spec.add_development_dependency 'rake', '>= 12.3.3' spec.add_development_dependency 'shindo', '~> 0.3' spec.add_dependency 'fog-core', '>= 1.27', '< 3.0' end fog-local-0.9.0/lib/000077500000000000000000000000001476707701100141435ustar00rootroot00000000000000fog-local-0.9.0/lib/fog/000077500000000000000000000000001476707701100147165ustar00rootroot00000000000000fog-local-0.9.0/lib/fog/bin/000077500000000000000000000000001476707701100154665ustar00rootroot00000000000000fog-local-0.9.0/lib/fog/bin/local.rb000066400000000000000000000012541476707701100171070ustar00rootroot00000000000000class Local < Fog::Bin class << self def class_for(key) case key when :storage Fog::Local::Storage else raise ArgumentError, "Unsupported #{self} service: #{key}" end end def [](service) @@connections ||= Hash.new do |hash, key| hash[key] = case key when :storage Fog::Logger.warning("Local[:storage] is not recommended, use Storage[:local] for portability") Fog::Local::Storage.new else raise ArgumentError, "Unrecognized service: #{key.inspect}" end end @@connections[service] end def services Fog::Local.services end end end fog-local-0.9.0/lib/fog/local.rb000066400000000000000000000004261476707701100163370ustar00rootroot00000000000000require 'fog/core' require 'fileutils' require 'tempfile' require 'fog/local/version' module Fog module Local extend Provider autoload :Storage, 'fog/local/storage' service :storage, :Storage end end Fog::Storage::Local = Fog::Local::Storage # legacy compat fog-local-0.9.0/lib/fog/local/000077500000000000000000000000001476707701100160105ustar00rootroot00000000000000fog-local-0.9.0/lib/fog/local/models/000077500000000000000000000000001476707701100172735ustar00rootroot00000000000000fog-local-0.9.0/lib/fog/local/models/directories.rb000066400000000000000000000014231476707701100221340ustar00rootroot00000000000000module Fog module Local class Storage class Directories < Fog::Collection model Directory def all data = if ::File.directory?(service.local_root) Dir.entries(service.local_root).select do |entry| entry[0...1] != '.' && ::File.directory?(service.path_to(entry)) end.map do |entry| {:key => entry} end else [] end load(data) end def get(key, options = {}) create_directory(key, options) if ::File.directory?(service.path_to(key)) end private def create_directory(key, options) options[:path] ? new(key: key + options[:path]) : new(key: key) end end end end end fog-local-0.9.0/lib/fog/local/models/directory.rb000066400000000000000000000013071476707701100216250ustar00rootroot00000000000000module Fog module Local class Storage class Directory < Fog::Model identity :key def destroy requires :key if ::File.directory?(path) Dir.rmdir(path) true else false end end def files @files ||= Files.new(directory: self, service: service) end def public=(new_public) new_public end def public_url nil end def save requires :key FileUtils.mkpath(path) true end private def path service.path_to(key) end end end end end fog-local-0.9.0/lib/fog/local/models/file.rb000066400000000000000000000101511476707701100205350ustar00rootroot00000000000000module Fog module Local class Storage class File < Fog::Model identity :key, :aliases => 'Key' attribute :content_length, :aliases => 'Content-Length', :type => :integer # attribute :content_type, :aliases => 'Content-Type' attribute :last_modified, :aliases => 'Last-Modified' require 'uri' def body attributes[:body] ||= if last_modified collection.get(identity).body else '' end end def body=(new_body) attributes[:body] = new_body end def content_type @content_type ||= begin unless (mime_types = ::MIME::Types.of(key)).empty? mime_types.first.content_type end end end def directory @directory end def copy(target_directory_key, target_file_key, options={}) requires :directory, :key service.copy_object(directory.key, key, target_directory_key, target_file_key) target_directory = service.directories.new(:key => target_directory_key) target_directory.files.get(target_file_key) end def destroy requires :directory, :key ::File.delete(path) if ::File.exist?(path) dirs = path.split(::File::SEPARATOR)[0...-1] dirs.length.times do |index| dir_path = dirs[0..-index].join(::File::SEPARATOR) if dir_path.empty? # path starts with ::File::SEPARATOR next end # don't delete the containing directory or higher if dir_path == service.path_to(directory.key) break end rm_if_empty_dir(dir_path) end true end def public=(new_public) new_public end def public_url requires :directory, :key if service.endpoint escaped_directory = uri_escape(directory.key) escaped_key = uri_escape(key) ::File.join(service.endpoint, escaped_directory, escaped_key) else nil end end def save(options = {}) requires :body, :directory, :key # Once 1.9.3 support is dropped, the following two lines # can be replaced with `File.dirname(path)` dirs = path.split(::File::SEPARATOR)[0...-1] dir_path = dirs.join(::File::SEPARATOR) # Create all directories in file path that do not yet exist FileUtils.mkdir_p(dir_path) if (body.is_a?(::File) || body.is_a?(Tempfile)) && ::File.exist?(body.path) FileUtils.cp(body.path, path) else write_file(path, body) end merge_attributes( :content_length => Fog::Storage.get_body_size(body), :last_modified => ::File.mtime(path) ) true end private def directory=(new_directory) @directory = new_directory end def uri_escape(string) string.b.gsub(/[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]/) do |m| '%' + m.unpack('H2' * m.bytesize).join('%').upcase end end def path service.path_to(::File.join(directory.key, key)) end def write_file(path, content) input_io = StringIO.new(content) if content.is_a?(String) input_io ||= content ::File.open(path, 'wb') do |file| IO.copy_stream(input_io, file) end end def rm_if_empty_dir(dir_path) if ::File.directory?(dir_path) Dir.rmdir(dir_path) if dir_empty?(dir_path) end end def dir_empty?(dir_path) # NOTE: There’s Dir.empty?, but it is only available on Ruby 2.4+ # NOTE: `entries` will be empty on Windows, and contain . and .. on # unix-like systems (macOS, Linux, BSD, …) entries = Dir.entries(dir_path) entries.empty? || entries.all? { |e| ['.', '..'].include?(e) } end end end end end fog-local-0.9.0/lib/fog/local/models/files.rb000066400000000000000000000041421476707701100207230ustar00rootroot00000000000000module Fog module Local class Storage class Files < Fog::Collection attribute :directory model File def all requires :directory if directory.collection.get(directory.key) data = [] Dir.chdir(service.path_to(directory.key)) { data = Dir.glob('**/*').reject do |file| ::File.directory?(file) end.map do |key| path = file_path(key) { :content_length => ::File.size(path), :key => key, :last_modified => ::File.mtime(path) } end } load(data) else nil end end def get(key, &block) requires :directory path = file_path(key) if ::File.exist?(path) data = { :content_length => ::File.size(path), :key => key, :last_modified => ::File.mtime(path) } body = String.new ::File.open(path) do |file| while (chunk = file.read(Excon::CHUNK_SIZE)) && (!block_given? || (block_given? && yield(chunk))) body << chunk end end data.merge!(:body => body) if !block_given? new(data) else nil end end def head(key) requires :directory path = file_path(key) if ::File.exist?(path) new({ :content_length => ::File.size(path), :key => key, :last_modified => ::File.mtime(path) }) else nil end end def new(attributes = {}) requires :directory super({ :directory => directory }.merge!(attributes)) end def is_truncated false end private def file_path(key) service.path_to(::File.join(directory.key, key)) end end end end end fog-local-0.9.0/lib/fog/local/storage.rb000066400000000000000000000046211476707701100200040ustar00rootroot00000000000000module Fog module Local class Storage < Fog::Service autoload :Directories, 'fog/local/models/directories' autoload :Directory, 'fog/local/models/directory' autoload :File, 'fog/local/models/file' autoload :Files, 'fog/local/models/files' requires :local_root recognizes :endpoint, :scheme, :host, :port, :path model_path 'fog/local/models' collection :directories model :directory model :file collection :files require 'uri' class Mock attr_reader :endpoint def self.data @data ||= Hash.new do |hash, key| hash[key] = {} end end def self.reset @data = nil end def initialize(options={}) Fog::Mock.not_implemented @local_root = ::File.expand_path(options[:local_root]) @endpoint = options[:endpoint] || build_endpoint_from_options(options) end def data self.class.data[@local_root] end def local_root @local_root end def path_to(partial) ::File.join(@local_root, partial) end def reset_data self.class.data.delete(@local_root) end private def build_endpoint_from_options(options) return unless options[:host] URI::Generic.build(options).to_s end end class Real attr_reader :endpoint def initialize(options={}) @local_root = ::File.expand_path(options[:local_root]) @endpoint = options[:endpoint] || build_endpoint_from_options(options) end def local_root @local_root end def path_to(partial) ::File.join(@local_root, partial) end def copy_object(source_directory_name, source_object_name, target_directory_name, target_object_name, options={}) source_path = path_to(::File.join(source_directory_name, source_object_name)) target_path = path_to(::File.join(target_directory_name, target_object_name)) ::FileUtils.mkdir_p(::File.dirname(target_path)) ::FileUtils.copy_file(source_path, target_path) end private def build_endpoint_from_options(options) return unless options[:host] URI::Generic.build(options).to_s end end end end end fog-local-0.9.0/lib/fog/local/version.rb000066400000000000000000000000721476707701100200210ustar00rootroot00000000000000module Fog module Local VERSION = '0.9.0' end end fog-local-0.9.0/tests/000077500000000000000000000000001476707701100145375ustar00rootroot00000000000000fog-local-0.9.0/tests/helper.rb000066400000000000000000000014721476707701100163470ustar00rootroot00000000000000begin require "codeclimate-test-reporter" CodeClimate::TestReporter.start rescue LoadError => e $stderr.puts "not recording test coverage: #{e.inspect}" end $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'fog/local' Bundler.require(:test) require 'tmpdir' Excon.defaults.merge!(:debug_request => true, :debug_response => true) require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'mock_helper')) # This overrides the default 600 seconds timeout during live test runs if Fog.mocking? Fog.timeout = ENV['FOG_TEST_TIMEOUT'] || 2000 Fog::Logger.warning "Setting default fog timeout to #{Fog.timeout} seconds" end def lorem_file File.open(File.dirname(__FILE__) + '/lorem.txt', 'r') end def array_differences(array_a, array_b) (array_a - array_b) | (array_b - array_a) end fog-local-0.9.0/tests/helpers/000077500000000000000000000000001476707701100162015ustar00rootroot00000000000000fog-local-0.9.0/tests/helpers/collection_helper.rb000066400000000000000000000050271476707701100222240ustar00rootroot00000000000000def collection_tests(collection, params = {}, mocks_implemented = true) tests('success') do tests("#new(#{params.inspect})").succeeds do pending if Fog.mocking? && !mocks_implemented collection.new(params) end tests("#create(#{params.inspect})").succeeds do pending if Fog.mocking? && !mocks_implemented @instance = collection.create(params) end # FIXME: work around for timing issue on AWS describe_instances mocks if Fog.mocking? && @instance.respond_to?(:ready?) @instance.wait_for { ready? } end tests("#all").succeeds do pending if Fog.mocking? && !mocks_implemented collection.all end if !Fog.mocking? || mocks_implemented @identity = @instance.identity end tests("#get(#{@identity})").succeeds do pending if Fog.mocking? && !mocks_implemented collection.get(@identity) end tests('Enumerable') do pending if Fog.mocking? && !mocks_implemented methods = [ 'all?', 'any?', 'find', 'detect', 'collect', 'map', 'find_index', 'flat_map', 'collect_concat', 'group_by', 'none?', 'one?' ] # JRuby 1.7.5+ issue causes a SystemStackError: stack level too deep # https://github.com/jruby/jruby/issues/1265 if RUBY_PLATFORM == "java" and JRUBY_VERSION =~ /1\.7\.[5-8]/ methods.delete('all?') end methods.each do |enum_method| if collection.respond_to?(enum_method) tests("##{enum_method}").succeeds do block_called = false collection.send(enum_method) {|x| block_called = true } block_called end end end [ 'max_by','min_by' ].each do |enum_method| if collection.respond_to?(enum_method) tests("##{enum_method}").succeeds do block_called = false collection.send(enum_method) {|x| block_called = true; 0 } block_called end end end end if block_given? yield(@instance) end if !Fog.mocking? || mocks_implemented @instance.destroy end end tests('failure') do if !Fog.mocking? || mocks_implemented @identity = @identity.to_s @identity = @identity.gsub(/[a-zA-Z]/) { Fog::Mock.random_letters(1) } @identity = @identity.gsub(/\d/) { Fog::Mock.random_numbers(1) } @identity end tests("#get('#{@identity}')").returns(nil) do pending if Fog.mocking? && !mocks_implemented collection.get(@identity) end end end fog-local-0.9.0/tests/helpers/mock_helper.rb000066400000000000000000000001741476707701100210200ustar00rootroot00000000000000# Use so you can run in mock mode from the command line # # FOG_MOCK=true fog if ENV["FOG_MOCK"] == "true" Fog.mock! end fog-local-0.9.0/tests/helpers/model_helper.rb000066400000000000000000000014141476707701100211650ustar00rootroot00000000000000def model_tests(collection, params = {}, mocks_implemented = true) tests('success') do @instance = collection.new(params) tests("#save").succeeds do pending if Fog.mocking? && !mocks_implemented @instance.save end if block_given? yield(@instance) end tests("#destroy").succeeds do pending if Fog.mocking? && !mocks_implemented @instance.destroy end end end # Generates a unique identifier with a random differentiator. # Useful when rapidly re-running tests, so we don't have to wait # serveral minutes for deleted objects to disappear from the API # E.g. 'fog-test-1234' def uniq_id(base_name = 'fog-test') # random_differentiator suffix = rand(65536).to_s(16).rjust(4, '0') [base_name, suffix] * '-' end fog-local-0.9.0/tests/helpers/succeeds_helper.rb000066400000000000000000000002131476707701100216570ustar00rootroot00000000000000module Shindo class Tests def succeeds(&block) test('succeeds') do !!instance_eval(&block) end end end end fog-local-0.9.0/tests/local/000077500000000000000000000000001476707701100156315ustar00rootroot00000000000000fog-local-0.9.0/tests/local/models/000077500000000000000000000000001476707701100171145ustar00rootroot00000000000000fog-local-0.9.0/tests/local/models/directories_tests.rb000066400000000000000000000010531476707701100231760ustar00rootroot00000000000000Shindo.tests('Storage[:local] | directories', ["local"]) do pending if Fog.mocking? @options = { :local_root => Dir.mktmpdir('fog-tests') } @collection = Fog::Local::Storage.new(@options).directories collection_tests(@collection, {:key => "fogdirtests"}, true) tests("#all") do tests("succeeds when :local_root does not exist").succeeds do FileUtils.remove_entry_secure(@options[:local_root]) @collection.all end end FileUtils.remove_entry_secure(@options[:local_root]) if File.directory?(@options[:local_root]) end fog-local-0.9.0/tests/local/models/directory_tests.rb000066400000000000000000000007331476707701100226720ustar00rootroot00000000000000Shindo.tests('Storage[:local] | directory', ["local"]) do pending if Fog.mocking? before do @options = { :local_root => Dir.mktmpdir('fog-tests') } end after do FileUtils.remove_entry_secure @options[:local_root] end tests('save') do returns('directory') do connection = Fog::Local::Storage.new(@options) connection.directories.create(:key => 'directory') connection.directories.create(:key => 'directory').key end end end fog-local-0.9.0/tests/local/models/file_tests.rb000066400000000000000000000111631476707701100216040ustar00rootroot00000000000000Shindo.tests('Storage[:local] | file', ["local"]) do pending if Fog.mocking? before do @options = { :local_root => Dir.mktmpdir('fog-tests') } end after do FileUtils.remove_entry_secure @options[:local_root] end tests('#public_url') do tests('when connection has an endpoint'). returns('http://example.com/files/directory/file.txt') do @options[:endpoint] = 'http://example.com/files' connection = Fog::Local::Storage.new(@options) directory = connection.directories.new(:key => 'directory') file = directory.files.new(:key => 'file.txt') file.public_url end tests('when connection has no endpoint'). returns(nil) do @options[:endpoint] = nil connection = Fog::Local::Storage.new(@options) directory = connection.directories.new(:key => 'directory') file = directory.files.new(:key => 'file.txt') file.public_url end tests('when file path has escapable characters'). returns('http://example.com/files/my%20directory/my%20file.txt') do @options[:endpoint] = 'http://example.com/files' connection = Fog::Local::Storage.new(@options) directory = connection.directories.new(:key => 'my directory') file = directory.files.new(:key => 'my file.txt') file.public_url end tests('when key has safe characters'). returns('http://example.com/files/my/directory/my/file.txt') do @options[:endpoint] = 'http://example.com/files' connection = Fog::Local::Storage.new(@options) directory = connection.directories.new(:key => 'my/directory') file = directory.files.new(:key => 'my/file.txt') file.public_url end end tests('#save') do tests('creates non-existent subdirs') do returns(true) do connection = Fog::Local::Storage.new(@options) directory = connection.directories.new(:key => 'path1') file = directory.files.new(:key => 'path2/file.rb', :body => "my contents") file.save File.exist?(@options[:local_root] + "/path1/path2/file.rb") end end tests('with tempfile').returns('tempfile') do connection = Fog::Local::Storage.new(@options) directory = connection.directories.create(:key => 'directory') tempfile = Tempfile.new(['file', '.txt']) tempfile.write('tempfile') tempfile.rewind tempfile.instance_eval do def read raise 'must not be read' end end file = directory.files.new(:key => 'tempfile.txt', :body => tempfile) file.save tempfile.close tempfile.unlink directory.files.get('tempfile.txt').body end end tests('#destroy') do # - removes dir if it contains no files # - keeps dir if it contains non-hidden files # - keeps dir if it contains hidden files # - stays in the same directory tests('removes enclosing dir if it is empty') do returns(false) do connection = Fog::Local::Storage.new(@options) directory = connection.directories.new(:key => 'path1') file = directory.files.new(:key => 'path2/file.rb', :body => "my contents") file.save file.destroy File.exist?(@options[:local_root] + "/path1/path2") end end tests('keeps enclosing dir if it is not empty') do returns(true) do connection = Fog::Local::Storage.new(@options) directory = connection.directories.new(:key => 'path1') file = directory.files.new(:key => 'path2/file.rb', :body => "my contents") file.save file = directory.files.new(:key => 'path2/file2.rb', :body => "my contents") file.save file.destroy File.exist?(@options[:local_root] + "/path1/path2") end end tests('keeps enclosing dir if contains only hidden files') do returns(true) do connection = Fog::Local::Storage.new(@options) directory = connection.directories.new(:key => 'path1') file = directory.files.new(:key => 'path2/.file.rb', :body => "my contents") file.save file = directory.files.new(:key => 'path2/.file2.rb', :body => "my contents") file.save file.destroy File.exist?(@options[:local_root] + "/path1/path2") end end tests('it stays in the same directory') do returns(Dir.pwd) do connection = Fog::Local::Storage.new(@options) directory = connection.directories.new(:key => 'path1') file = directory.files.new(:key => 'path2/file2.rb', :body => "my contents") file.save file.destroy Dir.pwd end end end end fog-local-0.9.0/tests/local/models/files_tests.rb000066400000000000000000000010251476707701100217630ustar00rootroot00000000000000Shindo.tests('Storage[:local] | files', ["local"]) do pending if Fog.mocking? before do @options = { :local_root => Dir.mktmpdir('fog-tests') } end after do FileUtils.remove_entry_secure(@options[:local_root]) if File.directory?(@options[:local_root]) end tests("#is_truncated") do returns(false) do connection = Fog::Local::Storage.new(@options) directory = connection.directories.create(:key => 'directory') collection = directory.files collection.is_truncated end end end fog-local-0.9.0/tests/local/storage_tests.rb000066400000000000000000000020621476707701100210440ustar00rootroot00000000000000Shindo.tests('Local | storage') do pending if Fog.mocking? before do @options = { :local_root => Dir.mktmpdir('fog-tests') } end after do FileUtils.remove_entry_secure @options[:local_root] end tests('#endpoint') do tests('when no endpoint is provided'). returns(nil) do Fog::Local::Storage.new(@options).endpoint end tests('when no host is provided'). returns(nil) do @options[:scheme] = 'http' @options[:path] = '/files' @options[:port] = 80 Fog::Local::Storage.new(@options).endpoint end tests('when endpoint is provided'). returns('http://example.com/files') do @options[:endpoint] = 'http://example.com/files' Fog::Local::Storage.new(@options).endpoint end tests('when at least host option is provided'). returns('http://example.com/files') do @options[:scheme] = 'http' @options[:host] = 'example.com' @options[:path] = '/files' Fog::Local::Storage.new(@options).endpoint end end end fog-local-0.9.0/tests/watchr.rb000066400000000000000000000007071476707701100163600ustar00rootroot00000000000000ENV['FOG_MOCK'] ||= 'true' ENV['AUTOTEST'] = 'true' ENV['WATCHR'] = '1' def file2shindo(file) result = file.sub('lib/fog/', 'tests/').gsub(/\.rb$/, '_tests.rb') end def run_shindo_test(file) if File.exist? file system("shindont #{file}") else puts "FIXME: No test #{file} [#{Time.now}]" end end watch( 'tests/.*_tests\.rb' ) do |md| run_shindo_test(md[0]) end watch( 'lib/.*\.rb' ) do |md| run_shindo_test(file2shindo(md[0])) end