worochi 0.0.7 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/worochi/agent/{sample.rb → #example.rb} +2 -14
  3. data/lib/worochi/agent/dropbox.rb +3 -13
  4. data/lib/worochi/agent/github.rb +8 -23
  5. data/lib/worochi/agent.rb +46 -18
  6. data/lib/worochi/config/#example.yml +35 -0
  7. data/lib/worochi/config/dropbox.yml +14 -0
  8. data/lib/worochi/config/github.yml +17 -0
  9. data/lib/worochi/config.rb +9 -84
  10. data/lib/worochi/configurator.rb +120 -0
  11. data/lib/worochi/helper/github_helper.rb +111 -0
  12. data/lib/worochi/helper.rb +28 -7
  13. data/lib/worochi/item.rb +5 -3
  14. data/lib/worochi/log.rb +8 -14
  15. data/lib/worochi/oauth.rb +69 -0
  16. data/lib/worochi/version.rb +1 -1
  17. data/lib/worochi.rb +20 -3
  18. data/spec/cassettes/Worochi/_push/pushes_with_agents.yml +512 -0
  19. data/spec/cassettes/Worochi_Agent_Dropbox/_push_item/pushes_it_chunked_if_size_exceeds_limit.yml +1049 -0
  20. data/spec/cassettes/Worochi_Agent_Dropbox/_push_item_chunked/raises_an_error.yml +44 -0
  21. data/spec/cassettes/Worochi_Agent_Dropbox/_push_items/pushes_multiple_items.yml +165 -0
  22. data/spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files/raises_error_on_invalid_path.yml +38 -0
  23. data/spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing.yml +79 -0
  24. data/spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing_including_the_required_fields.yml +79 -0
  25. data/spec/cassettes/Worochi_Agent_Github/_list/works_with_absolute_paths.yml +12 -12
  26. data/spec/cassettes/Worochi_Agent_Github/_repos/lists_the_repos.yml +207 -0
  27. data/spec/cassettes/Worochi_Agent_Github/_source_branch/retrieves_the_master_branch_correctly.yml +6 -6
  28. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/accepts_a_different_relative_path.yml +12 -12
  29. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/contains_file1.yml +12 -12
  30. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/does_not_contain_folder1.yml +12 -12
  31. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/raises_error_on_invalid_path.yml +133 -0
  32. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files_and_folders/contains_folder1_and_file1.yml +24 -24
  33. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing_including_the_required_fields.yml +133 -0
  34. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_folders/accepts_a_different_relative_path.yml +12 -12
  35. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_folders/contains_folder1.yml +12 -12
  36. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_folders/does_not_contain_file1.yml +12 -12
  37. data/spec/cassettes/Worochi_Agent_Github/{_push_all → modifies_the_repo/_push_all}/pushes_a_list_of_items_to_create_a_new_commit.yml +80 -80
  38. data/spec/cassettes/Worochi_Agent_Github/{_push_all → modifies_the_repo/_push_all}/pushes_the_file_to_the_right_place.yml +60 -60
  39. data/spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_blob/pushes_the_blob_even_when_it_is_larger_than_block_size.yml +181 -0
  40. data/spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_item/pushes_a_single_item_and_makes_a_commit.yml +687 -0
  41. data/spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_stream_blob/streams_the_file_as_an_Base64_JSON_field.yml +181 -0
  42. data/spec/cassettes/Worochi_OAuth/_flow_end/rejects_bad_code.yml +56 -0
  43. data/spec/{helper.rb → spec_helper.rb} +14 -1
  44. data/spec/support/aws_uri_matcher.rb +1 -1
  45. data/spec/support/shared_exampes_for_agents.rb +13 -2
  46. data/spec/support/test_files.rb +4 -4
  47. data/spec/worochi/agent/dropbox_spec.rb +29 -3
  48. data/spec/worochi/agent/github_spec.rb +54 -26
  49. data/spec/worochi/agent_spec.rb +34 -1
  50. data/spec/worochi/config_spec.rb +46 -30
  51. data/spec/worochi/helper/github_helper_spec.rb +94 -0
  52. data/spec/worochi/helper_spec.rb +15 -3
  53. data/spec/worochi/item_spec.rb +9 -6
  54. data/spec/worochi/log_spec.rb +30 -0
  55. data/spec/worochi/oauth_spec.rb +33 -0
  56. data/spec/worochi_spec.rb +25 -1
  57. data/worochi.gemspec +5 -1
  58. metadata +104 -11
  59. data/lib/worochi/helper/github.rb +0 -100
  60. data/spec/worochi/helper/github_spec.rb +0 -57
@@ -0,0 +1,181 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: delete
5
+ uri: https://api.github.com/repos/darkmirage/test/git/refs/heads/rspec
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Octokit Ruby Gem 1.25.0
12
+ Accept:
13
+ - application/vnd.github.beta+json
14
+ Authorization:
15
+ - token <GITHUB_TOKEN>
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 422
21
+ message: Unprocessable Entity
22
+ headers:
23
+ Server:
24
+ - GitHub.com
25
+ Date:
26
+ - Thu, 15 Aug 2013 21:10:11 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Status:
30
+ - 422 Unprocessable Entity
31
+ X-Ratelimit-Limit:
32
+ - '5000'
33
+ X-Ratelimit-Remaining:
34
+ - '4685'
35
+ X-Ratelimit-Reset:
36
+ - '1376602835'
37
+ X-Oauth-Scopes:
38
+ - user, public_repo, repo, gist
39
+ X-Accepted-Oauth-Scopes:
40
+ - repo, public_repo, repo:status, delete_repo, site_admin
41
+ X-Github-Media-Type:
42
+ - github.beta; format=json
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ Content-Length:
46
+ - '31'
47
+ Access-Control-Allow-Credentials:
48
+ - 'true'
49
+ Access-Control-Expose-Headers:
50
+ - ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes,
51
+ X-Accepted-OAuth-Scopes
52
+ Access-Control-Allow-Origin:
53
+ - '*'
54
+ body:
55
+ encoding: UTF-8
56
+ string: '{"message":"Validation Failed"}'
57
+ http_version:
58
+ recorded_at: Thu, 15 Aug 2013 21:10:11 GMT
59
+ - request:
60
+ method: post
61
+ uri: https://api.github.com/repos/darkmirage/test/git/blobs
62
+ body:
63
+ encoding: UTF-8
64
+ string: '{"content":"VGhpcyBpcyBhIGZpbGUgdXNlZCBmb3IgUlNwZWMgdGVzdHMgaW52b2x2aW5nIFdvcm9jaGk6Okl0ZW0u","encoding":"base64"}'
65
+ headers:
66
+ Accept-Encoding:
67
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
68
+ Accept:
69
+ - '*/*'
70
+ User-Agent:
71
+ - Ruby
72
+ Content-Length:
73
+ - '114'
74
+ Content-Type:
75
+ - application/x-www-form-urlencoded
76
+ Authorization:
77
+ - token <GITHUB_TOKEN>
78
+ response:
79
+ status:
80
+ code: 201
81
+ message: Created
82
+ headers:
83
+ Server:
84
+ - GitHub.com
85
+ Date:
86
+ - Thu, 15 Aug 2013 21:10:12 GMT
87
+ Content-Type:
88
+ - application/json; charset=utf-8
89
+ Status:
90
+ - 201 Created
91
+ X-Ratelimit-Limit:
92
+ - '5000'
93
+ X-Ratelimit-Remaining:
94
+ - '4684'
95
+ X-Ratelimit-Reset:
96
+ - '1376602835'
97
+ X-Oauth-Scopes:
98
+ - user, public_repo, repo, gist
99
+ X-Accepted-Oauth-Scopes:
100
+ - repo, public_repo, repo:status, delete_repo, site_admin
101
+ Location:
102
+ - https://api.github.com/repos/darkmirage/test/git/blobs/5df468c4497e072139462b88cb78e1df4357534b
103
+ X-Github-Media-Type:
104
+ - github.beta
105
+ X-Content-Type-Options:
106
+ - nosniff
107
+ Content-Length:
108
+ - '154'
109
+ Access-Control-Allow-Credentials:
110
+ - 'true'
111
+ Access-Control-Expose-Headers:
112
+ - ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes,
113
+ X-Accepted-OAuth-Scopes
114
+ Access-Control-Allow-Origin:
115
+ - '*'
116
+ Etag:
117
+ - '"0e380113ab3ae5bd4b7290693137935d"'
118
+ Cache-Control:
119
+ - max-age=0, private, must-revalidate
120
+ body:
121
+ encoding: UTF-8
122
+ string: '{"sha":"5df468c4497e072139462b88cb78e1df4357534b","url":"https://api.github.com/repos/darkmirage/test/git/blobs/5df468c4497e072139462b88cb78e1df4357534b"}'
123
+ http_version:
124
+ recorded_at: Thu, 15 Aug 2013 21:10:12 GMT
125
+ - request:
126
+ method: delete
127
+ uri: https://api.github.com/repos/darkmirage/test/git/refs/heads/rspec
128
+ body:
129
+ encoding: US-ASCII
130
+ string: ''
131
+ headers:
132
+ User-Agent:
133
+ - Octokit Ruby Gem 1.25.0
134
+ Accept:
135
+ - application/vnd.github.beta+json
136
+ Authorization:
137
+ - token <GITHUB_TOKEN>
138
+ Accept-Encoding:
139
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
140
+ response:
141
+ status:
142
+ code: 422
143
+ message: Unprocessable Entity
144
+ headers:
145
+ Server:
146
+ - GitHub.com
147
+ Date:
148
+ - Thu, 15 Aug 2013 21:10:12 GMT
149
+ Content-Type:
150
+ - application/json; charset=utf-8
151
+ Status:
152
+ - 422 Unprocessable Entity
153
+ X-Ratelimit-Limit:
154
+ - '5000'
155
+ X-Ratelimit-Remaining:
156
+ - '4683'
157
+ X-Ratelimit-Reset:
158
+ - '1376602835'
159
+ X-Oauth-Scopes:
160
+ - user, public_repo, repo, gist
161
+ X-Accepted-Oauth-Scopes:
162
+ - repo, public_repo, repo:status, delete_repo, site_admin
163
+ X-Github-Media-Type:
164
+ - github.beta; format=json
165
+ X-Content-Type-Options:
166
+ - nosniff
167
+ Content-Length:
168
+ - '31'
169
+ Access-Control-Allow-Credentials:
170
+ - 'true'
171
+ Access-Control-Expose-Headers:
172
+ - ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes,
173
+ X-Accepted-OAuth-Scopes
174
+ Access-Control-Allow-Origin:
175
+ - '*'
176
+ body:
177
+ encoding: UTF-8
178
+ string: '{"message":"Validation Failed"}'
179
+ http_version:
180
+ recorded_at: Thu, 15 Aug 2013 21:10:12 GMT
181
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://github.com/login/oauth/access_token
6
+ body:
7
+ encoding: UTF-8
8
+ string: grant_type=authorization_code&code=abc&client_id=<GITHUB_ID>&client_secret=<GITHUB_SECRET>&redirect_uri=http%3A%2F%2F127.0.0.1%3A3000
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - '*/*'
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - GitHub.com
25
+ Date:
26
+ - Thu, 15 Aug 2013 00:44:07 GMT
27
+ Content-Type:
28
+ - application/x-www-form-urlencoded; charset=utf-8
29
+ Connection:
30
+ - keep-alive
31
+ Status:
32
+ - 200 OK
33
+ Cache-Control:
34
+ - private, max-age=0, must-revalidate
35
+ Strict-Transport-Security:
36
+ - max-age=2592000
37
+ X-Frame-Options:
38
+ - deny
39
+ Set-Cookie:
40
+ - dotcom_user=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT
41
+ - logged_in=no; domain=.github.com; path=/; expires=Mon, 15-Aug-2033 00:44:07
42
+ GMT; secure; HttpOnly
43
+ X-Runtime:
44
+ - '20'
45
+ Etag:
46
+ - '"ed2cf91250498a9276e3b4fa6de2c2b6"'
47
+ Content-Length:
48
+ - '27'
49
+ Vary:
50
+ - Accept-Encoding
51
+ body:
52
+ encoding: UTF-8
53
+ string: error=bad_verification_code
54
+ http_version:
55
+ recorded_at: Thu, 15 Aug 2013 00:44:07 GMT
56
+ recorded_with: VCR 2.5.0
@@ -1,8 +1,17 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
9
+
1
10
  require 'worochi'
2
11
  require 'awesome_print'
3
12
  require 'digest'
4
- require 'ostruct'
5
13
  require 'vcr'
14
+ require 'webmock/rspec'
6
15
 
7
16
  Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
8
17
 
@@ -20,7 +29,11 @@ VCR.configure do |c|
20
29
  c.filter_sensitive_data('<AWS_KEY>') { ENV['AWS_SECRET_ACCESS_KEY'] }
21
30
  c.filter_sensitive_data('<AWS_ID>') { ENV['AWS_ACCESS_KEY_ID'] }
22
31
  c.filter_sensitive_data('<GITHUB_TOKEN>') { ENV['GITHUB_TEST_TOKEN'] }
32
+ c.filter_sensitive_data('<GITHUB_ID>') { ENV['GITHUB_ID'] }
33
+ c.filter_sensitive_data('<GITHUB_SECRET>') { ENV['GITHUB_SECRET'] }
23
34
  c.filter_sensitive_data('<DROPBOX_TOKEN>') { ENV['DROPBOX_TEST_TOKEN'] }
35
+ c.filter_sensitive_data('<DROPBOX_ID>') { ENV['DROPBOX_ID'] }
36
+ c.filter_sensitive_data('<DROPBOX_SECRET>') { ENV['DROPBOX_SECRET'] }
24
37
  end
25
38
 
26
39
  RSpec.configure do |c|
@@ -3,7 +3,7 @@ VCR.configure do |c|
3
3
  c.register_request_matcher :uri_aws do |x, y|
4
4
  next true if x.uri == y.uri
5
5
  next false unless x.uri.include?('amazonaws.com')
6
- URI(x.uri).path == URI(y.uri).path
6
+ URI(x.uri).path == URI(y.uri).path && URI(x.uri).host == URI(y.uri).host
7
7
  end
8
8
 
9
9
  c.default_cassette_options = {
@@ -2,7 +2,7 @@ shared_examples_for 'a service agent' do
2
2
  describe '#default_options' do
3
3
  it 'has the required options' do
4
4
  (required_keys + [:dir, :service]).each do |key|
5
- expect(agent.default_options).to include(key)
5
+ expect(agent.send(:default_options)).to include(key)
6
6
  end
7
7
  end
8
8
  end
@@ -26,6 +26,10 @@ shared_examples_for 'a service agent' do
26
26
  it 'accepts a different relative path' do
27
27
  expect(agent.files('folder1')).to include('test.txt')
28
28
  end
29
+
30
+ it 'raises error on invalid path' do
31
+ expect{agent.files('zzzzz')}.to raise_error Worochi::Error
32
+ end
29
33
  end
30
34
 
31
35
  describe '#folders', :vcr do
@@ -46,6 +50,13 @@ shared_examples_for 'a service agent' do
46
50
  it 'contains folder1 and file1' do
47
51
  expect(agent.files_and_folders).to include('file1')
48
52
  expect(agent.files_and_folders).to include('folder1')
49
- end
53
+ end
54
+
55
+ it 'shows detailed listing including the required fields' do
56
+ list = agent.files_and_folders(true)
57
+ expect(list.first).to include(:name)
58
+ expect(list.first).to include(:path)
59
+ expect(list.first).to include(:type)
60
+ end
50
61
  end
51
62
  end
@@ -6,18 +6,18 @@ module TestFiles
6
6
  checksum: '3c0d873709da4a08e9d9978f678dbc30a6cc5138182c2fee56db1c0b8b806d67',
7
7
  name: 'sr3.gif',
8
8
  path: '/folder1/sr3.gif',
9
- size: 2985
9
+ file_size: 2985
10
10
  })
11
11
  end
12
12
 
13
13
  # Local file for testing.
14
14
  def local
15
- @local ||= OpenStruct.new({
15
+ @local ||= Hashie::Mash.new({
16
16
  source: File.join(File.dirname(__FILE__), 'test_file'),
17
17
  checksum: '798d1088d589c155841cfd6ddd5c8254e883d49220d3a60c10d0f77ce96a5ac4',
18
18
  name: 'test_file',
19
19
  path: '/folder2/test_file',
20
- size: File.open(File.join(File.dirname(__FILE__), 'test_file')).size
20
+ file_size: File.open(File.join(File.dirname(__FILE__), 'test_file')).size
21
21
  })
22
22
  end
23
23
 
@@ -28,7 +28,7 @@ module TestFiles
28
28
  checksum: 'f0891f199f0966ec1b1d209b91ff3f51273577944dbbe338f1947ae9f33cb79a',
29
29
  name: '__init__.py',
30
30
  path: '/folder3/__init__.py',
31
- size: 4257
31
+ file_size: 8
32
32
  })
33
33
  end
34
34
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Worochi::Agent::Dropbox do
4
4
  let(:required_keys) { [:chunk_size, :overwrite] }
@@ -14,15 +14,32 @@ describe Worochi::Agent::Dropbox do
14
14
  it_should_behave_like 'a service agent'
15
15
 
16
16
  describe '#push_item', :vcr do
17
- it 'pushes a single item' do
17
+ def push_single
18
18
  agent.delete(local.name)
19
19
  expect(agent.files).not_to include(local.name)
20
20
 
21
21
  item = Worochi::Item.open_single(local.source)
22
- agent.push_item(item)
22
+ chunked = agent.push_item(item)
23
23
 
24
24
  expect(agent.files).to include(local.name)
25
25
  agent.delete(local.name)
26
+ chunked
27
+ end
28
+
29
+ it 'pushes a single item' do
30
+ expect(push_single).to be(false)
31
+ end
32
+ it 'pushes it chunked if size exceeds limit', :vcr do
33
+ agent.options.chunk_size = 4
34
+ expect(push_single).to be(true)
35
+ end
36
+ end
37
+
38
+ describe '#push_items', :vcr do
39
+ it 'pushes multiple items' do
40
+ items = Worochi::Item.open([local.source, local.source])
41
+ expect(agent.push_items(items)).to be(nil)
42
+ agent.delete(local.name)
26
43
  end
27
44
  end
28
45
 
@@ -37,6 +54,15 @@ describe Worochi::Agent::Dropbox do
37
54
  expect(agent.files).to include(local.name)
38
55
  agent.delete(local.name)
39
56
  end
57
+
58
+ it 'raises an error' do
59
+ bad_agent = Worochi::Agent::Dropbox.new({
60
+ token: 'badtoken',
61
+ dir: '/Dev/test'
62
+ })
63
+ item = Worochi::Item.open_single(local.source)
64
+ expect{bad_agent.push_item_chunked(item)}.to raise_error Worochi::Error
65
+ end
40
66
  end
41
67
 
42
68
  describe '#list', :vcr do
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Worochi::Agent::Github do
4
4
  let(:required_keys) { [:repo, :source, :target, :block_size, :commit_msg] }
@@ -17,11 +17,17 @@ describe Worochi::Agent::Github do
17
17
 
18
18
  it_should_behave_like 'a service agent'
19
19
 
20
- before do
21
- @client = agent.init_client
22
- end
20
+ context 'modifies the repo' do
21
+ before do
22
+ @client = agent.init_client
23
+ @item = Worochi::Item.open_single(path: local.path, source: local.source)
24
+ delete_target
25
+ end
26
+
27
+ after do
28
+ delete_target
29
+ end
23
30
 
24
- describe '#push_all', :vcr do
25
31
  def delete_target
26
32
  tag = "heads/#{agent.options[:target]}"
27
33
  begin
@@ -30,35 +36,51 @@ describe Worochi::Agent::Github do
30
36
  end
31
37
  end
32
38
 
33
- it 'pushes a list of items to create a new commit' do
34
- @client = agent.init_client
35
- delete_target
39
+ def ref
40
+ @client.ref(agent.options[:repo], "heads/#{agent.options[:target]}")
41
+ end
36
42
 
37
- hashes = [remote, local].map do |file|
38
- { path: file.path, source: file.source }
39
- end
40
- items = Worochi::Item.open(hashes)
43
+ describe '#push_all', :vcr do
44
+ it 'pushes a list of items to create a new commit' do
45
+ hashes = [remote, local].map do |file|
46
+ { path: file.path, source: file.source }
47
+ end
48
+ items = Worochi::Item.open(hashes)
41
49
 
42
- sha = agent.push_all(items)
43
- ref = @client.ref(agent.options[:repo], "heads/#{agent.options[:target]}")
44
- expect(ref.object.sha).to eq(sha)
50
+ sha = agent.push_all(items)
51
+ expect(ref.object.sha).to eq(sha)
45
52
 
46
- commit = @client.commit(agent.options[:repo], sha)
47
- expect(commit.commit.message).to eq(agent.options[:commit_msg])
53
+ commit = @client.commit(agent.options[:repo], sha)
54
+ expect(commit.commit.message).to eq(agent.options[:commit_msg])
55
+ end
48
56
 
49
- delete_target
57
+ it 'pushes the file to the right place' do
58
+ sha = agent.push_all([@item])
59
+ ls = agent.list(File.dirname(local.path), sha).map { |x| x[:name] }
60
+ expect(ls).to include(local.name)
61
+ end
50
62
  end
51
63
 
52
- it 'pushes the file to the right place' do
53
- delete_target
64
+ describe '#push_item', :vcr do
65
+ it 'pushes a single item and makes a commit' do
66
+ sha = agent.push_item(@item)
67
+ expect(ref.object.sha).to eq(sha)
68
+ end
69
+ end
54
70
 
55
- item = Worochi::Item.open({ source: local.source, path: local.path })
71
+ describe '#stream_blob', :vcr do
72
+ it 'streams the file as an Base64 JSON field' do
73
+ sha = agent.send(:stream_blob, @item)
74
+ expect(sha).to eq('5df468c4497e072139462b88cb78e1df4357534b')
75
+ end
76
+ end
56
77
 
57
- sha = agent.push_all(item)
58
- ls = agent.list(File.dirname(local.path), sha).map { |x| x[:name] }
59
- expect(ls).to include(local.name)
60
-
61
- delete_target
78
+ describe '#push_blob', :vcr do
79
+ it 'pushes the blob even when it is larger than block size' do
80
+ agent.options.block_size = 2
81
+ sha = agent.send(:push_blob, @item)
82
+ expect(sha).to eq('5df468c4497e072139462b88cb78e1df4357534b')
83
+ end
62
84
  end
63
85
  end
64
86
 
@@ -68,6 +90,12 @@ describe Worochi::Agent::Github do
68
90
  end
69
91
  end
70
92
 
93
+ describe '#repos', :vcr do
94
+ it 'lists the repos' do
95
+ expect(agent.repos).to include('darkmirage/test')
96
+ end
97
+ end
98
+
71
99
  describe '#list', :vcr do
72
100
  it 'works with absolute paths' do
73
101
  ls = agent.list('/folder2/subfolder/test').map { |x| x[:name] }
@@ -1,2 +1,35 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
+ class Worochi
4
+ describe Agent do
5
+ let(:agent) { Agent.new({ service: :github, token: '' }) }
6
+ describe '.new' do
7
+ it 'initializes the right child class' do
8
+ expect(agent.class).to be(Agent::Github)
9
+ end
10
+ end
11
+
12
+ describe '#name' do
13
+ it 'returns the display name for the agent' do
14
+ expect(agent.name).to eq('GitHub')
15
+ end
16
+ end
17
+
18
+ describe '#set_dir' do
19
+ it 'sets the remote directory' do
20
+ agent.set_dir('test/a')
21
+ expect(agent.options.dir).to eq('test/a')
22
+ end
23
+ end
24
+
25
+ describe '#remove' do
26
+ it 'removes self from the main agent list' do
27
+ a = Worochi.create(:github, '')
28
+ expect(Worochi.agents).to include(a)
29
+ a.remove
30
+ expect(Worochi.agents).not_to include(a)
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -1,41 +1,57 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
- describe Worochi::Config do
4
- describe '.services' do
5
- it 'returns an Array of services' do
6
- expect(Worochi::Config.services.class).to be(Array)
7
- expect(Worochi::Config.services.first.class).to be(Symbol)
3
+ class Worochi
4
+ describe Config do
5
+ describe '.services' do
6
+ it 'returns an Array of services' do
7
+ expect(Config.services.class).to be(Array)
8
+ expect(Config.services.first.class).to be(Symbol)
9
+ end
8
10
  end
9
- end
10
11
 
11
- describe '.service_display_name' do
12
- it 'returns display name given an ID' do
13
- expect(Worochi::Config.service_display_name(1)).to eq('GitHub')
14
- end
15
- it 'accepts display name given a name' do
16
- expect(Worochi::Config.service_display_name(:dropbox)).to eq('Dropbox')
12
+ describe '.service_display_name' do
13
+ it 'returns display name given an ID' do
14
+ expect(Config.service_display_name(1)).to eq('GitHub')
15
+ end
16
+ it 'accepts display name given a name' do
17
+ expect(Config.service_display_name(:dropbox)).to eq('Dropbox')
18
+ end
19
+ it 'returns nil when not found' do
20
+ expect(Config.service_display_name(:zzzzzz)).to eq(nil)
21
+ expect(Config.service_display_name(-1111)).to eq(nil)
22
+ end
17
23
  end
18
- it 'returns nil when not found' do
19
- expect(Worochi::Config.service_display_name(:zzzzzz)).to eq(nil)
20
- expect(Worochi::Config.service_display_name(-1111)).to eq(nil)
21
- end
22
- end
23
24
 
24
- describe '.service_id' do
25
- it 'returns the service ID given name' do
26
- expect(Worochi::Config.service_id(:dropbox)).to eq(2)
25
+ describe '.service_id' do
26
+ it 'returns the service ID given name' do
27
+ expect(Config.service_id(:dropbox)).to eq(2)
28
+ end
29
+ it 'returns nil when not found' do
30
+ expect(Config.service_id(:zzzzzzz)).to eq(nil)
31
+ end
27
32
  end
28
- it 'returns nil when not found' do
29
- expect(Worochi::Config.service_id(:zzzzzzz)).to eq(nil)
30
- end
31
- end
32
33
 
33
- describe '.service_name' do
34
- it 'returns the service name given ID' do
35
- expect(Worochi::Config.service_name(1)).to eq(:github)
34
+ describe '.service_name' do
35
+ it 'returns the service name given ID' do
36
+ expect(Config.service_name(1)).to eq(:github)
37
+ end
38
+ it 'returns nil when not found' do
39
+ expect(Config.service_name(-1111)).to eq(nil)
40
+ end
36
41
  end
37
- it 'returns nil when not found' do
38
- expect(Worochi::Config.service_name(-1111)).to eq(nil)
42
+
43
+ describe '.service_opts' do
44
+ it 'retrieves the service options' do
45
+ opts = Config.service_opts(:dropbox)
46
+ expect(opts).to include(:service)
47
+ end
48
+ it 'raises error on nil' do
49
+ expect{Config.service_opts(nil)}.to raise_error Error
50
+ expect{Config.service_opts(:zzzzz)}.to raise_error Error
51
+ Config.instance_variable_set(:@options, nil)
52
+ expect{Config.service_opts(:dropbox)}.to raise_error Error
53
+ Worochi.init
54
+ end
39
55
  end
40
56
  end
41
57
  end