huck 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/huck/receiver.rb +37 -0
- data/lib/huck/senders/sqs.rb +13 -11
- data/lib/huck/util.rb +2 -2
- data/lib/huck/version.rb +1 -1
- data/lib/huck.rb +3 -23
- data/spec/huck/generator_spec.rb +32 -0
- data/spec/huck/generators/basic_spec.rb +28 -0
- data/spec/huck/generators/exec_spec.rb +13 -0
- data/spec/huck/generators/facter_spec.rb +23 -0
- data/spec/huck/generators/file_spec.rb +19 -0
- data/spec/huck/generators/ohai_spec.rb +26 -0
- data/spec/huck/handler_spec.rb +17 -0
- data/spec/huck/handlers/echo_spec.rb +9 -0
- data/spec/huck/handlers/exec_spec.rb +16 -0
- data/spec/huck/huck_spec.rb +51 -0
- data/spec/huck/receiver_spec.rb +36 -0
- data/spec/huck/receivers/sqs_spec.rb +38 -0
- data/spec/huck/sender_spec.rb +17 -0
- data/spec/huck/senders/sqs_spec.rb +37 -0
- data/spec/huck/util_spec.rb +28 -1
- data/spec/spec_helper.rb +2 -1
- metadata +112 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25a756eec35292ca791c294071c7a845f8763a4b
|
4
|
+
data.tar.gz: 0b865048d077ea23f3fb206200f829bb7244ea9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29b100df5fe489d1b392b8def0a347ef194e719ac457c2d04b916ee0265de0b9b90e0ce8a5a2bfec7d2f08b9f5a81ccdb712c490dd90f94686a3b7e612c670ba
|
7
|
+
data.tar.gz: 16eae156c0519939642214cbc7db1add89b63289631e8e8a9edb00dc3fd9d2da04700f4c93439e01edc42cf3b6871121840def762f220f3f879d6740c17b1aef
|
data/lib/huck/receiver.rb
CHANGED
@@ -34,5 +34,42 @@ module Huck
|
|
34
34
|
return r
|
35
35
|
end
|
36
36
|
|
37
|
+
# Given some handlers (or a block), grab messages out of the
|
38
|
+
# queue and feed them through to the handlers.
|
39
|
+
#
|
40
|
+
# == Parameters:
|
41
|
+
# handlers::
|
42
|
+
# An array of Huck::Handler instances
|
43
|
+
# block::
|
44
|
+
# A code block, or nil
|
45
|
+
#
|
46
|
+
def accept handlers, block
|
47
|
+
begin
|
48
|
+
receive do |msg|
|
49
|
+
begin
|
50
|
+
if block
|
51
|
+
hname = '<block>'
|
52
|
+
block.call msg
|
53
|
+
next # skip other handlers
|
54
|
+
end
|
55
|
+
|
56
|
+
handlers.each do |h|
|
57
|
+
hname = h.class.to_s
|
58
|
+
h.handle msg
|
59
|
+
end
|
60
|
+
rescue => e
|
61
|
+
puts "Handler error (#{hname}): #{e.message}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
rescue Interrupt, SystemExit
|
65
|
+
return
|
66
|
+
rescue => e
|
67
|
+
puts "Receiver error (#{self.class}): #{e.message}"
|
68
|
+
puts "Retrying in 5s..."
|
69
|
+
sleep 5
|
70
|
+
retry
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
37
74
|
end
|
38
75
|
end
|
data/lib/huck/senders/sqs.rb
CHANGED
@@ -11,16 +11,15 @@ module Huck
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# Ensures that configuration is set properly before trying to use the
|
14
|
-
# connection data to talk to AWS
|
14
|
+
# connection data to talk to AWS. It is possible that IAM profiles are
|
15
|
+
# in use, so we can't strictly require that all of the access information
|
16
|
+
# is set in the configuration.
|
15
17
|
def verify_config
|
16
18
|
if !@config.has_key? 'sqs'
|
17
19
|
raise RuntimeError, 'missing sqs sender config'
|
18
20
|
end
|
19
|
-
['
|
20
|
-
|
21
|
-
if !@config['sqs'].has_key? key
|
22
|
-
raise RuntimeError, "missing sqs sender config: #{key}"
|
23
|
-
end
|
21
|
+
if !@config['sqs'].has_key? 'queue_name'
|
22
|
+
raise RuntimeError, 'missing sqs sender config: queue_name'
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -33,11 +32,14 @@ module Huck
|
|
33
32
|
def send msg
|
34
33
|
verify_config
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
options = Hash.new
|
36
|
+
[:access_key_id, :secret_access_key, :region].each do |arg|
|
37
|
+
if @config['sqs'].has_key? arg.to_s
|
38
|
+
options[arg] = @config['sqs'][arg.to_s]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
sqs = AWS::SQS.new options
|
41
43
|
|
42
44
|
queue = sqs.queues.create @config['sqs']['queue_name']
|
43
45
|
queue.send_message msg
|
data/lib/huck/util.rb
CHANGED
@@ -60,7 +60,7 @@ module Huck
|
|
60
60
|
#
|
61
61
|
def self.must_load name
|
62
62
|
if !self.try_load name
|
63
|
-
raise RuntimeError, "unable to load #{name}"
|
63
|
+
raise RuntimeError, "huck: unable to load #{name}"
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -108,7 +108,7 @@ module Huck
|
|
108
108
|
elsif provider.kind_of? String
|
109
109
|
name = provider
|
110
110
|
else
|
111
|
-
raise RuntimeError, "expected hash, got: #{
|
111
|
+
raise RuntimeError, "expected string or hash, got: #{provider}"
|
112
112
|
end
|
113
113
|
yield name, config
|
114
114
|
end
|
data/lib/huck/version.rb
CHANGED
data/lib/huck.rb
CHANGED
@@ -73,7 +73,7 @@ module Huck
|
|
73
73
|
# config::
|
74
74
|
# Configuration hash to use in place of a config file
|
75
75
|
#
|
76
|
-
def self.serve kwargs = {}
|
76
|
+
def self.serve kwargs = {}, &block
|
77
77
|
config = Huck::getarg kwargs, :config, nil
|
78
78
|
if config.nil?
|
79
79
|
conf_file = Huck::getarg kwargs, :config_file, nil
|
@@ -93,29 +93,9 @@ module Huck
|
|
93
93
|
end
|
94
94
|
recv_arg = Huck::getarg kwargs, :receiver, nil
|
95
95
|
recv_name = recv_arg if !recv_arg.nil?
|
96
|
-
|
96
|
+
receiver = Receiver::factory :name => recv_name, :config => config
|
97
97
|
|
98
|
-
|
99
|
-
begin
|
100
|
-
r.receive do |msg|
|
101
|
-
begin
|
102
|
-
if block_given?
|
103
|
-
hname = '<block>'
|
104
|
-
yield msg
|
105
|
-
next # skip other handlers
|
106
|
-
end
|
107
|
-
|
108
|
-
handlers.each do |h|
|
109
|
-
hname = h.class.to_s
|
110
|
-
h.handle msg
|
111
|
-
end
|
112
|
-
rescue => e
|
113
|
-
puts "Handler error (#{hname}): #{e.message}"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
rescue Interrupt, SystemExit
|
117
|
-
return
|
118
|
-
end
|
98
|
+
receiver.accept handlers, block
|
119
99
|
end
|
120
100
|
|
121
101
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'getting generator instances' do
|
4
|
+
it 'should return the basic generator' do
|
5
|
+
expect(Huck::Generator::factory :name => 'basic').to(
|
6
|
+
be_a Huck::Generators::BasicGenerator)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return the facter generator' do
|
10
|
+
expect(Huck::Generator::factory :name => 'facter').to(
|
11
|
+
be_a Huck::Generators::FacterGenerator)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return the ohai generator' do
|
15
|
+
expect(Huck::Generator::factory :name => 'ohai').to(
|
16
|
+
be_a Huck::Generators::OhaiGenerator)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return the file generator' do
|
20
|
+
expect(Huck::Generator::factory :name => 'file').to(
|
21
|
+
be_a Huck::Generators::FileGenerator)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should return the exec generator' do
|
25
|
+
expect(Huck::Generator::factory :name => 'exec').to(
|
26
|
+
be_a Huck::Generators::ExecGenerator)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should raise on invalid generator' do
|
30
|
+
expect { Huck::Generator::factory :name => 'bad' }.to raise_error
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'basic generator' do
|
4
|
+
before(:each) do
|
5
|
+
stub_const('RUBY_PLATFORM', 'linux')
|
6
|
+
allow(Socket).to receive(:gethostname).and_return('test')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return json by default' do
|
10
|
+
g = Huck::Generator::factory :name => 'basic', :config => {}
|
11
|
+
expect(g.generate).to eq('{"hostname":"test","platform":"linux"}')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return json on request' do
|
15
|
+
g = Huck::Generator::factory :name => 'basic', :config => {'format' => 'json'}
|
16
|
+
expect(g.generate).to eq('{"hostname":"test","platform":"linux"}')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return yaml on request' do
|
20
|
+
g = Huck::Generator::factory :name => 'basic', :config => {'format' => 'yaml'}
|
21
|
+
expect(g.generate).to eq("---\nhostname: test\nplatform: linux\n")
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should raise on invalid format' do
|
25
|
+
g = Huck::Generator::factory :name => 'basic', :config => {'format' => 'bad'}
|
26
|
+
expect { g.generate }.to raise_error
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'exec generator' do
|
4
|
+
it 'should return the output of a command' do
|
5
|
+
g = Huck::Generator::factory :name => 'exec', :config => {'command' => 'echo hi'}
|
6
|
+
expect(g.generate).to eq("hi\n")
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should raise if no command is given' do
|
10
|
+
g = Huck::Generator::factory :name => 'exec', :config => {}
|
11
|
+
expect { g.generate }.to raise_error
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'facter generator' do
|
4
|
+
before(:each) do
|
5
|
+
allow(Huck).to receive(:try_load).and_return(true)
|
6
|
+
allow(Facter).to receive(:to_hash).and_return({'a' => 'b'})
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return json by default' do
|
10
|
+
g = Huck::Generator::factory :name => 'facter', :config => {}
|
11
|
+
expect(g.generate).to eq('{"a":"b"}')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return json upon request' do
|
15
|
+
g = Huck::Generator::factory :name => 'facter', :config => {'format' => 'json'}
|
16
|
+
expect(g.generate).to eq('{"a":"b"}')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return yaml upon request' do
|
20
|
+
g = Huck::Generator::factory :name => 'facter', :config => {'format' => 'yaml'}
|
21
|
+
expect(g.generate).to eq("---\na: b\n")
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'file generator' do
|
4
|
+
it 'should return the raw content of a file' do
|
5
|
+
file = mktempfile :content => 'test'
|
6
|
+
g = Huck::Generator::factory :name => 'file', :config => {'path' => file}
|
7
|
+
expect(g.generate).to eq('test')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should raise if no path is provided' do
|
11
|
+
g = Huck::Generator::factory :name => 'file', :config => {}
|
12
|
+
expect { g.generate }.to raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should raise if the file does not exist' do
|
16
|
+
g = Huck::Generator::factory :name => 'file', :config => {'path' => '/bad'}
|
17
|
+
expect { g.generate }.to raise_error
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'ohai generator' do
|
4
|
+
before(:each) do
|
5
|
+
allow(Huck).to receive(:must_load)
|
6
|
+
ohai_system = double
|
7
|
+
allow(Ohai::System).to receive(:new).and_return(ohai_system)
|
8
|
+
allow(ohai_system).to receive(:all_plugins)
|
9
|
+
allow(ohai_system).to receive(:json_pretty_print).and_return('{"a":"b"}')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should return json by default' do
|
13
|
+
g = Huck::Generator::factory :name => 'ohai', :config => {}
|
14
|
+
expect(g.generate).to eq('{"a":"b"}')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return json upon request' do
|
18
|
+
g = Huck::Generator::factory :name => 'ohai', :config => {'format' => 'json'}
|
19
|
+
expect(g.generate).to eq('{"a":"b"}')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should return yaml upon request' do
|
23
|
+
g = Huck::Generator::factory :name => 'ohai', :config => {'format' => 'yaml'}
|
24
|
+
expect(g.generate).to eq("---\na: b\n")
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'getting handler instances' do
|
4
|
+
it 'should return the echo handler' do
|
5
|
+
expect(Huck::Handler::factory :name => 'echo').to(
|
6
|
+
be_a Huck::Handlers::EchoHandler)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return the exec handler' do
|
10
|
+
expect(Huck::Handler::factory :name => 'exec').to(
|
11
|
+
be_a Huck::Handlers::ExecHandler)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should raise if no valid handlers found' do
|
15
|
+
expect { Huck::Handler::factory :name => 'bad' }.to raise_error
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'exec handler' do
|
4
|
+
it 'should raise if no command provided' do
|
5
|
+
h = Huck::Handler::factory :name => 'exec', :config => {}
|
6
|
+
expect { h.verify_config }.to raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should execute a command and return its output' do
|
10
|
+
file = mktempfile
|
11
|
+
config = {'command' => "cat >> #{file}"}
|
12
|
+
h = Huck::Handler::factory :name => 'exec', :config => config
|
13
|
+
h.handle 'hello'
|
14
|
+
expect(open(file).read).to eq('hello')
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'running the client' do
|
4
|
+
before(:each) do
|
5
|
+
sender = double
|
6
|
+
allow(sender).to receive(:send).once
|
7
|
+
allow(Huck::Sender).to receive(:factory).and_return(sender)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should accept config as a hash' do
|
11
|
+
config = {'sender' => 'sqs', 'generators' => ['basic']}
|
12
|
+
expect(Huck.run :config => config).not_to be_empty
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should read a config file' do
|
16
|
+
file = mktempfile :content => <<EOF
|
17
|
+
sender: sqs
|
18
|
+
generators:
|
19
|
+
- basic
|
20
|
+
EOF
|
21
|
+
expect(Huck.run :config_file => file).not_to be_empty
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should raise if a non-string is generated' do
|
25
|
+
expect { Huck.run { 0 } }.to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'running the server' do
|
31
|
+
before(:each) do
|
32
|
+
receiver = double
|
33
|
+
expect(receiver).to receive(:accept).once
|
34
|
+
allow(Huck::Receiver).to receive(:factory).and_return(receiver)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should accept config as a hash' do
|
38
|
+
config = {'receiver' => 'sqs', 'handlers' => ['echo']}
|
39
|
+
Huck.serve :config => config
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should read a config file' do
|
43
|
+
file = mktempfile :content => <<EOF
|
44
|
+
receiver: sqs
|
45
|
+
handlers:
|
46
|
+
- echo
|
47
|
+
EOF
|
48
|
+
Huck.serve :config_file => file
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'getting receiver instances' do
|
4
|
+
it 'should return the sqs receiver' do
|
5
|
+
expect(Huck::Receiver::factory :name => 'sqs').to(
|
6
|
+
be_a Huck::Receivers::SQSReceiver)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return the rabbitmq receiver' do
|
10
|
+
expect(Huck::Receiver::factory :name => 'rabbitmq').to(
|
11
|
+
be_a Huck::Receivers::RabbitMQReceiver)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should raise on invalid receiver' do
|
15
|
+
expect { Huck::Receiver::factory :name => 'bad' }.to raise_error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'accepting messages from queues' do
|
20
|
+
it 'should accept a message and hand it to the handler' do
|
21
|
+
h = double
|
22
|
+
allow(h).to receive(:handle)
|
23
|
+
r = Huck::Receiver::factory :name => 'sqs'
|
24
|
+
allow(r).to receive(:receive).and_yield('test')
|
25
|
+
r.accept [h], nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should dump an error message on handler error' do
|
29
|
+
h = double
|
30
|
+
expect(STDOUT).to receive(:puts).with('Handler error (RSpec::Mocks::Double): RuntimeError')
|
31
|
+
allow(h).to receive(:handle).and_raise(RuntimeError)
|
32
|
+
r = Huck::Receiver::factory :name => 'sqs'
|
33
|
+
allow(r).to receive(:receive).and_yield('test')
|
34
|
+
r.accept [h], nil
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'sqs receiver' do
|
4
|
+
before(:each) do
|
5
|
+
allow(Huck).to receive(:must_load)
|
6
|
+
sqs = double
|
7
|
+
queues = double
|
8
|
+
allow(sqs).to receive(:queues).and_return(queues)
|
9
|
+
queue = double
|
10
|
+
msg = double(:body => 'test')
|
11
|
+
allow(queue).to receive(:poll).and_yield(msg)
|
12
|
+
allow(queues).to receive(:create).with('q').and_return(queue)
|
13
|
+
allow(AWS::SQS).to receive(:new).with(
|
14
|
+
:access_key_id => 'i',
|
15
|
+
:secret_access_key => 's',
|
16
|
+
:region => 'r'
|
17
|
+
).and_return(sqs)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should raise if no sqs config provided' do
|
21
|
+
r = Huck::Receiver::factory :name => 'sqs', :config => {}
|
22
|
+
expect { r.receive }.to raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should raise if not all required config provided' do
|
26
|
+
config = {'sqs' => {'access_key_id' => 'test', 'region' => 'test'}}
|
27
|
+
r = Huck::Receiver::factory :name => 'sqs', :config => config
|
28
|
+
expect { r.receive }.to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should call the aws sdk to poll messages' do
|
32
|
+
config = {'sqs' => {'access_key_id' => 'i', 'region' => 'r',
|
33
|
+
'secret_access_key' => 's', 'queue_name' => 'q'}}
|
34
|
+
r = Huck::Receiver::factory :name => 'sqs', :config => config
|
35
|
+
expect { |b| r.receive(&b) }.to yield_with_args('test')
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'getting sender instances' do
|
4
|
+
it 'should return the sqs sender' do
|
5
|
+
expect(Huck::Sender::factory :name => 'sqs').to(
|
6
|
+
be_a Huck::Senders::SQSSender)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return the rabbitmq sender' do
|
10
|
+
expect(Huck::Sender::factory :name => 'rabbitmq').to(
|
11
|
+
be_a Huck::Senders::RabbitMQSender)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should raise on invalid sender' do
|
15
|
+
expect { Huck::Sender::factory :name => 'bad' }.to raise_error
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'sqs sender' do
|
4
|
+
before(:each) do
|
5
|
+
allow(Huck).to receive(:must_load)
|
6
|
+
sqs = double
|
7
|
+
queues = double
|
8
|
+
allow(sqs).to receive(:queues).and_return(queues)
|
9
|
+
queue = double
|
10
|
+
allow(queue).to receive(:send_message).with('test')
|
11
|
+
allow(queues).to receive(:create).with('q').and_return(queue)
|
12
|
+
allow(AWS::SQS).to receive(:new).with(
|
13
|
+
:access_key_id => 'i',
|
14
|
+
:secret_access_key => 's',
|
15
|
+
:region => 'r'
|
16
|
+
).and_return(sqs)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should raise if no sqs config provided' do
|
20
|
+
s = Huck::Sender::factory :name => 'sqs', :config => {}
|
21
|
+
expect { s.send 'test' }.to raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should raise if not all required config provided' do
|
25
|
+
config = {'sqs' => {'access_key_id' => 'test', 'region' => 'test'}}
|
26
|
+
s = Huck::Sender::factory :name => 'sqs', :config => config
|
27
|
+
expect { s.send 'test' }.to raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should call the aws sdk to send a message' do
|
31
|
+
config = {'sqs' => {'access_key_id' => 'i', 'region' => 'r',
|
32
|
+
'secret_access_key' => 's', 'queue_name' => 'q'}}
|
33
|
+
s = Huck::Sender::factory :name => 'sqs', :config => config
|
34
|
+
s.send 'test'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/spec/huck/util_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe 'Huck Configuration' do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should accept an alternate config file path' do
|
16
|
-
file = mktempfile "test: config\n"
|
16
|
+
file = mktempfile :content => "test: config\n"
|
17
17
|
expect(Huck.config :path => file).to eq({'test' => 'config'})
|
18
18
|
end
|
19
19
|
end
|
@@ -49,4 +49,31 @@ describe 'Data Serialization' do
|
|
49
49
|
output = YAML.dump input
|
50
50
|
expect(Huck::serialize(input, :format => 'yaml')).to eq(output)
|
51
51
|
end
|
52
|
+
|
53
|
+
it 'should raise on unknown format' do
|
54
|
+
expect { Huck::serialize(input, :format => 'bad') }.to raise_error
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'Parsing Providers' do
|
59
|
+
it 'should parse provider hashes correctly' do
|
60
|
+
config = [{'provider1' => {'config1' => 'val1'}}, 'provider2']
|
61
|
+
i = 0
|
62
|
+
Huck::parse_providers config do |name, config|
|
63
|
+
case i
|
64
|
+
when 0
|
65
|
+
expect(name).to eq('provider1')
|
66
|
+
expect(config).to eq({'config1' => 'val1'})
|
67
|
+
when 1
|
68
|
+
expect(name).to eq('provider2')
|
69
|
+
expect(config).to be {}
|
70
|
+
end
|
71
|
+
i += 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should raise an error on incorrect provider config' do
|
76
|
+
expect { Huck::parse_providers nil }.to raise_error
|
77
|
+
expect { Huck::parse_providers [0] }.to raise_error
|
78
|
+
end
|
52
79
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Uber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-mocks
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: simplecov
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,62 @@ dependencies:
|
|
52
66
|
- - '>='
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: facter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ohai
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: aws-sdk
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bunny
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
55
125
|
description: Open-ended information sharing framework
|
56
126
|
email: ru@ryanuber.com
|
57
127
|
executables:
|
@@ -59,26 +129,40 @@ executables:
|
|
59
129
|
extensions: []
|
60
130
|
extra_rdoc_files: []
|
61
131
|
files:
|
62
|
-
-
|
63
|
-
- lib/huck/
|
132
|
+
- lib/huck/generators/ohai.rb
|
133
|
+
- lib/huck/generators/facter.rb
|
64
134
|
- lib/huck/generators/basic.rb
|
65
135
|
- lib/huck/generators/exec.rb
|
66
|
-
- lib/huck/generators/facter.rb
|
67
136
|
- lib/huck/generators/file.rb
|
68
|
-
- lib/huck/
|
69
|
-
- lib/huck/
|
70
|
-
- lib/huck/handlers/echo.rb
|
71
|
-
- lib/huck/handlers/exec.rb
|
137
|
+
- lib/huck/senders/sqs.rb
|
138
|
+
- lib/huck/senders/rabbitmq.rb
|
72
139
|
- lib/huck/receiver.rb
|
73
|
-
- lib/huck/receivers/rabbitmq.rb
|
74
|
-
- lib/huck/receivers/sqs.rb
|
75
140
|
- lib/huck/sender.rb
|
76
|
-
- lib/huck/senders/rabbitmq.rb
|
77
|
-
- lib/huck/senders/sqs.rb
|
78
141
|
- lib/huck/util.rb
|
142
|
+
- lib/huck/generator.rb
|
143
|
+
- lib/huck/receivers/sqs.rb
|
144
|
+
- lib/huck/receivers/rabbitmq.rb
|
145
|
+
- lib/huck/handlers/exec.rb
|
146
|
+
- lib/huck/handlers/echo.rb
|
79
147
|
- lib/huck/version.rb
|
148
|
+
- lib/huck/handler.rb
|
80
149
|
- lib/huck.rb
|
150
|
+
- bin/huck
|
151
|
+
- spec/huck/generators/facter_spec.rb
|
152
|
+
- spec/huck/generators/basic_spec.rb
|
153
|
+
- spec/huck/generators/exec_spec.rb
|
154
|
+
- spec/huck/generators/file_spec.rb
|
155
|
+
- spec/huck/generators/ohai_spec.rb
|
81
156
|
- spec/huck/util_spec.rb
|
157
|
+
- spec/huck/receiver_spec.rb
|
158
|
+
- spec/huck/senders/sqs_spec.rb
|
159
|
+
- spec/huck/huck_spec.rb
|
160
|
+
- spec/huck/sender_spec.rb
|
161
|
+
- spec/huck/handler_spec.rb
|
162
|
+
- spec/huck/receivers/sqs_spec.rb
|
163
|
+
- spec/huck/generator_spec.rb
|
164
|
+
- spec/huck/handlers/echo_spec.rb
|
165
|
+
- spec/huck/handlers/exec_spec.rb
|
82
166
|
- spec/spec_helper.rb
|
83
167
|
homepage: https://github.com/ryanuber/huck
|
84
168
|
licenses:
|
@@ -100,10 +184,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
184
|
version: '0'
|
101
185
|
requirements: []
|
102
186
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.1.11
|
104
188
|
signing_key:
|
105
189
|
specification_version: 4
|
106
190
|
summary: Information sharing framework
|
107
191
|
test_files:
|
192
|
+
- spec/huck/generators/facter_spec.rb
|
193
|
+
- spec/huck/generators/basic_spec.rb
|
194
|
+
- spec/huck/generators/exec_spec.rb
|
195
|
+
- spec/huck/generators/file_spec.rb
|
196
|
+
- spec/huck/generators/ohai_spec.rb
|
108
197
|
- spec/huck/util_spec.rb
|
198
|
+
- spec/huck/receiver_spec.rb
|
199
|
+
- spec/huck/senders/sqs_spec.rb
|
200
|
+
- spec/huck/huck_spec.rb
|
201
|
+
- spec/huck/sender_spec.rb
|
202
|
+
- spec/huck/handler_spec.rb
|
203
|
+
- spec/huck/receivers/sqs_spec.rb
|
204
|
+
- spec/huck/generator_spec.rb
|
205
|
+
- spec/huck/handlers/echo_spec.rb
|
206
|
+
- spec/huck/handlers/exec_spec.rb
|
109
207
|
- spec/spec_helper.rb
|