outliers 0.3.3 → 0.5.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +21 -17
- data/lib/outliers/{credentials.rb → account.rb} +4 -4
- data/lib/outliers/cli/process.rb +53 -15
- data/lib/outliers/cli.rb +1 -1
- data/lib/outliers/collection.rb +24 -18
- data/lib/outliers/evaluation.rb +60 -32
- data/lib/outliers/exceptions.rb +10 -1
- data/lib/outliers/filters/aws/ec2/tags.rb +2 -2
- data/lib/outliers/handlers/json.rb +36 -0
- data/lib/outliers/handlers/outliers_api.rb +62 -0
- data/lib/outliers/handlers.rb +1 -0
- data/lib/outliers/provider.rb +7 -7
- data/lib/outliers/resources/aws/ec2/instance.rb +1 -1
- data/lib/outliers/resources/aws/elb/load_balancer.rb +1 -1
- data/lib/outliers/resources/aws/rds/db_instance.rb +1 -1
- data/lib/outliers/resources/aws/s3/bucket_collection.rb +1 -1
- data/lib/outliers/result.rb +32 -8
- data/lib/outliers/run.rb +9 -3
- data/lib/outliers/verifications/shared.rb +2 -2
- data/lib/outliers/version.rb +1 -1
- data/lib/outliers.rb +2 -1
- data/outliers.gemspec +1 -1
- data/reference.yaml +10 -10
- data/shared.yaml +1 -1
- data/spec/{credentials_spec.rb → account_spec.rb} +7 -7
- data/spec/collection_spec.rb +48 -7
- data/spec/evaluation_spec.rb +109 -47
- data/spec/fixtures/{credentials1.yml → account1.yml} +1 -1
- data/spec/fixtures/{credentials2.yml → account2.yml} +1 -1
- data/spec/handlers/outliers_api_spec.rb +61 -0
- data/spec/info_spec.rb +2 -2
- data/spec/provider_spec.rb +9 -9
- data/spec/results_spec.rb +65 -16
- data/spec/run_spec.rb +4 -4
- data/spec/spec_helper.rb +3 -3
- data/spec/verifications/shared_spec.rb +3 -3
- metadata +18 -13
data/lib/outliers/provider.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Outliers
|
2
2
|
class Provider
|
3
3
|
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :account
|
5
5
|
|
6
|
-
def self.connect_to(
|
7
|
-
provider =
|
8
|
-
Outliers::Providers.name_map.fetch(provider).new
|
6
|
+
def self.connect_to(account)
|
7
|
+
provider = account.fetch 'provider'
|
8
|
+
Outliers::Providers.name_map.fetch(provider).new account
|
9
9
|
rescue KeyError
|
10
10
|
raise Outliers::Exceptions::UnknownProvider.new "Unkown provider '#{provider.join('_').downcase}'."
|
11
11
|
end
|
@@ -14,10 +14,10 @@ module Outliers
|
|
14
14
|
(self.to_s.split('::') - ['Outliers', 'Providers']).map { |p| p.underscore }.join('_').downcase
|
15
15
|
end
|
16
16
|
|
17
|
-
def initialize(
|
18
|
-
@
|
17
|
+
def initialize(account)
|
18
|
+
@account = account
|
19
19
|
@logger = Outliers.logger
|
20
|
-
settings
|
20
|
+
settings account.keys_to_sym
|
21
21
|
end
|
22
22
|
|
23
23
|
def logger
|
@@ -5,7 +5,7 @@ module Outliers
|
|
5
5
|
class BucketCollection < Collection
|
6
6
|
|
7
7
|
def load_all
|
8
|
-
unless provider.
|
8
|
+
unless provider.account['region'] == 'us-east-1'
|
9
9
|
raise Exceptions::UnsupportedRegion.new "Bucket verifications must target region us-east-1."
|
10
10
|
end
|
11
11
|
connect.buckets.map {|r| resource_class.new r}
|
data/lib/outliers/result.rb
CHANGED
@@ -1,18 +1,34 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Outliers
|
2
4
|
class Result
|
3
5
|
|
4
|
-
attr_reader :
|
6
|
+
attr_reader :account_name, :arguments, :failing_resources, :name, :passing_resources,
|
7
|
+
:provider_name, :resource_name, :verification_name
|
8
|
+
|
9
|
+
def to_json
|
10
|
+
to_hash.to_json
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_hash
|
14
|
+
{ 'account_name' => account_name,
|
15
|
+
'arguments' => arguments,
|
16
|
+
'name' => name,
|
17
|
+
'provider_name' => provider_name,
|
18
|
+
'resource_name' => resource_name,
|
19
|
+
'verification_name' => verification_name,
|
20
|
+
'resources' => resources }
|
21
|
+
end
|
5
22
|
|
6
23
|
def initialize(args)
|
7
|
-
@
|
24
|
+
@account_name = args[:account_name]
|
25
|
+
@arguments = args[:arguments]
|
8
26
|
@failing_resources = args[:failing_resources]
|
27
|
+
@name = args[:name] || 'unspecified'
|
9
28
|
@passing_resources = args[:passing_resources]
|
10
|
-
@
|
11
|
-
@
|
12
|
-
|
13
|
-
|
14
|
-
def to_s
|
15
|
-
passed? ? 'passed' : 'failed'
|
29
|
+
@provider_name = args[:provider_name]
|
30
|
+
@resource_name = args[:resource_name]
|
31
|
+
@verification_name = args[:verification_name]
|
16
32
|
end
|
17
33
|
|
18
34
|
def passed?
|
@@ -23,5 +39,13 @@ module Outliers
|
|
23
39
|
@failing_resources.any?
|
24
40
|
end
|
25
41
|
|
42
|
+
private
|
43
|
+
|
44
|
+
def resources
|
45
|
+
r = passing_resources.map{|r| { 'id' => r.id, 'passing' => 1 } }
|
46
|
+
r += failing_resources.map{|r| { 'id' => r.id, 'passing' => 0 } }
|
47
|
+
r
|
48
|
+
end
|
49
|
+
|
26
50
|
end
|
27
51
|
end
|
data/lib/outliers/run.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Outliers
|
2
2
|
class Run
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :account, :results, :threads, :threaded, :thread_count
|
4
4
|
|
5
5
|
def initialize(options={})
|
6
6
|
@results = []
|
@@ -29,14 +29,20 @@ module Outliers
|
|
29
29
|
|
30
30
|
evaluation = Proc.new { Evaluation.new(:name => name, :run => self).instance_eval &block }
|
31
31
|
|
32
|
+
if name
|
33
|
+
logger.info "Loading evaluation '#{name}'."
|
34
|
+
else
|
35
|
+
logger.info "Loading unnamed evaluation."
|
36
|
+
end
|
37
|
+
|
32
38
|
threaded ? threads << Thread.new { evaluation.call } : evaluation.call
|
33
39
|
end
|
34
40
|
|
35
|
-
def
|
41
|
+
def passing_results
|
36
42
|
@results.select {|r| r.passed?}
|
37
43
|
end
|
38
44
|
|
39
|
-
def
|
45
|
+
def failing_results
|
40
46
|
@results.reject {|r| r.passed?}
|
41
47
|
end
|
42
48
|
|
@@ -7,8 +7,8 @@ module Outliers
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def equals?(args)
|
10
|
-
keys = Array(args
|
11
|
-
logger.debug "Verifying '#{
|
10
|
+
keys = Array(args)
|
11
|
+
logger.debug "Verifying '#{keys.join(',')}' equals '#{list.empty? ? 'no resources' : list_by_key.join(',')}'."
|
12
12
|
list.reject {|r| keys.include? r.id}
|
13
13
|
end
|
14
14
|
|
data/lib/outliers/version.rb
CHANGED
data/lib/outliers.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require "outliers/mixins.rb"
|
2
2
|
require "outliers/verifications"
|
3
3
|
|
4
|
+
require "outliers/account"
|
4
5
|
require "outliers/collection"
|
5
|
-
require "outliers/credentials"
|
6
6
|
require "outliers/info"
|
7
7
|
require "outliers/exceptions"
|
8
8
|
require "outliers/evaluation"
|
9
9
|
require "outliers/filters"
|
10
|
+
require "outliers/handlers"
|
10
11
|
require "outliers/provider"
|
11
12
|
require "outliers/providers"
|
12
13
|
require "outliers/resource"
|
data/outliers.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["brett@weav.net"]
|
11
11
|
spec.description = %q{Configuraiton verification framework.}
|
12
12
|
spec.summary = %q{Configuration verification framework.}
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "http://www.getoutliers.com/documentation"
|
14
14
|
spec.license = "Apache2"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/reference.yaml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
aws_cloud_formation:
|
2
|
-
|
2
|
+
account:
|
3
3
|
access_key_id: AWS Account Access Key
|
4
4
|
secret_access_key: AWS Account Secret Key
|
5
5
|
region: AWS Region
|
@@ -10,7 +10,7 @@ aws_cloud_formation:
|
|
10
10
|
verifications: {}
|
11
11
|
|
12
12
|
aws_ec2:
|
13
|
-
|
13
|
+
account:
|
14
14
|
access_key_id: AWS Account Access Key
|
15
15
|
secret_access_key: AWS Account Secret Key
|
16
16
|
region: AWS Region
|
@@ -30,7 +30,7 @@ aws_ec2:
|
|
30
30
|
description: Instance status is running.
|
31
31
|
valid_image_id:
|
32
32
|
description: ami_ids=ami_id1,ami_id2 - Instances Image ID (AMI) is in given list.
|
33
|
-
args: '
|
33
|
+
args: '[IMAGE_ID1, IMAGEID2]'
|
34
34
|
vpc:
|
35
35
|
description: Instance is in a VPC.
|
36
36
|
security_group:
|
@@ -45,7 +45,7 @@ aws_ec2:
|
|
45
45
|
verifications: {}
|
46
46
|
|
47
47
|
aws_elb:
|
48
|
-
|
48
|
+
account:
|
49
49
|
access_key_id: AWS Account Access Key
|
50
50
|
secret_access_key: AWS Account Secret Key
|
51
51
|
region: AWS Region
|
@@ -56,10 +56,10 @@ aws_elb:
|
|
56
56
|
verifications:
|
57
57
|
ssl_certificates_valid:
|
58
58
|
description: Validates all SSL certificates associated with an ELB are valid for given number of days.
|
59
|
-
args: '
|
59
|
+
args: 'DAYS'
|
60
60
|
|
61
61
|
aws_iam:
|
62
|
-
|
62
|
+
account:
|
63
63
|
access_key_id: AWS Account Access Key
|
64
64
|
secret_access_key: AWS Account Secret Key
|
65
65
|
region: AWS Region
|
@@ -76,7 +76,7 @@ aws_iam:
|
|
76
76
|
description: Verify password not set for user.
|
77
77
|
|
78
78
|
aws_rds:
|
79
|
-
|
79
|
+
account:
|
80
80
|
access_key_id: AWS Account Access Key
|
81
81
|
secret_access_key: AWS Account Secret Key
|
82
82
|
region: AWS Region
|
@@ -87,7 +87,7 @@ aws_rds:
|
|
87
87
|
verifications:
|
88
88
|
backup_retention_period:
|
89
89
|
description: Validate the backup retention period equals given days for the db_instance.
|
90
|
-
args: '
|
90
|
+
args: 'DAYS'
|
91
91
|
multi_az:
|
92
92
|
description: RDS Multi AZ set to yes.
|
93
93
|
db_snapshot:
|
@@ -96,7 +96,7 @@ aws_rds:
|
|
96
96
|
verifications: {}
|
97
97
|
|
98
98
|
aws_s3:
|
99
|
-
|
99
|
+
account:
|
100
100
|
access_key_id: AWS Account Access Key
|
101
101
|
secret_access_key: AWS Account Secret Key
|
102
102
|
region: AWS Region
|
@@ -115,7 +115,7 @@ aws_s3:
|
|
115
115
|
description: Bucket is not configured as a website.
|
116
116
|
|
117
117
|
aws_sqs:
|
118
|
-
|
118
|
+
account:
|
119
119
|
access_key_id: AWS Account Access Key
|
120
120
|
secret_access_key: AWS Account Secret Key
|
121
121
|
region: AWS Region
|
data/shared.yaml
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Outliers::
|
4
|
-
subject { Outliers::
|
5
|
-
let(:
|
6
|
-
let(:
|
3
|
+
describe Outliers::Account do
|
4
|
+
subject { Outliers::Account }
|
5
|
+
let(:account1) { fixture_file 'account1.yml' }
|
6
|
+
let(:account2) { fixture_file 'account2.yml' }
|
7
7
|
|
8
8
|
context "#load_from_file" do
|
9
|
-
it "should load the
|
10
|
-
File.should_receive(:read).with('/home/user/outliers.yml').and_return
|
11
|
-
results = { "
|
9
|
+
it "should load the account from the given yaml file" do
|
10
|
+
File.should_receive(:read).with('/home/user/outliers.yml').and_return account1
|
11
|
+
results = { "test_account_1" =>
|
12
12
|
{ "region" => "us-west-1",
|
13
13
|
"provider" => "aws_ec2",
|
14
14
|
"access_key_id" => "01234567890123456789",
|
data/spec/collection_spec.rb
CHANGED
@@ -4,6 +4,7 @@ describe Outliers::Collection do
|
|
4
4
|
let(:provider) { mock 'provider' }
|
5
5
|
let(:resource1) { mock 'resource1' }
|
6
6
|
let(:resource2) { mock 'resource2' }
|
7
|
+
let(:resource3) { mock 'resource3' }
|
7
8
|
|
8
9
|
subject { Outliers::Collection.new provider }
|
9
10
|
|
@@ -12,7 +13,7 @@ describe Outliers::Collection do
|
|
12
13
|
resource1.stub name: 'resource1', key: 'name', id: 'resource1'
|
13
14
|
resource2.stub name: 'resource2', key: 'name', id: 'resource2'
|
14
15
|
subject.stub :load_all => [resource1, resource2],
|
15
|
-
:class
|
16
|
+
:class => Outliers::Resources::Aws::Ec2::SecurityGroupCollection
|
16
17
|
end
|
17
18
|
|
18
19
|
context "#to_human" do
|
@@ -36,16 +37,56 @@ describe Outliers::Collection do
|
|
36
37
|
end
|
37
38
|
|
38
39
|
context "#filter" do
|
39
|
-
|
40
|
+
before do
|
41
|
+
subject.instance_variable_set(:@list, [resource1, resource2, resource3])
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should include resources matched by include filter" do
|
40
45
|
subject.should_receive('filter_tag').with('Name:test123').and_return [resource1]
|
41
|
-
subject.filter '
|
46
|
+
subject.filter 'include', tag: 'Name:test123'
|
42
47
|
expect(subject.list).to eq([resource1])
|
43
48
|
end
|
44
49
|
|
50
|
+
it "should exclude resources matched by exclude filter" do
|
51
|
+
subject.should_receive('filter_tag').with('Name:test123').and_return [resource1]
|
52
|
+
subject.filter 'exclude', tag: 'Name:test123'
|
53
|
+
expect(subject.list).to eq([resource2, resource3])
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should apply multiple exclude filters" do
|
57
|
+
subject.should_receive('filter_tag').with('Name:test123').and_return [resource1]
|
58
|
+
subject.should_receive('filter_tag').with('Name:test321').and_return [resource2]
|
59
|
+
subject.filter 'exclude', tag: 'Name:test123'
|
60
|
+
subject.filter 'exclude', tag: 'Name:test321'
|
61
|
+
expect(subject.list).to eq([resource3])
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should apply multiple include filters and only return the union" do
|
65
|
+
subject.should_receive('filter_tag').with('Name:test123').and_return [resource1, resource3]
|
66
|
+
subject.should_receive('filter_tag').with('Name:test321').and_return [resource2, resource3]
|
67
|
+
subject.filter 'include', tag: 'Name:test123'
|
68
|
+
subject.filter 'include', tag: 'Name:test321'
|
69
|
+
expect(subject.list).to eq([resource3])
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should apply exclude and include filters and only return the union" do
|
73
|
+
subject.should_receive('filter_tag').with('Name:test123').and_return [resource1, resource3]
|
74
|
+
subject.should_receive('filter_tag').with('Name:test321').and_return [resource1, resource2]
|
75
|
+
subject.filter 'include', tag: 'Name:test123'
|
76
|
+
subject.filter 'exclude', tag: 'Name:test321'
|
77
|
+
expect(subject.list).to eq([resource3])
|
78
|
+
end
|
79
|
+
|
45
80
|
it "should raise an exception if the filter does not exist" do
|
46
|
-
expect { subject.filter('bogus' => 'Name:test123') }.
|
81
|
+
expect { subject.filter('include', 'bogus' => 'Name:test123') }.
|
47
82
|
to raise_error Outliers::Exceptions::UnknownFilter
|
48
83
|
end
|
84
|
+
|
85
|
+
it "should raise an exception if the filter action does not exist" do
|
86
|
+
subject.should_receive('filter_tag').with('Name:test123').and_return [resource1]
|
87
|
+
expect { subject.filter('bad_action', 'tag' => 'Name:test123') }.
|
88
|
+
to raise_error Outliers::Exceptions::UnknownFilterAction
|
89
|
+
end
|
49
90
|
end
|
50
91
|
|
51
92
|
context "#key" do
|
@@ -72,16 +113,16 @@ describe Outliers::Collection do
|
|
72
113
|
end
|
73
114
|
|
74
115
|
it "should verify the given verification against the colection" do
|
75
|
-
expect(subject.verify 'none_exist?'
|
116
|
+
expect(subject.verify 'none_exist?').
|
76
117
|
to eq( { failing_resources: [resource1, resource2], passing_resources: [] } )
|
77
118
|
end
|
78
119
|
|
79
120
|
it "should raise unkown verification if the verification does not exist" do
|
80
|
-
expect { subject.verify 'none'
|
121
|
+
expect { subject.verify 'none' }.to raise_error Outliers::Exceptions::UnknownVerification
|
81
122
|
end
|
82
123
|
|
83
124
|
it "should verify the given verification against the colection with options" do
|
84
|
-
expect(subject.verify 'equals?',
|
125
|
+
expect(subject.verify 'equals?', ['resource1', 'resource2']).
|
85
126
|
to eq( { failing_resources: [], passing_resources: [resource1, resource2] } )
|
86
127
|
end
|
87
128
|
|
data/spec/evaluation_spec.rb
CHANGED
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Outliers::Evaluation do
|
4
4
|
let(:run) { mock 'run' }
|
5
|
-
let(:connect) { subject.connect('
|
5
|
+
let(:connect) { subject.connect('test_account_1') }
|
6
6
|
let(:resources) { subject.resources('security_group') }
|
7
7
|
subject { Outliers::Evaluation.new :run => run, :name => 'test' }
|
8
8
|
|
9
9
|
before do
|
10
10
|
stub_logger
|
11
|
-
run.stub :
|
11
|
+
run.stub :account => account
|
12
12
|
end
|
13
13
|
|
14
14
|
context "#connect" do
|
@@ -18,20 +18,21 @@ describe Outliers::Evaluation do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should connect to the provider specified as an option" do
|
21
|
-
subject.connect('
|
21
|
+
subject.connect('test_account_1', { 'provider' => 'aws_rds' })
|
22
22
|
expect(subject.provider_name_array).to eq(['Aws', 'Rds'])
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should throw an error if the provider if the provider class is unkown" do
|
26
|
-
expect { subject.connect('
|
26
|
+
expect { subject.connect('test_account_1', { 'provider' => 'bad_provider' }) }.
|
27
27
|
to raise_error(Outliers::Exceptions::UnknownProvider)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should override a valid provider with one provided" do
|
31
|
-
subject.connect('
|
31
|
+
subject.connect('test_account_1', { 'provider' => 'aws_ec2' })
|
32
32
|
expect(subject.provider_name_array).to eq(['Aws', 'Ec2'])
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
35
36
|
|
36
37
|
context "with connection and resources" do
|
37
38
|
before do
|
@@ -41,9 +42,9 @@ describe Outliers::Evaluation do
|
|
41
42
|
|
42
43
|
context "#resources" do
|
43
44
|
it "should assign the collection_object" do
|
44
|
-
expect(subject.
|
45
|
+
expect(subject.resource_collection.class).
|
45
46
|
to eq(Outliers::Resources::Aws::Ec2::SecurityGroupCollection)
|
46
|
-
expect(subject.
|
47
|
+
expect(subject.resource_collection.provider.class).
|
47
48
|
to eq(Outliers::Providers::Aws::Ec2)
|
48
49
|
end
|
49
50
|
|
@@ -53,40 +54,71 @@ describe Outliers::Evaluation do
|
|
53
54
|
end
|
54
55
|
|
55
56
|
it "should test that over ride options are applied when selecting colleciton" do
|
56
|
-
subject.connect('
|
57
|
+
subject.connect('test_account_1', :provider => 'aws_rds')
|
57
58
|
subject.resources('db_instance')
|
58
|
-
expect(subject.
|
59
|
+
expect(subject.resource_collection.provider.class).
|
59
60
|
to eq(Outliers::Providers::Aws::Rds)
|
60
61
|
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
context "testing resource assignment" do
|
64
|
+
before do
|
65
|
+
subject.connect('test_account_1', :provider => 'aws_rds')
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should set the collection targets if specified" do
|
69
|
+
subject.resources('db_instance', include: 'instance-123')
|
70
|
+
expect(subject.resource_collection.targets).to eq ['instance-123']
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should send call exclude_by_key with given array" do
|
74
|
+
Outliers::Resources::Aws::Rds::DbInstanceCollection.
|
75
|
+
any_instance.should_receive(:exclude_by_key).with(['instance-123', 'instance-321'])
|
76
|
+
subject.resources('db_instance', exclude: ['instance-123', 'instance-321'])
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should convert input to array and send call exclude_by_key with value" do
|
80
|
+
Outliers::Resources::Aws::Rds::DbInstanceCollection.
|
81
|
+
any_instance.should_receive(:exclude_by_key).with(['instance-123'])
|
82
|
+
subject.resources('db_instance', exclude: 'instance-123')
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should include the given string as array" do
|
86
|
+
subject.resources('db_instance', include: 'instance-123')
|
87
|
+
expect(subject.resource_collection.targets).to eq ['instance-123']
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should include the array from the include key" do
|
91
|
+
subject.resources('db_instance', include: ['instance-123', 'instance-321'])
|
92
|
+
expect(subject.resource_collection.targets).to eq ['instance-123', 'instance-321']
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should include the array" do
|
96
|
+
subject.resources('db_instance', ['instance-123', 'instance-321'])
|
97
|
+
expect(subject.resource_collection.targets).to eq ['instance-123', 'instance-321']
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should include the string" do
|
101
|
+
subject.resources('db_instance', 'instance-123')
|
102
|
+
expect(subject.resource_collection.targets).to eq ['instance-123']
|
103
|
+
end
|
72
104
|
end
|
73
105
|
end
|
74
106
|
|
75
107
|
context "#filter" do
|
76
108
|
it "should apply the given filter to the collection" do
|
77
|
-
resources.should_receive(:filter).with('tag' => 'Name:test123')
|
78
|
-
subject.filter 'tag' => 'Name:test123'
|
109
|
+
resources.should_receive(:filter).with('include', 'tag' => 'Name:test123')
|
110
|
+
subject.filter 'include', 'tag' => 'Name:test123'
|
79
111
|
end
|
80
112
|
|
81
113
|
it "should convert keys in the args hash to strings" do
|
82
|
-
resources.should_receive(:filter).with('tag' => 'Name:test123')
|
83
|
-
subject.filter tag: 'Name:test123'
|
114
|
+
resources.should_receive(:filter).with('include', 'tag' => 'Name:test123')
|
115
|
+
subject.filter 'include', tag: 'Name:test123'
|
84
116
|
end
|
85
117
|
end
|
86
118
|
|
87
119
|
context "#verify" do
|
88
|
-
let(:result1) {
|
89
|
-
let(:result2) {
|
120
|
+
let(:result1) { stub 'result1', :passed? => true }
|
121
|
+
let(:result2) { stub 'result2', :passed? => true }
|
90
122
|
let(:verification_response) { ( { passing_resources: ['1', '2'], failing_resources: ['3', '4'] } ) }
|
91
123
|
|
92
124
|
before do
|
@@ -95,40 +127,70 @@ describe Outliers::Evaluation do
|
|
95
127
|
end
|
96
128
|
|
97
129
|
it "should verify the given method" do
|
98
|
-
resources.should_receive(:verify).with('test_verification?',
|
99
|
-
Outliers::Result.should_receive(:new).with(
|
100
|
-
|
130
|
+
resources.should_receive(:verify).with('test_verification?', nil).and_return verification_response
|
131
|
+
Outliers::Result.should_receive(:new).with(account_name: 'test_account_1',
|
132
|
+
arguments: [],
|
101
133
|
failing_resources: ['3','4'],
|
102
|
-
|
103
|
-
|
104
|
-
|
134
|
+
name: 'test',
|
135
|
+
passing_resources: ['1','2'],
|
136
|
+
provider_name: 'aws_ec2',
|
137
|
+
resource_name: 'security_group',
|
138
|
+
verification_name: 'test_verification?').and_return result1
|
139
|
+
expect(subject.verify('test_verification?')).to eq([result1])
|
105
140
|
end
|
106
141
|
|
107
142
|
it "should convert all options to symbols" do
|
108
|
-
resources.should_receive(:verify).with('test_verification?',
|
109
|
-
Outliers::Result.should_receive(:new).with(
|
143
|
+
resources.should_receive(:verify).with('test_verification?', ['test123']).and_return verification_response
|
144
|
+
Outliers::Result.should_receive(:new).with(account_name: 'test_account_1',
|
145
|
+
arguments: ['test123'],
|
146
|
+
failing_resources: ['3','4'],
|
147
|
+
name: 'test',
|
110
148
|
passing_resources: ['1','2'],
|
149
|
+
provider_name: 'aws_ec2',
|
150
|
+
resource_name: 'security_group',
|
151
|
+
verification_name: 'test_verification?').and_return result1
|
152
|
+
expect(subject.verify('test_verification?', ['test123'] )).to eq([result1])
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should convert arguments string to array in results" do
|
156
|
+
resources.should_receive(:verify).with('test_verification?', ['arg']).and_return verification_response
|
157
|
+
Outliers::Result.should_receive(:new).with(account_name: 'test_account_1',
|
158
|
+
arguments: ['arg'],
|
111
159
|
failing_resources: ['3','4'],
|
112
|
-
|
113
|
-
|
114
|
-
|
160
|
+
name: 'test',
|
161
|
+
passing_resources: ['1','2'],
|
162
|
+
provider_name: 'aws_ec2',
|
163
|
+
resource_name: 'security_group',
|
164
|
+
verification_name: 'test_verification?').and_return result1
|
165
|
+
expect(subject.verify('test_verification?', 'arg' )).to eq([result1])
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should raise and error if the arguments are not nil, string or array" do
|
169
|
+
expect { subject.verify('test_verification?', arg: 'bad_arg' ) }.
|
170
|
+
to raise_error(Outliers::Exceptions::InvalidArguments)
|
115
171
|
end
|
116
172
|
|
117
173
|
it "should run verify multiple times in given evaluation" do
|
118
|
-
resources.should_receive(:verify).with('test_verification1?',
|
119
|
-
resources.should_receive(:verify).with('test_verification2?',
|
120
|
-
Outliers::Result.should_receive(:new).with(
|
121
|
-
|
174
|
+
resources.should_receive(:verify).with('test_verification1?', ['arg1']).and_return verification_response
|
175
|
+
resources.should_receive(:verify).with('test_verification2?', ['arg2']).and_return verification_response
|
176
|
+
Outliers::Result.should_receive(:new).with(account_name: 'test_account_1',
|
177
|
+
arguments: ['arg1'],
|
122
178
|
failing_resources: ['3','4'],
|
123
|
-
|
124
|
-
verification: 'test_verification1?').and_return result1
|
125
|
-
Outliers::Result.should_receive(:new).with(evaluation: 'test',
|
179
|
+
name: 'test',
|
126
180
|
passing_resources: ['1','2'],
|
181
|
+
provider_name: 'aws_ec2',
|
182
|
+
resource_name: 'security_group',
|
183
|
+
verification_name: 'test_verification1?').and_return result1
|
184
|
+
Outliers::Result.should_receive(:new).with(account_name: 'test_account_1',
|
185
|
+
arguments: ['arg2'],
|
127
186
|
failing_resources: ['3','4'],
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
187
|
+
name: 'test',
|
188
|
+
passing_resources: ['1','2'],
|
189
|
+
provider_name: 'aws_ec2',
|
190
|
+
resource_name: 'security_group',
|
191
|
+
verification_name: 'test_verification2?').and_return result2
|
192
|
+
expect(subject.verify('test_verification1?', ['arg1'])).to eq [result1]
|
193
|
+
expect(subject.verify('test_verification2?', ['arg2'])).to eq [result1, result2]
|
132
194
|
end
|
133
195
|
end
|
134
196
|
|