alephant-harness 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.ruby-version +1 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +7 -0
- data/alephant-harness.gemspec +27 -0
- data/lib/alephant/harness.rb +8 -0
- data/lib/alephant/harness/aws.rb +36 -0
- data/lib/alephant/harness/service/dynamo_db.rb +35 -0
- data/lib/alephant/harness/service/s3.rb +49 -0
- data/lib/alephant/harness/service/sqs.rb +35 -0
- data/lib/alephant/harness/setup.rb +54 -0
- data/lib/alephant/harness/version.rb +5 -0
- data/schema/lookup.yaml +15 -0
- data/schema/sequencer.yaml +21 -0
- data/spec/aws_spec.rb +46 -0
- data/spec/service/dynamo_db_spec.rb +40 -0
- data/spec/service/s3_spec.rb +99 -0
- data/spec/service/sqs_spec.rb +58 -0
- data/spec/spec_helper.rb +9 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 445339854ef761f7192b986877399c3091bfba01
|
4
|
+
data.tar.gz: 5dcfbadaf88e308fae957aa48e430a6cbdf4321f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eecc2c6fea73e390e48c1dd531823cba8bb734a4b827dfcb20c99de4bccc8ff5176213dae3a68931e97ac7b302a28417399c5d78e539179ed0352f2db846787e
|
7
|
+
data.tar.gz: 631312304a8a6be7413f4326d7d701f819d5cca68620ec29600d87cf444f8fd67a6687c91cf28a6a802702b4e1ee7a7fd0d97cedf204093ecd37d4593a85f73d
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
|
24
|
+
#Vim swap
|
25
|
+
*.swp
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-1.7.8
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Steven Jack
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Alephant::Harness
|
2
|
+
|
3
|
+
Provides supporting classes for running the alephant framework locally.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'alephant-harness'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install alephant-harness
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Coming soon
|
22
|
+
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it ( https://github.com/bbc-news/alephant-harness/fork )
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'alephant/harness/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "alephant-harness"
|
8
|
+
spec.version = Alephant::Harness::VERSION
|
9
|
+
spec.authors = ["Steven Jack"]
|
10
|
+
spec.email = ["stevenmajack@gmail.com"]
|
11
|
+
spec.summary = %q{Stuff}
|
12
|
+
spec.description = %q{More Stuff}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "aws-sdk"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module Alephant
|
4
|
+
module Harness
|
5
|
+
module AWS
|
6
|
+
|
7
|
+
def self.configure(environment = nil)
|
8
|
+
|
9
|
+
environment ||= ENV
|
10
|
+
|
11
|
+
::AWS.config(aws_properties_from(environment))
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.aws_properties_from(env)
|
15
|
+
env.inject({}) do |hash, (key, value)|
|
16
|
+
hash.tap do |h|
|
17
|
+
h[config_key(key)] = sanitise_value(value) if key =~ /^AWS_/
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.config_key(original_key)
|
23
|
+
original_key[/AWS_(.*)/,1].downcase.to_sym
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.sanitise_value(value)
|
27
|
+
if %w[ true false ].include?(value)
|
28
|
+
value == 'true'
|
29
|
+
else
|
30
|
+
value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Alephant
|
5
|
+
module Harness
|
6
|
+
module Service
|
7
|
+
module DynamoDB
|
8
|
+
|
9
|
+
def self.client
|
10
|
+
@@client ||= ::AWS::DynamoDB::Client::V20120810.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.create(table_name, schema_name)
|
14
|
+
schema = load_schema(schema_name).tap { |s| s[:table_name] = table_name }
|
15
|
+
client.create_table schema
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.remove(tables)
|
19
|
+
tables.each do |table_name|
|
20
|
+
begin
|
21
|
+
client.delete_table({ :table_name => table_name })
|
22
|
+
rescue Exception => e
|
23
|
+
#If table doesn't exist fail silently
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.load_schema(schema_name)
|
29
|
+
YAML::load_file(File.join([File.dirname(__FILE__), *(%w'..' * 4), 'schema', "#{schema_name}.yaml"]))
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module Alephant
|
4
|
+
module Harness
|
5
|
+
module Service
|
6
|
+
module S3
|
7
|
+
|
8
|
+
def self.client
|
9
|
+
@@client ||= ::AWS::S3.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create(id)
|
13
|
+
client.buckets.create id
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.delete(id)
|
17
|
+
client.buckets[id].tap do |bucket|
|
18
|
+
bucket.objects.each do |object|
|
19
|
+
object.delete
|
20
|
+
end
|
21
|
+
bucket.delete
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.add_object(id, object_id, data)
|
26
|
+
client.buckets[id]
|
27
|
+
.objects[object_id]
|
28
|
+
.write(data)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.get_object(id, object_id)
|
32
|
+
client.buckets[id]
|
33
|
+
.objects[object_id]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.delete_object(id, object_id)
|
37
|
+
get_object(id, object_id).delete
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.exists?(id, object_id)
|
41
|
+
if get_object(id, object_id)
|
42
|
+
yield
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module Alephant
|
4
|
+
module Harness
|
5
|
+
module Service
|
6
|
+
module SQS
|
7
|
+
|
8
|
+
def self.client
|
9
|
+
@@client ||= ::AWS::SQS.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create(queue)
|
13
|
+
client.queues.create /(?<name>[^\/]+)$/.match(queue)[:name]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get(queue_name)
|
17
|
+
client.queues.named(queue_name)
|
18
|
+
rescue ::AWS::SQS::Errors::NonExistentQueue
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.exists?(queue_name)
|
23
|
+
if get(queue_name)
|
24
|
+
yield
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.delete(queue_name)
|
29
|
+
client.queues.named(queue_name).delete
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "alephant/harness/service/dynamo_db"
|
2
|
+
require "alephant/harness/service/s3"
|
3
|
+
require "alephant/harness/service/sqs"
|
4
|
+
require "alephant/harness/aws"
|
5
|
+
|
6
|
+
module Alephant
|
7
|
+
module Harness
|
8
|
+
module Setup
|
9
|
+
|
10
|
+
def self.configure(opts = {}, env = nil)
|
11
|
+
AWS.configure(env)
|
12
|
+
|
13
|
+
queue_name = opts[:sqs_queue_url] and recreate_sqs queue_name
|
14
|
+
bucket = opts[:bucket_id] and recreate_s3 bucket
|
15
|
+
|
16
|
+
tables = {
|
17
|
+
:lookup => opts[:lookup_table_name],
|
18
|
+
:sequencer => opts[:sequencer_table_name],
|
19
|
+
} and recreate_dynamo_db tables
|
20
|
+
|
21
|
+
#recreate_sqs queue_name
|
22
|
+
|
23
|
+
#recreate_s3 bucket
|
24
|
+
|
25
|
+
#recreate_dynamo_db tables
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.recreate_sqs(queue_name)
|
29
|
+
Service::SQS.exists?(queue_name) do
|
30
|
+
Service::SQS.delete(queue_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
Service::SQS.create(queue_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.recreate_s3(bucket)
|
37
|
+
Service::S3.exists?(bucket) do
|
38
|
+
Service::S3.delete(bucket)
|
39
|
+
end
|
40
|
+
|
41
|
+
Service::S3.create(queue_name)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.recreate_dynamo_db(tables)
|
45
|
+
Service::DynamoDB.remove(tables.values)
|
46
|
+
|
47
|
+
tables.each do |schema_name, table_name|
|
48
|
+
Service::DynamoDB.create(table_name, schema_name)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/schema/lookup.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
:attribute_definitions:
|
2
|
+
-
|
3
|
+
:attribute_name: 'key'
|
4
|
+
:attribute_type: 'S'
|
5
|
+
|
6
|
+
:table_name: ''
|
7
|
+
|
8
|
+
:key_schema:
|
9
|
+
-
|
10
|
+
:attribute_name: 'key'
|
11
|
+
:key_type: 'HASH'
|
12
|
+
|
13
|
+
:provisioned_throughput:
|
14
|
+
:read_capacity_units: 10
|
15
|
+
:write_capacity_units: 10
|
@@ -0,0 +1,21 @@
|
|
1
|
+
:attribute_definitions:
|
2
|
+
-
|
3
|
+
:attribute_name: 'batch_version'
|
4
|
+
:attribute_type: 'N'
|
5
|
+
-
|
6
|
+
:attribute_name: 'component_key'
|
7
|
+
:attribute_type: 'S'
|
8
|
+
|
9
|
+
:table_name: ''
|
10
|
+
|
11
|
+
:key_schema:
|
12
|
+
-
|
13
|
+
:attribute_name: 'component_key'
|
14
|
+
:key_type: 'HASH'
|
15
|
+
-
|
16
|
+
:attribute_name: 'batch_version'
|
17
|
+
:key_type: 'RANGE'
|
18
|
+
|
19
|
+
:provisioned_throughput:
|
20
|
+
:read_capacity_units: 10
|
21
|
+
:write_capacity_units: 10
|
data/spec/aws_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alephant::Harness::AWS do
|
4
|
+
|
5
|
+
describe ".configure" do
|
6
|
+
|
7
|
+
it "Configures the AWS global config based on environment variables" do
|
8
|
+
environment = {
|
9
|
+
'AWS_S3_ENDPOINT' => 'localhost',
|
10
|
+
'AWS_S3_PORT' => '4569',
|
11
|
+
'AWS_SQS_ENDPOINT' => 'localhost',
|
12
|
+
'AWS_SQS_PORT' => '4568',
|
13
|
+
'AWS_DYNAMO_DB_ENDPOINT' => 'localhost',
|
14
|
+
'AWS_DYNAMO_DB_PORT' => '4570',
|
15
|
+
'AWS_USE_SSL' => false,
|
16
|
+
'AWS_S3_FORCE_PATH_STYLE' => true,
|
17
|
+
'AWS_ACCESS_KEY_ID' => 'access',
|
18
|
+
'AWS_SECRET_ACCESS_KEY' => 'secret'
|
19
|
+
}
|
20
|
+
|
21
|
+
Alephant::Harness::AWS.configure(environment)
|
22
|
+
|
23
|
+
environment.each do |key, value|
|
24
|
+
key = key[/AWS_(.*)/,1].downcase.to_sym
|
25
|
+
config_value = AWS.config.send(key.to_sym)
|
26
|
+
expect(config_value).to eq(value)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
it "Sanitises boolean values" do
|
32
|
+
environment = {
|
33
|
+
'AWS_USE_SSL' => 'false',
|
34
|
+
'AWS_S3_FORCE_PATH_STYLE' => 'true'
|
35
|
+
}
|
36
|
+
|
37
|
+
Alephant::Harness::AWS.configure(environment)
|
38
|
+
|
39
|
+
expect(AWS.config.use_ssl).to be_falsy
|
40
|
+
expect(AWS.config.s3_force_path_style).to be_truthy
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alephant::Harness::Service::DynamoDB do
|
4
|
+
|
5
|
+
describe ".create" do
|
6
|
+
it "creates a table based off a schema" do
|
7
|
+
|
8
|
+
table_name = 'test_lookup'
|
9
|
+
schema_name = 'lookup'
|
10
|
+
|
11
|
+
expected_schema = YAML::load_file(File.join(File.dirname(__FILE__), *[%w'..' * 2], 'schema', "#{schema_name}.yaml"))
|
12
|
+
expected_schema[:table_name] = table_name
|
13
|
+
|
14
|
+
expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to receive(:create_table).with(expected_schema)
|
15
|
+
subject.create(table_name, schema_name)
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".delete" do
|
21
|
+
let(:tables) { %w(foo bar) }
|
22
|
+
|
23
|
+
context "When tables exist" do
|
24
|
+
it "removes specified tables" do
|
25
|
+
expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to receive(:delete_table).twice
|
26
|
+
subject.remove(tables)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "When tables don't exist" do
|
31
|
+
it "Fails silently" do
|
32
|
+
expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to receive(:delete_table).twice.and_raise(Exception)
|
33
|
+
expect { subject.remove(tables) }.to_not raise_error(Exception)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alephant::Harness::Service::S3 do
|
4
|
+
let(:id) { 'my-bucket' }
|
5
|
+
let(:buckets) { double("AWS::S3::BucketCollection") }
|
6
|
+
let(:bucket) { double("AWS::S3::Bucket") }
|
7
|
+
let(:s3_object) { double("AWS::S3::S3Object") }
|
8
|
+
let(:s3_object_collection) { double('AWS::S3::ObjectCollection') }
|
9
|
+
|
10
|
+
|
11
|
+
describe ".create" do
|
12
|
+
it "creates a bucket" do
|
13
|
+
allow(buckets).to receive(:create).with(id)
|
14
|
+
expect_any_instance_of(AWS::S3).to receive(:buckets).and_return(buckets)
|
15
|
+
subject.create id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".delete(id)" do
|
20
|
+
it "deletes a bucket" do
|
21
|
+
bucket = double('AWS::S3::Bucket', :delete => nil)
|
22
|
+
s3_object = double('AWS::S3::S3Object', :delete => nil)
|
23
|
+
|
24
|
+
allow(buckets).to receive(:[]).with(id).and_return(bucket)
|
25
|
+
allow(bucket).to receive(:objects).and_return([s3_object])
|
26
|
+
|
27
|
+
expect_any_instance_of(AWS::S3).to receive(:buckets).and_return(buckets)
|
28
|
+
subject.delete id
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ".add_object(bucket_id, object_id, data)" do
|
33
|
+
it "adds an object to the bucket" do
|
34
|
+
object_id = 'foo/bar'
|
35
|
+
data = { :some => 'data' }
|
36
|
+
|
37
|
+
allow(buckets).to receive(:[]).with(id).and_return(bucket)
|
38
|
+
allow(bucket).to receive(:objects).and_return(s3_object_collection)
|
39
|
+
allow(s3_object_collection).to receive(:[]).with(object_id).and_return(s3_object)
|
40
|
+
allow(s3_object).to receive(:write).with(data)
|
41
|
+
|
42
|
+
expect_any_instance_of(AWS::S3).to receive(:buckets).and_return(buckets)
|
43
|
+
subject.add_object(id, object_id, data)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".get_object(bucket_id, object_id)" do
|
48
|
+
it "gets an object from the specified bucket" do
|
49
|
+
object_id = 'foo/bar'
|
50
|
+
|
51
|
+
allow(buckets).to receive(:[]).with(id).and_return(bucket)
|
52
|
+
allow(bucket).to receive(:objects).and_return(s3_object_collection)
|
53
|
+
allow(s3_object_collection).to receive(:[]).with(object_id).and_return(s3_object)
|
54
|
+
|
55
|
+
expect_any_instance_of(AWS::S3).to receive(:buckets).and_return(buckets)
|
56
|
+
expect(subject.get_object(id, object_id)).to eq(s3_object)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".delete_object(bucket_id, object_id)" do
|
61
|
+
it "deletes an object from the specified bucket" do
|
62
|
+
object_id = 'foo/bar'
|
63
|
+
|
64
|
+
allow(buckets).to receive(:[]).with(id).and_return(bucket)
|
65
|
+
allow(bucket).to receive(:objects).and_return(s3_object_collection)
|
66
|
+
allow(s3_object_collection).to receive(:[]).with(object_id).and_return(s3_object)
|
67
|
+
allow(s3_object).to receive(:delete)
|
68
|
+
|
69
|
+
expect_any_instance_of(AWS::S3).to receive(:buckets).and_return(buckets)
|
70
|
+
subject.delete_object(id, object_id)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe ".exists?" do
|
75
|
+
context "when queue exists" do
|
76
|
+
it "yields control" do
|
77
|
+
allow_any_instance_of(AWS::S3).to receive(:buckets).and_return(buckets)
|
78
|
+
|
79
|
+
allow(buckets).to receive(:[]).with(id).and_return(bucket)
|
80
|
+
allow(bucket).to receive(:objects).and_return(s3_object_collection)
|
81
|
+
allow(s3_object_collection).to receive(:[]).with(object_id).and_return(s3_object)
|
82
|
+
|
83
|
+
expect { |b| subject.exists?(id, object_id, &b) }.to yield_control
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when queue does not exist" do
|
88
|
+
it "does not yield control" do
|
89
|
+
allow_any_instance_of(AWS::S3).to receive(:buckets).and_return(buckets)
|
90
|
+
|
91
|
+
allow(buckets).to receive(:[]).with(id).and_return(bucket)
|
92
|
+
allow(bucket).to receive(:objects).and_return(s3_object_collection)
|
93
|
+
allow(s3_object_collection).to receive(:[]).with(object_id).and_return(nil)
|
94
|
+
|
95
|
+
expect { |b| subject.exists?(id, object_id, &b) }.to_not yield_control
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alephant::Harness::Service::SQS do
|
4
|
+
|
5
|
+
let(:queue_name) { "queue" }
|
6
|
+
let(:queues) { double("AWS::SQS::QueueCollection") }
|
7
|
+
let(:queue) { double("AWS::SQS::Queue") }
|
8
|
+
|
9
|
+
describe ".create" do
|
10
|
+
it "creates a new queue" do
|
11
|
+
allow(queues).to receive(:create).with(queue_name)
|
12
|
+
|
13
|
+
expect_any_instance_of(AWS::SQS).to receive(:queues).and_return(queues)
|
14
|
+
subject.create queue_name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".delete" do
|
19
|
+
it "deletes a queue" do
|
20
|
+
allow_any_instance_of(AWS::SQS).to receive(:queues).and_return(queues)
|
21
|
+
|
22
|
+
allow(queues).to receive(:named).and_return(queue)
|
23
|
+
|
24
|
+
expect(queue).to receive(:delete)
|
25
|
+
subject.delete queue_name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".get" do
|
30
|
+
it "gets a queue" do
|
31
|
+
allow_any_instance_of(AWS::SQS).to receive(:queues).and_return(queues)
|
32
|
+
allow(queues).to receive(:named).with(queue_name).and_return(queue)
|
33
|
+
|
34
|
+
expect(subject.get queue_name).to eq(queue)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ".exists?" do
|
39
|
+
context "when queue exists" do
|
40
|
+
it "yields control" do
|
41
|
+
allow_any_instance_of(AWS::SQS).to receive(:queues).and_return(queues)
|
42
|
+
allow(queues).to receive(:named).with(queue_name).and_return(queue)
|
43
|
+
|
44
|
+
expect { |b| subject.exists?(queue_name, &b) }.to yield_control
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when queue does not exist" do
|
49
|
+
it "does not yield control" do
|
50
|
+
allow_any_instance_of(AWS::SQS).to receive(:queues).and_return(queues)
|
51
|
+
allow(queues).to receive(:named).with(queue_name).and_return(nil)
|
52
|
+
|
53
|
+
expect { |b| subject.exists?(queue_name, &b) }.to_not yield_control
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
|
3
|
+
require 'pry'
|
4
|
+
require 'alephant/harness'
|
5
|
+
require 'alephant/harness/aws'
|
6
|
+
require 'alephant/harness/service/dynamo_db'
|
7
|
+
require 'alephant/harness/service/s3'
|
8
|
+
require 'alephant/harness/service/sqs'
|
9
|
+
require 'aws-sdk'
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alephant-harness
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steven Jack
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '1.6'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '3'
|
67
|
+
prerelease: false
|
68
|
+
type: :development
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
prerelease: false
|
82
|
+
type: :development
|
83
|
+
description: More Stuff
|
84
|
+
email:
|
85
|
+
- stevenmajack@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .ruby-version
|
92
|
+
- .travis.yml
|
93
|
+
- Gemfile
|
94
|
+
- Guardfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- alephant-harness.gemspec
|
99
|
+
- lib/alephant/harness.rb
|
100
|
+
- lib/alephant/harness/aws.rb
|
101
|
+
- lib/alephant/harness/service/dynamo_db.rb
|
102
|
+
- lib/alephant/harness/service/s3.rb
|
103
|
+
- lib/alephant/harness/service/sqs.rb
|
104
|
+
- lib/alephant/harness/setup.rb
|
105
|
+
- lib/alephant/harness/version.rb
|
106
|
+
- schema/lookup.yaml
|
107
|
+
- schema/sequencer.yaml
|
108
|
+
- spec/aws_spec.rb
|
109
|
+
- spec/service/dynamo_db_spec.rb
|
110
|
+
- spec/service/s3_spec.rb
|
111
|
+
- spec/service/sqs_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
homepage: ''
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.1.9
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Stuff
|
137
|
+
test_files:
|
138
|
+
- spec/aws_spec.rb
|
139
|
+
- spec/service/dynamo_db_spec.rb
|
140
|
+
- spec/service/s3_spec.rb
|
141
|
+
- spec/service/sqs_spec.rb
|
142
|
+
- spec/spec_helper.rb
|