Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit FileSystemTarget #3

Merged
merged 1 commit into from
Jun 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/tumugi/plugin/target/google_drive_file.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require 'tumugi/config'
require 'tumugi/plugin'
require 'tumugi/plugin/file_system_target'
require 'tumugi/plugin/google_drive/atomic_file'
require 'tumugi/plugin/google_drive/file_system'

module Tumugi
module Plugin
class GoogleDriveFileTarget < Tumugi::Target
class GoogleDriveFileTarget < Tumugi::Plugin::FileSystemTarget
Tumugi::Plugin.register_target('google_drive_file', self)
Tumugi::Config.register_section('google_drive', :project_id, :client_email, :private_key, :private_key_file)

Expand All @@ -16,7 +17,7 @@ def initialize(file_id: nil, name: nil, parents: nil, fs: nil)
@file_id = file_id || self.fs.generate_file_id
@name = name
@parents = parents
log "file_id='#{file_id}', name='#{name}', parents='#{parents}'"
super(@file_id)
end

def fs
Expand Down
3 changes: 3 additions & 0 deletions test/plugin/target/google_drive_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ class Tumugi::Plugin::GoogleDriveFileTargetTest < Test::Unit::TestCase
assert_equal('test', target.name)
assert_nil(target.parents)
assert_match(/^[0-9a-zA-Z]{28}$/, target.file_id)
assert_equal(target.path, target.file_id)
end

test "with name and parents" do
target = Tumugi::Plugin::GoogleDriveFileTarget.new(name: 'test', parents: 'parent')
assert_equal('test', target.name)
assert_equal('parent', target.parents)
assert_match(/^[0-9a-zA-Z]{28}$/, target.file_id)
assert_equal(target.path, target.file_id)
end

test "with name and parents and file_id" do
target = Tumugi::Plugin::GoogleDriveFileTarget.new(name: 'test', parents: 'parent', file_id: 'a'*28)
assert_equal('test', target.name)
assert_equal('parent', target.parents)
assert_equal('a'*28, target.file_id)
assert_equal(target.path, target.file_id)
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)

raise "ENV['PROJECT_ID'] must be set" unless ENV.key?('PROJECT_ID')
raise "ENV['CLIENT_EMAIL'] must be set" unless ENV.key?('CLIENT_EMAIL')
raise "ENV['PRIVATE_KEY'] must be set" unless ENV.key?('PRIVATE_KEY')

require 'test/unit'
require 'test/unit/rr'

Expand Down