-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from k1LoW/add-command-generate-cloudwatch_alarm
Add command `awspec generate cloudwatch_alarm`
- Loading branch information
Showing
6 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Awspec::Generator | ||
module Spec | ||
class CloudwatchAlarm | ||
include Awspec::Helper::Finder | ||
def generate_all | ||
alarms = select_all_cloudwatch_alarms | ||
alarms.empty? && fail('Not Found alarm') | ||
ERB.new(alarm_spec_template, nil, '-').result(binding).chomp | ||
end | ||
|
||
def alarm_spec_template | ||
template = <<-'EOF' | ||
<% alarms.each do |alarm| %> | ||
describe cloudwatch_alarm('<%= alarm.alarm_name %>') do | ||
it { should exist } | ||
<%- alarm.ok_actions.each do |action| -%> | ||
it { should have_ok_action('<%= action %>') } | ||
<%- end -%> | ||
<%- alarm.alarm_actions.each do |action| -%> | ||
it { should have_alarm_action('<%= action %>') } | ||
<%- end -%> | ||
<%- alarm.insufficient_data_actions.each do |action| -%> | ||
it { should have_insufficient_data_action('<%= action %>') } | ||
<%- end -%> | ||
it { should belong_to_metric('<%= alarm.metric_name %>').namespace('<%= alarm.namespace %>') } | ||
its(:state_value) { should eq '<%= alarm.state_value %>' } | ||
its(:statistic) { should eq '<%= alarm.statistic %>' } | ||
its(:period) { should eq <%= alarm.period %> } | ||
its(:unit) { should eq '<%= alarm.unit %>' } | ||
its(:evaluation_periods) { should eq <%= alarm.evaluation_periods %> } | ||
its(:threshold) { should eq <%= alarm.threshold %> } | ||
its(:comparison_operator) { should eq '<%= alarm.comparison_operator %>' } | ||
end | ||
<% end %> | ||
EOF | ||
template | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Awspec::Generator::Spec::CloudwatchAlarm' do | ||
before do | ||
Awspec::Stub.load 'cloudwatch_alarm' | ||
end | ||
let(:cloudwatch_alarm) { Awspec::Generator::Spec::CloudwatchAlarm.new } | ||
it 'generate_all generate spec' do | ||
spec = <<-'EOF' | ||
describe cloudwatch_alarm('my-cloudwatch-alarm') do | ||
it { should exist } | ||
it { should have_ok_action('arn:aws:sns:ap-northeast-1:1234567890:sns_alert') } | ||
it { should have_alarm_action('arn:aws:sns:ap-northeast-1:1234567890:sns_alert') } | ||
it { should have_insufficient_data_action('arn:aws:sns:ap-northeast-1:1234567890:sns_alert') } | ||
it { should belong_to_metric('NumberOfProcesses').namespace('my-cloudwatch-namespace') } | ||
its(:state_value) { should eq 'OK' } | ||
its(:statistic) { should eq 'Average' } | ||
its(:period) { should eq 300 } | ||
its(:unit) { should eq 'Seconds' } | ||
its(:evaluation_periods) { should eq 1 } | ||
its(:threshold) { should eq 5.0 } | ||
its(:comparison_operator) { should eq 'LessThanOrEqualToThreshold' } | ||
end | ||
EOF | ||
expect(cloudwatch_alarm.generate_all.to_s.gsub(/\n/, "\n")).to eq spec | ||
end | ||
end |