ryespy 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,138 @@
1
+ require_relative '../../helper'
2
+
3
+ require_relative '../../../lib/ryespy/listener/amzn_s3'
4
+
5
+
6
+ describe Ryespy::Listener::AmznS3 do
7
+
8
+ before do
9
+ etag = 'QpD453wgum7qpJKUZaeHgcnHtGabP6CS'
10
+
11
+ @files = [
12
+ stub(:content_length => 0, :content_type => '', :key => 'flies/', :etag => etag),
13
+ stub(:content_length => 1, :content_type => '', :key => 'flies/a.txt', :etag => etag),
14
+ stub(:content_length => 1, :content_type => '', :key => 'flies/b.txt', :etag => etag),
15
+ stub(:content_length => 0, :content_type => '', :key => 'f/', :etag => etag),
16
+ stub(:content_length => 1, :content_type => '', :key => 'f/flies_README.txt', :etag => etag),
17
+ stub(:content_length => 0, :content_type => '', :key => 'spiders/', :etag => etag),
18
+ stub(:content_length => 1, :content_type => '', :key => 'spiders/spider.txt', :etag => etag),
19
+ ]
20
+
21
+ @files_no_dirs = @files.select { |f| f.content_length != 0 }
22
+
23
+ @fog_storage = stub
24
+
25
+ @fog_storage_directories = stub
26
+
27
+ @fog_storage_directories.stubs(:get).with('icw', {
28
+ :prefix => 'flies/'
29
+ }).returns(stub(:files => @files.select { |f| f.key =~ /^flies\// }))
30
+ @fog_storage_directories.stubs(:get).with('icw', {
31
+ :prefix => 'f'
32
+ }).returns(stub(:files => @files.select { |f| f.key =~ /^f/ }))
33
+ @fog_storage_directories.stubs(:get).with('icw', {
34
+ :prefix => 'spiders/'
35
+ }).returns(stub(:files => @files.select { |f| f.key =~ /^spiders\// }))
36
+ @fog_storage_directories.stubs(:get).with('icw', {
37
+ :prefix => ''
38
+ }).returns(stub(:files => @files))
39
+
40
+ @fog_storage.stubs(:directories).returns(@fog_storage_directories)
41
+
42
+ Fog::Storage.stubs(:new).with({
43
+ :provider => 'AWS',
44
+ :aws_access_key_id => 'r.m.renfield',
45
+ :aws_secret_access_key => 'master',
46
+ }).returns(@fog_storage)
47
+ end
48
+
49
+ describe "#check" do
50
+ before do
51
+ Ryespy::Test::Redis::setup
52
+
53
+ @notifier = mock()
54
+
55
+ @amzn_s3 = Ryespy::Listener::AmznS3.new(
56
+ :access_key => 'r.m.renfield',
57
+ :secret_key => 'master',
58
+ :bucket => 'icw',
59
+ :notifiers => [@notifier],
60
+ )
61
+
62
+ @redis = @amzn_s3.instance_variable_get(:@redis)
63
+ end
64
+
65
+ after do
66
+ @amzn_s3.close
67
+
68
+ Ryespy::Test::Redis::flush_namespace(@redis)
69
+ end
70
+
71
+ it "notifies when new files prefix *" do
72
+ @files_no_dirs.each do |file|
73
+ @notifier.expects(:notify).with('RyespyAmznS3Job', [file.key]).once
74
+ end
75
+
76
+ @amzn_s3.check('')
77
+ end
78
+
79
+ it "notifies when new files prefix spiders/" do
80
+ @files_no_dirs.select { |f| f.key =~ /^spiders\// }.each do |file|
81
+ @notifier.expects(:notify).with('RyespyAmznS3Job', [file.key]).once
82
+ end
83
+
84
+ @amzn_s3.check('spiders/')
85
+ end
86
+
87
+ it "notifies when new files prefix f" do
88
+ @files_no_dirs.select { |f| f.key =~ /^f/ }.each do |file|
89
+ @notifier.expects(:notify).with('RyespyAmznS3Job', [file.key]).once
90
+ end
91
+
92
+ @amzn_s3.check('f')
93
+ end
94
+
95
+ it "doesn't notify when no new files" do
96
+ @notifier.expects(:notify).times(2)
97
+
98
+ @amzn_s3.check('flies/')
99
+
100
+ @notifier.expects(:notify).never
101
+
102
+ @amzn_s3.check('flies/')
103
+ end
104
+
105
+ it "doesn't notify when no new files prefix subset" do
106
+ @notifier.expects(:notify).times(3)
107
+
108
+ @amzn_s3.check('f')
109
+
110
+ @notifier.expects(:notify).never
111
+
112
+ @amzn_s3.check('flies/')
113
+ end
114
+
115
+ it "notifies when new files prefix distinct" do
116
+ @notifier.expects(:notify).times(3)
117
+
118
+ @amzn_s3.check('f')
119
+
120
+ @notifier.expects(:notify).times(1)
121
+
122
+ @amzn_s3.check('spiders/')
123
+ end
124
+
125
+ it "notifies when changed etag" do
126
+ @notifier.expects(:notify).times(2)
127
+
128
+ @amzn_s3.check('flies/')
129
+
130
+ @files[1].stubs(:etag).returns(-2303600400)
131
+
132
+ @notifier.expects(:notify).with('RyespyAmznS3Job', ['flies/a.txt']).once
133
+
134
+ @amzn_s3.check('flies/')
135
+ end
136
+ end
137
+
138
+ end
@@ -0,0 +1,96 @@
1
+ require_relative '../../helper'
2
+
3
+ require_relative '../../../lib/ryespy/listener/ftp'
4
+
5
+
6
+ describe Ryespy::Listener::FTP do
7
+
8
+ before do
9
+ @files = [
10
+ 'Bottlenose',
11
+ 'Haeviside',
12
+ 'Franciscana',
13
+ ]
14
+
15
+ @net_ftp = stub
16
+
17
+ @net_ftp.stubs(:connect).with('ftp.example.com', 2121)
18
+ @net_ftp.stubs(:passive=)
19
+ @net_ftp.stubs(:login).with('d.adams', 'solongandthanksforallthefish')
20
+ @net_ftp.stubs(:chdir).with('/dolphin')
21
+ @net_ftp.stubs(:nlst).returns(@files)
22
+ @net_ftp.stubs(:mtime).returns(-562032000)
23
+ @net_ftp.stubs(:size).returns(42)
24
+ @net_ftp.stubs(:close)
25
+
26
+ Net::FTP.stubs(:new).returns(@net_ftp)
27
+ end
28
+
29
+ describe "#check" do
30
+ before do
31
+ Ryespy::Test::Redis::setup
32
+
33
+ @notifier = mock()
34
+
35
+ @ftp = Ryespy::Listener::FTP.new(
36
+ :host => 'ftp.example.com',
37
+ :port => 2121,
38
+ :passive => true,
39
+ :username => 'd.adams',
40
+ :password => 'solongandthanksforallthefish',
41
+ :notifiers => [@notifier],
42
+ )
43
+
44
+ @redis = @ftp.instance_variable_get(:@redis)
45
+ end
46
+
47
+ after do
48
+ @ftp.close
49
+
50
+ Ryespy::Test::Redis::flush_namespace(@redis)
51
+ end
52
+
53
+ it "notifies when new files" do
54
+ @files.each do |file|
55
+ @notifier.expects(:notify).with('RyespyFTPJob', ['/dolphin', file]).once
56
+ end
57
+
58
+ @ftp.check('/dolphin')
59
+ end
60
+
61
+ it "doesn't notify when no new files" do
62
+ @notifier.expects(:notify).times(3)
63
+
64
+ @ftp.check('/dolphin')
65
+
66
+ @notifier.expects(:notify).never
67
+
68
+ @ftp.check('/dolphin')
69
+ end
70
+
71
+ it "notifies when changed mtime" do
72
+ @notifier.expects(:notify).times(3)
73
+
74
+ @ftp.check('/dolphin')
75
+
76
+ @net_ftp.stubs(:mtime).with('Bottlenose').returns(-562031999)
77
+
78
+ @notifier.expects(:notify).with('RyespyFTPJob', ['/dolphin', 'Bottlenose']).once
79
+
80
+ @ftp.check('/dolphin')
81
+ end
82
+
83
+ it "notifies when changed size" do
84
+ @notifier.expects(:notify).times(3)
85
+
86
+ @ftp.check('/dolphin')
87
+
88
+ @net_ftp.stubs(:size).with('Franciscana').returns(41)
89
+
90
+ @notifier.expects(:notify).with('RyespyFTPJob', ['/dolphin', 'Franciscana']).once
91
+
92
+ @ftp.check('/dolphin')
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,138 @@
1
+ require_relative '../../helper'
2
+
3
+ require_relative '../../../lib/ryespy/listener/goog_cs'
4
+
5
+
6
+ describe Ryespy::Listener::GoogCS do
7
+
8
+ before do
9
+ etag = 'QpD453wgum7qpJKUZaeHgcnHtGabP6CS'
10
+
11
+ @files = [
12
+ stub(:content_length => 0, :content_type => '', :key => 'flies/', :etag => etag),
13
+ stub(:content_length => 1, :content_type => '', :key => 'flies/a.txt', :etag => etag),
14
+ stub(:content_length => 1, :content_type => '', :key => 'flies/b.txt', :etag => etag),
15
+ stub(:content_length => 0, :content_type => '', :key => 'f/', :etag => etag),
16
+ stub(:content_length => 1, :content_type => '', :key => 'f/flies_README.txt', :etag => etag),
17
+ stub(:content_length => 0, :content_type => '', :key => 'spiders/', :etag => etag),
18
+ stub(:content_length => 1, :content_type => '', :key => 'spiders/spider.txt', :etag => etag),
19
+ ]
20
+
21
+ @files_no_dirs = @files.select { |f| f.content_length != 0 }
22
+
23
+ @fog_storage = stub
24
+
25
+ @fog_storage_directories = stub
26
+
27
+ @fog_storage_directories.stubs(:get).with('icw', {
28
+ :prefix => 'flies/'
29
+ }).returns(stub(:files => @files.select { |f| f.key =~ /^flies\// }))
30
+ @fog_storage_directories.stubs(:get).with('icw', {
31
+ :prefix => 'f'
32
+ }).returns(stub(:files => @files.select { |f| f.key =~ /^f/ }))
33
+ @fog_storage_directories.stubs(:get).with('icw', {
34
+ :prefix => 'spiders/'
35
+ }).returns(stub(:files => @files.select { |f| f.key =~ /^spiders\// }))
36
+ @fog_storage_directories.stubs(:get).with('icw', {
37
+ :prefix => ''
38
+ }).returns(stub(:files => @files))
39
+
40
+ @fog_storage.stubs(:directories).returns(@fog_storage_directories)
41
+
42
+ Fog::Storage.stubs(:new).with({
43
+ :provider => 'Google',
44
+ :google_storage_access_key_id => 'r.m.renfield',
45
+ :google_storage_secret_access_key => 'master',
46
+ }).returns(@fog_storage)
47
+ end
48
+
49
+ describe "#check" do
50
+ before do
51
+ Ryespy::Test::Redis::setup
52
+
53
+ @notifier = mock()
54
+
55
+ @goog_cs = Ryespy::Listener::GoogCS.new(
56
+ :access_key => 'r.m.renfield',
57
+ :secret_key => 'master',
58
+ :bucket => 'icw',
59
+ :notifiers => [@notifier],
60
+ )
61
+
62
+ @redis = @goog_cs.instance_variable_get(:@redis)
63
+ end
64
+
65
+ after do
66
+ @goog_cs.close
67
+
68
+ Ryespy::Test::Redis::flush_namespace(@redis)
69
+ end
70
+
71
+ it "notifies when new files prefix *" do
72
+ @files_no_dirs.each do |file|
73
+ @notifier.expects(:notify).with('RyespyGoogCSJob', [file.key]).once
74
+ end
75
+
76
+ @goog_cs.check('')
77
+ end
78
+
79
+ it "notifies when new files prefix spiders/" do
80
+ @files_no_dirs.select { |f| f.key =~ /^spiders\// }.each do |file|
81
+ @notifier.expects(:notify).with('RyespyGoogCSJob', [file.key]).once
82
+ end
83
+
84
+ @goog_cs.check('spiders/')
85
+ end
86
+
87
+ it "notifies when new files prefix f" do
88
+ @files_no_dirs.select { |f| f.key =~ /^f/ }.each do |file|
89
+ @notifier.expects(:notify).with('RyespyGoogCSJob', [file.key]).once
90
+ end
91
+
92
+ @goog_cs.check('f')
93
+ end
94
+
95
+ it "doesn't notify when no new files" do
96
+ @notifier.expects(:notify).times(2)
97
+
98
+ @goog_cs.check('flies/')
99
+
100
+ @notifier.expects(:notify).never
101
+
102
+ @goog_cs.check('flies/')
103
+ end
104
+
105
+ it "doesn't notify when no new files prefix subset" do
106
+ @notifier.expects(:notify).times(3)
107
+
108
+ @goog_cs.check('f')
109
+
110
+ @notifier.expects(:notify).never
111
+
112
+ @goog_cs.check('flies/')
113
+ end
114
+
115
+ it "notifies when new files prefix distinct" do
116
+ @notifier.expects(:notify).times(3)
117
+
118
+ @goog_cs.check('f')
119
+
120
+ @notifier.expects(:notify).times(1)
121
+
122
+ @goog_cs.check('spiders/')
123
+ end
124
+
125
+ it "notifies when changed etag" do
126
+ @notifier.expects(:notify).times(2)
127
+
128
+ @goog_cs.check('flies/')
129
+
130
+ @files[1].stubs(:etag).returns(-2303600400)
131
+
132
+ @notifier.expects(:notify).with('RyespyGoogCSJob', ['flies/a.txt']).once
133
+
134
+ @goog_cs.check('flies/')
135
+ end
136
+ end
137
+
138
+ end
@@ -0,0 +1,68 @@
1
+ require_relative '../../helper'
2
+
3
+ require_relative '../../../lib/ryespy/listener/imap'
4
+
5
+
6
+ describe Ryespy::Listener::IMAP do
7
+
8
+ before do
9
+ @uids = [6, 7, 42]
10
+
11
+ @net_imap = stub
12
+
13
+ @net_imap.stubs(:login).with('d.adams', 'solongandthanksforallthefish')
14
+ @net_imap.stubs(:select).with('Dolphin')
15
+ @net_imap.stubs(:uid_search).with('1:*').returns(@uids)
16
+ @net_imap.stubs(:uid_search).with('43:*').returns([])
17
+ @net_imap.stubs(:disconnect)
18
+
19
+ Net::IMAP.stubs(:new).with('imap.example.com', {
20
+ :port => 42,
21
+ :ssl => true,
22
+ }).returns(@net_imap)
23
+ end
24
+
25
+ describe "#check" do
26
+ before do
27
+ Ryespy::Test::Redis::setup
28
+
29
+ @notifier = mock()
30
+
31
+ @imap = Ryespy::Listener::IMAP.new(
32
+ :host => 'imap.example.com',
33
+ :port => 42,
34
+ :ssl => true,
35
+ :username => 'd.adams',
36
+ :password => 'solongandthanksforallthefish',
37
+ :notifiers => [@notifier],
38
+ )
39
+
40
+ @redis = @imap.instance_variable_get(:@redis)
41
+ end
42
+
43
+ after do
44
+ @imap.close
45
+
46
+ Ryespy::Test::Redis::flush_namespace(@redis)
47
+ end
48
+
49
+ it "notifies when new files" do
50
+ @uids.each do |uid|
51
+ @notifier.expects(:notify).with('RyespyIMAPJob', ['Dolphin', uid]).once
52
+ end
53
+
54
+ @imap.check('Dolphin')
55
+ end
56
+
57
+ it "doesn't notify when no new files" do
58
+ @notifier.expects(:notify).times(3)
59
+
60
+ @imap.check('Dolphin')
61
+
62
+ @notifier.expects(:notify).never
63
+
64
+ @imap.check('Dolphin')
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,142 @@
1
+ require_relative '../../helper'
2
+
3
+ require_relative '../../../lib/ryespy/listener/rax_cf'
4
+
5
+
6
+ describe Ryespy::Listener::RaxCF do
7
+
8
+ before do
9
+ etag = 'dvYAPmJPy8nyqtR8hqqPYIagWEDuZ9FN'
10
+
11
+ @files = [
12
+ stub(:content_length => 0, :content_type => 'application/directory', :key => 'abraham/', :etag => etag),
13
+ stub(:content_length => 1, :content_type => 'text/plain', :key => 'abraham/a.txt', :etag => etag),
14
+ stub(:content_length => 1, :content_type => 'text/plain', :key => 'abraham/b.txt', :etag => etag),
15
+ stub(:content_length => 0, :content_type => 'application/directory', :key => 'a/', :etag => etag),
16
+ stub(:content_length => 1, :content_type => 'text/plain', :key => 'a/abraham_README.txt', :etag => etag),
17
+ stub(:content_length => 0, :content_type => 'application/directory', :key => 'van/', :etag => etag),
18
+ stub(:content_length => 1, :content_type => 'text/plain', :key => 'van/van.txt', :etag => etag),
19
+ ]
20
+
21
+ @files_no_dirs = @files.select { |f| f.content_type != 'application/directory' }
22
+
23
+ @fog_storage = stub
24
+
25
+ @fog_storage_directories = stub
26
+
27
+ @fog_storage_directories.stubs(:get).with('tmtiscnoa', {
28
+ :prefix => 'abraham/'
29
+ }).returns(stub(:files => @files.select { |f| f.key =~ /^abraham\// }))
30
+ @fog_storage_directories.stubs(:get).with('tmtiscnoa', {
31
+ :prefix => 'a'
32
+ }).returns(stub(:files => @files.select { |f| f.key =~ /^a/ }))
33
+ @fog_storage_directories.stubs(:get).with('tmtiscnoa', {
34
+ :prefix => 'van/'
35
+ }).returns(stub(:files => @files.select { |f| f.key =~ /^van\// }))
36
+ @fog_storage_directories.stubs(:get).with('tmtiscnoa', {
37
+ :prefix => ''
38
+ }).returns(stub(:files => @files))
39
+
40
+ @fog_storage.stubs(:directories).returns(@fog_storage_directories)
41
+
42
+ Fog::Storage.stubs(:new).with({
43
+ :provider => 'Rackspace',
44
+ :rackspace_auth_url => 'https://lon.identity.api.rackspacecloud.com/v2.0',
45
+ :rackspace_region => :lon,
46
+ :rackspace_username => 'van.helsing',
47
+ :rackspace_api_key => 'M.D., D.Ph., D.Litt., etc.',
48
+ }).returns(@fog_storage)
49
+ end
50
+
51
+ describe "#check" do
52
+ before do
53
+ Ryespy::Test::Redis::setup
54
+
55
+ @notifier = mock()
56
+
57
+ @rax_cf = Ryespy::Listener::RaxCF.new(
58
+ :endpoint => 'uk',
59
+ :region => 'lon',
60
+ :username => 'van.helsing',
61
+ :api_key => 'M.D., D.Ph., D.Litt., etc.',
62
+ :container => 'tmtiscnoa',
63
+ :notifiers => [@notifier],
64
+ )
65
+
66
+ @redis = @rax_cf.instance_variable_get(:@redis)
67
+ end
68
+
69
+ after do
70
+ @rax_cf.close
71
+
72
+ Ryespy::Test::Redis::flush_namespace(@redis)
73
+ end
74
+
75
+ it "notifies when new files prefix *" do
76
+ @files_no_dirs.each do |file|
77
+ @notifier.expects(:notify).with('RyespyRaxCFJob', [file.key]).once
78
+ end
79
+
80
+ @rax_cf.check('')
81
+ end
82
+
83
+ it "notifies when new files prefix van/" do
84
+ @files_no_dirs.select { |f| f.key =~ /^van\// }.each do |file|
85
+ @notifier.expects(:notify).with('RyespyRaxCFJob', [file.key]).once
86
+ end
87
+
88
+ @rax_cf.check('van/')
89
+ end
90
+
91
+ it "notifies when new files prefix a" do
92
+ @files_no_dirs.select { |f| f.key =~ /^a/ }.each do |file|
93
+ @notifier.expects(:notify).with('RyespyRaxCFJob', [file.key]).once
94
+ end
95
+
96
+ @rax_cf.check('a')
97
+ end
98
+
99
+ it "doesn't notify when no new files" do
100
+ @notifier.expects(:notify).times(2)
101
+
102
+ @rax_cf.check('abraham/')
103
+
104
+ @notifier.expects(:notify).never
105
+
106
+ @rax_cf.check('abraham/')
107
+ end
108
+
109
+ it "doesn't notify when no new files prefix subset" do
110
+ @notifier.expects(:notify).times(3)
111
+
112
+ @rax_cf.check('a')
113
+
114
+ @notifier.expects(:notify).never
115
+
116
+ @rax_cf.check('abraham/')
117
+ end
118
+
119
+ it "notifies when new files prefix distinct" do
120
+ @notifier.expects(:notify).times(3)
121
+
122
+ @rax_cf.check('a')
123
+
124
+ @notifier.expects(:notify).times(1)
125
+
126
+ @rax_cf.check('van/')
127
+ end
128
+
129
+ it "notifies when changed etag" do
130
+ @notifier.expects(:notify).times(2)
131
+
132
+ @rax_cf.check('abraham/')
133
+
134
+ @files[1].stubs(:etag).returns(-2303600400)
135
+
136
+ @notifier.expects(:notify).with('RyespyRaxCFJob', ['abraham/a.txt']).once
137
+
138
+ @rax_cf.check('abraham/')
139
+ end
140
+ end
141
+
142
+ end