Class: Heroku::Samorau::ManifestCheck
- Defined in:
- lib/heroku/samorau.rb
Constant Summary collapse
- ValidPriceUnits =
%w[month dyno_hour]
Instance Attribute Summary
Attributes inherited from Check
Instance Method Summary collapse
Methods inherited from Check
#call, #check, #error, #initialize, #run, #test, #to_proc
Constructor Details
This class inherits a constructor from Heroku::Samorau::Check
Instance Method Details
#call! ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/heroku/samorau.rb', line 118 def call! test "manifest name key" check "if exists" do data.has_key?("name") end check "is a string" do data["name"].is_a?(String) end check "is not blank" do !data["name"].empty? end test "manifest api key" check "if exists" do data.has_key?("api") end check "is a hash" do data["api"].is_a?(Hash) end check "contains username" do data["api"].has_key?("username") && data["api"]["username"] != "" end check "contains password" do data["api"].has_key?("password") && data["api"]["password"] != "" end check "contains test url" do data["api"].has_key?("test") end check "contains production url" do data["api"].has_key?("production") end check "production url uses SSL" do data["api"]["production"] =~ /^https:/ end check "contains config_vars array" do data["api"].has_key?("config_vars") && data["api"]["config_vars"].is_a?(Array) end check "containst at least one config var" do !data["api"]["config_vars"].empty? end check "all config vars are uppercase strings" do data["api"]["config_vars"].each do |k, v| if k =~ /^[A-Z][0-9A-Z_]+$/ true else error "#{k.inspect} is not a valid ENV key" end end end test "plans" check "key must exist" do data.has_key?("plans") end check "is an array" do data["plans"].is_a?(Array) end check "contains at least one plan" do !data["plans"].empty? end check "all plans are a hash" do data["plans"].all? {|plan| plan.is_a?(Hash) } end check "all plans have a name" do data["plans"].all? {|plan| plan.has_key?("name") } end check "all plans have a unique name" do names = data["plans"].map {|plan| plan["name"] } names.size == names.uniq.size end data["plans"].each do |plan| check "#{plan["name"]} has a valid price" do if plan["price"] !~ /^\d+$/ error "expected an integer" else true end end check "#{plan["name"]} has a valid price_unit" do if ValidPriceUnits.include?(plan["price_unit"]) true else error "expected #{ValidPriceUnits.join(" or ")} but got #{plan["price_unit"].inspect}" end end end end |