alephant-harness 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69b32c4c3242f203d078c5a7965505fa394f188b
4
- data.tar.gz: 3964b65f56abd6e524c4cd6ecaa20047eb055897
3
+ metadata.gz: 78000956e367b55089f00f64ec5c18f673c77b31
4
+ data.tar.gz: f6eb7f0508515e6fd1882345eabe822045180d01
5
5
  SHA512:
6
- metadata.gz: e2913a3cc82486bea58fd4cfd6f7116adb954157f4e834d4d450275058f25092f51de64de3432bcf1405a785d7cfc248fae0149495099f3048776769537aaadd
7
- data.tar.gz: 123794109826d6b5e8ef1365578a3d393df3a5027fce89d5f321bdc58c0a82c1f3a502ca336d10811eaddd7a7632b887cab830eb6296e233b2365976d6e1a9f7
6
+ metadata.gz: 733e2041639c6927941b0e665dca64bd82874ac182a9bc68837cca36d9ca1d765128225e1e6f309f3079c6cef0f5a83b23b22bd918ef97b1b5f4a11045b90551
7
+ data.tar.gz: c8f3603539932f843e1162a0ef9b123fb5744fcc3b786e2171e5ff5c3fb6678661bdc94c295091b63da00101c42f53c856f776dbdd518770c0372e5300bc1fc8
@@ -1 +1 @@
1
- jruby-1.7.17
1
+ 2.3
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - "2.3"
3
4
  - "jruby"
4
5
  notifications:
5
6
  email:
6
7
  recipients:
7
- - kenoir@gmail.com
8
- - stevenmajack@gmail.com
8
+ - D&ENewsFrameworksTeam@bbc.co.uk
9
9
  on_failure: change
10
10
  on_success: never
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "alephant-harness"
8
8
  spec.version = Alephant::Harness::VERSION
9
9
  spec.authors = ["BBC News"]
10
- spec.email = ["FutureMediaNewsRubyGems@bbc.co.uk"]
10
+ spec.email = ["D&ENewsFrameworksTeam@bbc.co.uk"]
11
11
  spec.summary = %q{Stuff}
12
12
  spec.description = %q{More Stuff}
13
13
  spec.homepage = ""
@@ -18,7 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "aws-sdk", "~> 1.0"
21
+ spec.add_runtime_dependency "aws-sdk-sqs"
22
+ spec.add_runtime_dependency "aws-sdk-s3"
23
+ spec.add_runtime_dependency "aws-sdk-dynamodb"
22
24
 
23
25
  spec.add_development_dependency "bundler", "~> 1.6"
24
26
  spec.add_development_dependency "rake"
@@ -1,36 +1,70 @@
1
- require 'aws-sdk'
1
+ require "aws-sdk-dynamodb"
2
+ require "aws-sdk-s3"
3
+ require "aws-sdk-sqs"
2
4
 
3
5
  module Alephant
4
6
  module Harness
5
7
  module AWS
8
+ class << self
9
+ def environment
10
+ aws_properties_from(@environment || ENV)
11
+ end
6
12
 
7
- def self.configure(environment = nil)
13
+ def config=(environment)
14
+ @environment = environment
15
+ end
8
16
 
9
- environment ||= ENV
17
+ def s3_config
18
+ environment.select do |key, _|
19
+ (ACCESS_CONFIG_KEYS + S3_CONFIG_KEYS).include?(key)
20
+ end.map do |key, value|
21
+ [key.to_s.gsub('s3_', '').to_sym, value]
22
+ end.to_h
23
+ end
10
24
 
11
- ::AWS.config(aws_properties_from(environment))
12
- end
25
+ def sqs_config
26
+ environment.select do |key, _|
27
+ (ACCESS_CONFIG_KEYS + SQS_CONFIG_KEYS).include?(key)
28
+ end.map do |key, value|
29
+ [key.to_s.gsub('sqs_', '').to_sym, value]
30
+ end.to_h
31
+ end
32
+
33
+ def dynamo_config
34
+ environment.select do |key, _|
35
+ (ACCESS_CONFIG_KEYS + DYNAMO_CONFIG_KEYS).include?(key)
36
+ end.map do |key, value|
37
+ [key.to_s.gsub('dynamo_db_', '').to_sym, value]
38
+ end.to_h
39
+ end
13
40
 
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_/
41
+ private
42
+
43
+ ACCESS_CONFIG_KEYS = [:access_key_id, :secret_access_key, :region]
44
+ DYNAMO_CONFIG_KEYS = [:dynamo_db_endpoint]
45
+ S3_CONFIG_KEYS = [:s3_endpoint, :s3_force_path_style]
46
+ SQS_CONFIG_KEYS = [:sqs_endpoint]
47
+
48
+ def aws_properties_from(env)
49
+ env.inject({}) do |hash, (key, value)|
50
+ hash.tap do |h|
51
+ h[config_key(key)] = sanitise_value(value) if key =~ /^AWS_/
52
+ end
18
53
  end
19
54
  end
20
- end
21
55
 
22
- def self.config_key(original_key)
23
- original_key[/AWS_(.*)/,1].downcase.to_sym
24
- end
56
+ def config_key(original_key)
57
+ original_key[/AWS_(.*)/,1].downcase.to_sym
58
+ end
25
59
 
26
- def self.sanitise_value(value)
27
- if %w[ true false ].include?(value)
28
- value == 'true'
29
- else
30
- value
60
+ def sanitise_value(value)
61
+ if %w[ true false ].include?(value)
62
+ value == 'true'
63
+ else
64
+ value
65
+ end
31
66
  end
32
67
  end
33
-
34
68
  end
35
69
  end
36
70
  end
@@ -1,31 +1,30 @@
1
- require 'aws-sdk'
1
+ require "aws-sdk-dynamodb"
2
2
  require 'yaml'
3
3
 
4
4
  module Alephant
5
5
  module Harness
6
6
  module Service
7
7
  module DynamoDB
8
-
9
- def self.client
10
- @@client ||= ::AWS::DynamoDB::Client::V20120810.new
11
- end
12
-
13
8
  def self.create(table_name, schema)
14
9
  schema.tap { |s| s[:table_name] = table_name }
15
- client.create_table schema
10
+ client.create_table(schema)
16
11
  end
17
12
 
18
13
  def self.remove(table_name)
19
14
  client.delete_table({ :table_name => table_name })
20
- rescue Exception => e
21
- #If table doesn't exist fail silently
15
+ rescue Aws::DynamoDB::Errors::ResourceNotFoundException => e
16
+ # If table doesn't exist fail silently
22
17
  end
23
18
 
24
-
25
19
  def self.load_schema(schema_name)
26
20
  YAML::load_file(File.join([File.dirname(__FILE__), *(%w'..' * 4), 'schema', "#{schema_name}.yaml"]))
27
21
  end
28
22
 
23
+ private
24
+
25
+ def self.client
26
+ @@client ||= ::Aws::DynamoDB::Client.new(AWS.dynamo_config)
27
+ end
29
28
  end
30
29
  end
31
30
  end
@@ -1,60 +1,50 @@
1
- require 'aws-sdk'
1
+ require "aws-sdk-s3"
2
2
 
3
3
  module Alephant
4
4
  module Harness
5
5
  module Service
6
6
  module S3
7
-
8
- def self.client
9
- @@client ||= ::AWS::S3.new
10
- end
11
-
12
7
  def self.create(id)
13
- client.buckets.create id
8
+ client.create_bucket(bucket: id)
14
9
  end
15
10
 
16
11
  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
12
+ s3 = Aws::S3::Resource.new(client: client)
13
+ s3.bucket(id).delete
23
14
  end
24
15
 
25
16
  def self.add_object(id, object_id, data)
26
- client.buckets[id]
27
- .objects[object_id]
28
- .write(data)
17
+ client.put_object(
18
+ body: data,
19
+ bucket: id,
20
+ key: object_id
21
+ )
29
22
  end
30
23
 
31
24
  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
25
+ client.get_object(
26
+ bucket: id,
27
+ key: object_id
28
+ )
38
29
  end
39
30
 
40
31
  def self.bucket_exists?(bucket_id)
41
32
  begin
42
- exists = client.buckets[bucket_id].exists?
43
- rescue ::AWS::S3::Errors::NoSuchKey => e
44
- exists = false
45
- end
46
-
47
- exists.tap do |e|
48
- yield if e && block_given?
33
+ client.head_bucket(
34
+ bucket: bucket_id
35
+ )
36
+ yield if block_given?
37
+ true
38
+ rescue => e
39
+ false
49
40
  end
50
41
  end
51
42
 
52
- def self.exists?(id, object_id)
53
- if get_object(id, object_id)
54
- yield
55
- end
56
- end
43
+ private
57
44
 
45
+ def self.client
46
+ @client ||= ::Aws::S3::Client.new(AWS.s3_config)
47
+ end
58
48
  end
59
49
  end
60
50
  end
@@ -1,38 +1,39 @@
1
- require 'aws-sdk'
1
+ require "aws-sdk-sqs"
2
2
 
3
3
  module Alephant
4
4
  module Harness
5
5
  module Service
6
6
  module SQS
7
+ class << self
8
+ def create(queue_name)
9
+ client.create_queue(queue_name: queue_name)
10
+ end
7
11
 
8
- def self.client
9
- @@client ||= ::AWS::SQS.new
10
- end
12
+ def exists?(queue_name)
13
+ if get_queue_url(queue_name)
14
+ yield
15
+ end
16
+ end
11
17
 
12
- def self.create(queue)
13
- client.queues.create queue_name(queue)
14
- end
18
+ def delete(queue_name)
19
+ # @TODO: queue url not returned
20
+ queue_url = client.get_queue_url(queue_name: queue_name).queue_url
21
+ queue_url = 'http://www.bbc.co.uk/news'
22
+ client.delete_queue(queue_url: queue_url)
23
+ end
15
24
 
16
- def self.get(queue)
17
- client.queues.named(queue_name(queue))
18
- rescue ::AWS::SQS::Errors::NonExistentQueue
19
- false
20
- end
25
+ private
21
26
 
22
- def self.exists?(queue_name)
23
- if get(queue_name)
24
- yield
27
+ def client
28
+ @@client ||= ::Aws::SQS::Client.new(AWS.sqs_config)
25
29
  end
26
- end
27
-
28
- def self.delete(queue_name)
29
- get(queue_name).delete
30
- end
31
30
 
32
- def self.queue_name(queue)
33
- /(?<name>[^\/]+)$/.match(queue)[:name]
31
+ def get_queue_url(queue_name)
32
+ client.get_queue_url(queue_name: queue_name).queue_url
33
+ rescue ::Aws::SQS::Errors::NonExistentQueue
34
+ false
35
+ end
34
36
  end
35
-
36
37
  end
37
38
  end
38
39
  end
@@ -13,7 +13,7 @@ module Alephant
13
13
  end
14
14
 
15
15
  def self.configure(opts = {}, env = nil)
16
- AWS.configure(env)
16
+ AWS.config = env
17
17
 
18
18
  unless opts[:queues].nil?
19
19
  logger.info "Adding #{opts[:queues].length} queue(s)"
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Harness
3
- VERSION = "0.2.2"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -1,11 +1,65 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Alephant::Harness::AWS do
4
+ describe '.environment' do
5
+ it 'returns environment variables' do
6
+ ENV['AWS_FOO'] = 'BAR'
4
7
 
5
- describe ".configure" do
8
+ expect(subject.environment[:foo]).to eq('BAR')
9
+ end
10
+
11
+ it 'sanitises boolean values when false' do
12
+ subject.config = {'AWS_USE_SSL' => 'false'}
13
+
14
+ expect(subject.environment[:use_ssl]).to eq(false)
15
+ end
16
+
17
+ it 'sanitises boolean values when true' do
18
+ subject.config = {'AWS_USE_SSL' => 'true'}
19
+
20
+ expect(subject.environment[:use_ssl]).to eq(true)
21
+ end
22
+
23
+ it 'ignores keys not starting with AWS' do
24
+ subject.config = {'CONFIG_KEY' => 'value'}
25
+
26
+ expect(subject.environment).to_not have_key(:config_key)
27
+ expect(subject.environment).to_not have_key(:aws_config_key)
28
+ expect(subject.environment).to_not have_key(:AWS_CONFIG_KEY)
29
+ expect(subject.environment).to_not have_key('AWS_CONFIG_KEY')
30
+ end
31
+
32
+ it 'kepps boolean values when true' do
33
+ subject.config = {'AWS_USE_SSL' => true}
34
+
35
+ expect(subject.environment[:use_ssl]).to eq(true)
36
+ end
37
+
38
+ it 'kepps boolean values when false' do
39
+ subject.config = {'AWS_USE_SSL' => false}
6
40
 
7
- it "Configures the AWS global config based on environment variables" do
8
- environment = {
41
+ expect(subject.environment[:use_ssl]).to eq(false)
42
+ end
43
+ end
44
+
45
+ describe '.config' do
46
+ it 'sets config overriding environment variables' do
47
+ subject.config = {'AWS_FOO': 'BAR2'}
48
+
49
+ expect(subject.environment).to include(foo: 'BAR2')
50
+ end
51
+
52
+ it 'sets config overriding existing environment variables' do
53
+ ENV['FOO'] = 'BAR3'
54
+ subject.config = {'AWS_FOO': 'BAZ'}
55
+
56
+ expect(subject.environment).to include(foo: 'BAZ')
57
+ end
58
+ end
59
+
60
+ describe '.s3_config' do
61
+ before do
62
+ subject.config = {
9
63
  'AWS_S3_ENDPOINT' => 'localhost',
10
64
  'AWS_S3_PORT' => '4569',
11
65
  'AWS_SQS_ENDPOINT' => 'localhost',
@@ -15,32 +69,57 @@ describe Alephant::Harness::AWS do
15
69
  'AWS_USE_SSL' => false,
16
70
  'AWS_S3_FORCE_PATH_STYLE' => true,
17
71
  'AWS_ACCESS_KEY_ID' => 'access',
18
- 'AWS_SECRET_ACCESS_KEY' => 'secret'
72
+ 'AWS_SECRET_ACCESS_KEY' => 'secret',
73
+ 'AWS_REGION' => 'eu-west-1'
19
74
  }
75
+ end
20
76
 
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
-
77
+ it 'should filter to necessary S3 keys' do
78
+ expect(subject.s3_config.keys).to eq([:endpoint, :force_path_style, :access_key_id, :secret_access_key, :region])
29
79
  end
80
+ end
30
81
 
31
- it "Sanitises boolean values" do
32
- environment = {
33
- 'AWS_USE_SSL' => 'false',
34
- 'AWS_S3_FORCE_PATH_STYLE' => 'true'
82
+ describe '.sqs_config' do
83
+ before do
84
+ subject.config = {
85
+ 'AWS_S3_ENDPOINT' => 'localhost',
86
+ 'AWS_S3_PORT' => '4569',
87
+ 'AWS_SQS_ENDPOINT' => 'localhost',
88
+ 'AWS_SQS_PORT' => '4568',
89
+ 'AWS_DYNAMO_DB_ENDPOINT' => 'localhost',
90
+ 'AWS_DYNAMO_DB_PORT' => '4570',
91
+ 'AWS_USE_SSL' => false,
92
+ 'AWS_S3_FORCE_PATH_STYLE' => true,
93
+ 'AWS_ACCESS_KEY_ID' => 'access',
94
+ 'AWS_SECRET_ACCESS_KEY' => 'secret',
95
+ 'AWS_REGION' => 'eu-west-1'
35
96
  }
97
+ end
36
98
 
37
- Alephant::Harness::AWS.configure(environment)
99
+ it 'should filter to necessary SQS keys' do
100
+ expect(subject.sqs_config.keys).to eq([:endpoint, :access_key_id, :secret_access_key, :region])
101
+ end
102
+ end
38
103
 
39
- expect(AWS.config.use_ssl).to be_falsy
40
- expect(AWS.config.s3_force_path_style).to be_truthy
104
+ describe '.dynamo_config' do
105
+ before do
106
+ subject.config = {
107
+ 'AWS_S3_ENDPOINT' => 'localhost',
108
+ 'AWS_S3_PORT' => '4569',
109
+ 'AWS_SQS_ENDPOINT' => 'localhost',
110
+ 'AWS_SQS_PORT' => '4568',
111
+ 'AWS_DYNAMO_DB_ENDPOINT' => 'localhost',
112
+ 'AWS_DYNAMO_DB_PORT' => '4570',
113
+ 'AWS_USE_SSL' => false,
114
+ 'AWS_S3_FORCE_PATH_STYLE' => true,
115
+ 'AWS_ACCESS_KEY_ID' => 'access',
116
+ 'AWS_SECRET_ACCESS_KEY' => 'secret',
117
+ 'AWS_REGION' => 'eu-west-1'
118
+ }
41
119
  end
42
120
 
121
+ it 'should filter to necessary DynamoDB keys' do
122
+ expect(subject.dynamo_config.keys).to eq([:endpoint, :access_key_id, :secret_access_key, :region])
123
+ end
43
124
  end
44
125
  end
45
-
46
-
@@ -2,6 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe Alephant::Harness::Service::DynamoDB do
4
4
 
5
+ let(:fake_client) { Aws::DynamoDB::Client.new(stub_responses: true) }
6
+
7
+ before do
8
+ allow(subject).to receive(:client).and_return(fake_client)
9
+ end
10
+
5
11
  describe ".create" do
6
12
  it "creates a table based off a schema" do
7
13
 
@@ -12,9 +18,7 @@ describe Alephant::Harness::Service::DynamoDB do
12
18
  expected_schema = YAML::load_file(File.join(File.dirname(__FILE__), *[%w'..' * 2], 'schema', "#{schema_name}.yaml"))
13
19
  expected_schema[:table_name] = table_name
14
20
 
15
- expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to receive(:create_table).with(expected_schema)
16
- subject.create(table_name, schema)
17
-
21
+ expect(subject.create(table_name, schema).data).to be_a(Aws::DynamoDB::Types::CreateTableOutput)
18
22
  end
19
23
  end
20
24
 
@@ -23,21 +27,18 @@ describe Alephant::Harness::Service::DynamoDB do
23
27
 
24
28
  context "When tables exist" do
25
29
  it "removes specified tables" do
26
- expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to receive(:delete_table).twice
27
30
  tables.each do |table|
28
- subject.remove(table)
31
+ expect(subject.remove(table).data).to be_a(Aws::DynamoDB::Types::DeleteTableOutput)
29
32
  end
30
33
  end
31
34
  end
32
35
 
33
36
  context "When tables don't exist" do
34
37
  it "Fails silently" do
35
- expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to receive(:delete_table).and_raise(Exception)
38
+ fake_client.stub_responses(:delete_table, 'ResourceNotFoundException')
36
39
  expect { subject.remove('blah') }.to_not raise_error(Exception)
37
40
  end
38
41
  end
39
-
40
42
  end
41
-
42
43
  end
43
44
 
@@ -2,45 +2,30 @@ require 'spec_helper'
2
2
 
3
3
  describe Alephant::Harness::Service::S3 do
4
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') }
5
+ let(:fake_client) { Aws::S3::Client.new(stub_responses: true) }
9
6
 
7
+ before do
8
+ allow(subject).to receive(:client).and_return(fake_client)
9
+ end
10
10
 
11
11
  describe ".create" do
12
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
13
+ expect(subject.create(id).data).to be_a(Aws::S3::Types::CreateBucketOutput)
16
14
  end
17
15
  end
18
16
 
19
17
  describe ".delete(id)" do
20
18
  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
19
+ expect(subject.delete(id)).to be_a(Aws::EmptyStructure)
29
20
  end
30
21
  end
31
22
 
32
23
  describe ".add_object(bucket_id, object_id, data)" do
33
24
  it "adds an object to the bucket" do
34
25
  object_id = 'foo/bar'
35
- data = { :some => 'data' }
26
+ data = 'Some data'
36
27
 
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)
28
+ expect(subject.add_object(id, object_id, data).data).to be_a(Aws::S3::Types::PutObjectOutput)
44
29
  end
45
30
  end
46
31
 
@@ -48,72 +33,39 @@ describe Alephant::Harness::Service::S3 do
48
33
  it "gets an object from the specified bucket" do
49
34
  object_id = 'foo/bar'
50
35
 
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)
36
+ expect(subject.get_object(id, object_id).data).to be_a(Aws::S3::Types::GetObjectOutput)
71
37
  end
72
38
  end
73
39
 
74
40
  describe ".bucket_exists?" do
75
- before(:each) do
76
- allow_any_instance_of(AWS::S3).to receive(:buckets).and_return(buckets)
77
- allow(buckets).to receive(:[]).with(id).and_return(bucket)
78
- end
79
-
80
41
  context "when bucket exists" do
81
- it "yields control" do
82
- allow(bucket).to receive(:exists?).and_return(true)
83
- expect { |b| subject.bucket_exists?(id, &b) }.to yield_control
42
+ context 'with block' do
43
+ it 'should call block' do
44
+ expect { |b| subject.bucket_exists?(id, &b) }.to yield_control
45
+ end
84
46
  end
85
- end
86
47
 
87
- context "when bucket does not exist" do
88
- it "does not yield control" do
89
- allow(bucket).to receive(:exists?).and_return(false)
90
- expect { |b| subject.bucket_exists?(id, &b) }.to_not yield_control
48
+ context 'with no block' do
49
+ it 'should return true' do
50
+ fake_client.stub_data(:head_bucket, {})
51
+ expect(subject.bucket_exists?(id)).to eq(true)
52
+ end
91
53
  end
92
54
  end
93
- end
94
-
95
- describe ".exists?" do
96
- context "when queue exists" do
97
- it "yields control" do
98
- allow_any_instance_of(AWS::S3).to receive(:buckets).and_return(buckets)
99
55
 
100
- allow(buckets).to receive(:[]).with(id).and_return(bucket)
101
- allow(bucket).to receive(:objects).and_return(s3_object_collection)
102
- allow(s3_object_collection).to receive(:[]).with(object_id).and_return(s3_object)
103
-
104
- expect { |b| subject.exists?(id, object_id, &b) }.to yield_control
56
+ context "when bucket does not exist" do
57
+ context 'with block' do
58
+ it 'should not call block' do
59
+ fake_client.stub_responses(:head_bucket, Aws::EmptyStructure)
60
+ expect { |b| subject.bucket_exists?(id, &b) }.to_not yield_control
61
+ end
105
62
  end
106
- end
107
-
108
- context "when queue does not exist" do
109
- it "does not yield control" do
110
- allow_any_instance_of(AWS::S3).to receive(:buckets).and_return(buckets)
111
-
112
- allow(buckets).to receive(:[]).with(id).and_return(bucket)
113
- allow(bucket).to receive(:objects).and_return(s3_object_collection)
114
- allow(s3_object_collection).to receive(:[]).with(object_id).and_return(nil)
115
63
 
116
- expect { |b| subject.exists?(id, object_id, &b) }.to_not yield_control
64
+ context 'with no block' do
65
+ it 'should return false' do
66
+ fake_client.stub_responses(:head_bucket, Aws::EmptyStructure)
67
+ expect(subject.bucket_exists?(id)).to eq(false)
68
+ end
117
69
  end
118
70
  end
119
71
  end
@@ -3,43 +3,33 @@ require 'spec_helper'
3
3
  describe Alephant::Harness::Service::SQS do
4
4
 
5
5
  let(:queue_name) { "queue" }
6
- let(:queues) { double("AWS::SQS::QueueCollection") }
7
- let(:queue) { double("AWS::SQS::Queue") }
6
+ let(:fake_client) { Aws::SQS::Client.new(stub_responses: true) }
7
+
8
+ before do
9
+ allow(subject).to receive(:client).and_return(fake_client)
10
+ end
8
11
 
9
12
  describe ".create" do
10
- it "creates a new queue" do
11
- allow(queues).to receive(:create).with(queue_name)
13
+ it "creates a Aws::SQS::Types::CreateQueueResult" do
14
+ fake_client.stub_data(:create_queue)
12
15
 
13
- expect_any_instance_of(AWS::SQS).to receive(:queues).and_return(queues)
14
- subject.create queue_name
16
+ expect(subject.create(queue_name).data).to be_a(Aws::SQS::Types::CreateQueueResult)
15
17
  end
16
18
  end
17
19
 
18
20
  describe ".delete" do
19
21
  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
22
+ fake_client.stub_data(:get_queue_url, { queue_url: 'http://sqs.aws.myqueue/id' })
23
+ fake_client.stub_data(:delete_queue)
28
24
 
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)
25
+ expect(subject.delete(queue_name).data).to be_a(Aws::EmptyStructure)
35
26
  end
36
27
  end
37
28
 
38
29
  describe ".exists?" do
39
30
  context "when queue exists" do
40
31
  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)
32
+ fake_client.stub_data(:get_queue_url, { queue_url: 'http://sqs.aws.myqueue/id' })
43
33
 
44
34
  expect { |b| subject.exists?(queue_name, &b) }.to yield_control
45
35
  end
@@ -47,12 +37,10 @@ describe Alephant::Harness::Service::SQS do
47
37
 
48
38
  context "when queue does not exist" do
49
39
  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)
40
+ fake_client.stub_responses(:get_queue_url, 'NonExistentQueue')
52
41
 
53
42
  expect { |b| subject.exists?(queue_name, &b) }.to_not yield_control
54
43
  end
55
44
  end
56
45
  end
57
-
58
46
  end
@@ -6,4 +6,6 @@ require 'alephant/harness/aws'
6
6
  require 'alephant/harness/service/dynamo_db'
7
7
  require 'alephant/harness/service/s3'
8
8
  require 'alephant/harness/service/sqs'
9
- require 'aws-sdk'
9
+ require "aws-sdk-dynamodb"
10
+ require "aws-sdk-s3"
11
+ require "aws-sdk-sqs"
metadata CHANGED
@@ -1,95 +1,123 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-harness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BBC News
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-11 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-sqs
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - ~>
17
+ - - ">="
17
18
  - !ruby/object:Gem::Version
18
- version: '1.0'
19
- name: aws-sdk
19
+ version: '0'
20
+ type: :runtime
20
21
  prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-s3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
21
34
  type: :runtime
35
+ prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ~>
38
+ - - ">="
25
39
  - !ruby/object:Gem::Version
26
- version: '1.0'
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-dynamodb
28
43
  requirement: !ruby/object:Gem::Requirement
29
44
  requirements:
30
- - - ~>
45
+ - - ">="
31
46
  - !ruby/object:Gem::Version
32
- version: '1.6'
33
- name: bundler
47
+ version: '0'
48
+ type: :runtime
34
49
  prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
35
62
  type: :development
63
+ prerelease: false
36
64
  version_requirements: !ruby/object:Gem::Requirement
37
65
  requirements:
38
- - - ~>
66
+ - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '1.6'
41
69
  - !ruby/object:Gem::Dependency
70
+ name: rake
42
71
  requirement: !ruby/object:Gem::Requirement
43
72
  requirements:
44
- - - '>='
73
+ - - ">="
45
74
  - !ruby/object:Gem::Version
46
75
  version: '0'
47
- name: rake
48
- prerelease: false
49
76
  type: :development
77
+ prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - '>='
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
83
  - !ruby/object:Gem::Dependency
84
+ name: rspec
56
85
  requirement: !ruby/object:Gem::Requirement
57
86
  requirements:
58
- - - ~>
87
+ - - "~>"
59
88
  - !ruby/object:Gem::Version
60
89
  version: '3'
61
- name: rspec
62
- prerelease: false
63
90
  type: :development
91
+ prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - ~>
94
+ - - "~>"
67
95
  - !ruby/object:Gem::Version
68
96
  version: '3'
69
97
  - !ruby/object:Gem::Dependency
98
+ name: pry
70
99
  requirement: !ruby/object:Gem::Requirement
71
100
  requirements:
72
- - - '>='
101
+ - - ">="
73
102
  - !ruby/object:Gem::Version
74
103
  version: '0'
75
- name: pry
76
- prerelease: false
77
104
  type: :development
105
+ prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - '>='
108
+ - - ">="
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
111
  description: More Stuff
84
112
  email:
85
- - FutureMediaNewsRubyGems@bbc.co.uk
113
+ - D&ENewsFrameworksTeam@bbc.co.uk
86
114
  executables: []
87
115
  extensions: []
88
116
  extra_rdoc_files: []
89
117
  files:
90
- - .gitignore
91
- - .ruby-version
92
- - .travis.yml
118
+ - ".gitignore"
119
+ - ".ruby-version"
120
+ - ".travis.yml"
93
121
  - Gemfile
94
122
  - Guardfile
95
123
  - LICENSE.txt
@@ -114,24 +142,24 @@ homepage: ''
114
142
  licenses:
115
143
  - MIT
116
144
  metadata: {}
117
- post_install_message:
145
+ post_install_message:
118
146
  rdoc_options: []
119
147
  require_paths:
120
148
  - lib
121
149
  required_ruby_version: !ruby/object:Gem::Requirement
122
150
  requirements:
123
- - - '>='
151
+ - - ">="
124
152
  - !ruby/object:Gem::Version
125
153
  version: '0'
126
154
  required_rubygems_version: !ruby/object:Gem::Requirement
127
155
  requirements:
128
- - - '>='
156
+ - - ">="
129
157
  - !ruby/object:Gem::Version
130
158
  version: '0'
131
159
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.1.9
134
- signing_key:
160
+ rubyforge_project:
161
+ rubygems_version: 2.6.12
162
+ signing_key:
135
163
  specification_version: 4
136
164
  summary: Stuff
137
165
  test_files: