lib/rspec/terraform/helpers/actions/validate.rb in rspec-terraform-0.1.0.pre.47 vs lib/rspec/terraform/helpers/actions/validate.rb in rspec-terraform-0.1.0.pre.48
- old
+ new
@@ -4,19 +4,51 @@
module Terraform
module Helpers
module Actions
module Validate
def validate(parameters)
- missing_parameters =
- required_parameters(execution_mode)
- .filter { |parameter| parameters[parameter].nil? }
+ required = required_parameters(execution_mode)
- return if missing_parameters.empty?
+ log_validate_starting(required)
+ log_validate_using_parameters(parameters)
- raise_missing_parameters(missing_parameters)
+ missing = determine_missing(parameters, required)
+
+ handle_result(missing)
end
private
+
+ def determine_missing(parameters, required)
+ required.filter { |parameter| parameters[parameter].nil? }
+ end
+
+ def handle_result(missing)
+ if missing.empty?
+ log_validate_successful
+ else
+ log_validate_failed(missing)
+ raise_missing_parameters(missing)
+ end
+ end
+
+ def log_validate_starting(required)
+ logger&.info(
+ "Validating required parameters: #{required} present..."
+ )
+ end
+
+ def log_validate_using_parameters(parameters)
+ logger&.debug("Validating parameters: #{parameters}...")
+ end
+
+ def log_validate_successful
+ logger&.info('Validate successful.')
+ end
+
+ def log_validate_failed(missing)
+ logger&.error("Validate failed. Parameters: #{missing} missing.")
+ end
def raise_missing_parameters(parameters)
parameters = parameters.collect { |parameter| "`:#{parameter}`" }
if parameters.count == 1
raise StandardError,