Sha256: 4e2f2f5fbede45a7ba2d4c759fc10d55d379a335f972979fa194af9886fb45cf

Contents?: true

Size: 1.9 KB

Versions: 14

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

module RSpec
  module Terraform
    module Helpers
      module Actions
        module Validate
          def validate(parameters)
            required = required_parameters(execution_mode)

            log_validate_starting(required)
            log_validate_using_parameters(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,
                    "Required parameter: #{parameters[0]} missing."
            else
              parameters =
                "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
              raise StandardError,
                    "Required parameters: #{parameters} missing."
            end
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rspec-terraform-0.5.0.pre.9 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.5.0.pre.8 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.5.0.pre.7 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.5.0.pre.6 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.5.0.pre.5 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.5.0.pre.4 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.5.0.pre.3 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.5.0.pre.2 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.5.0.pre.1 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.4.0 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.3.0.pre.1 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.2.0 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.1.0.pre.49 lib/rspec/terraform/helpers/actions/validate.rb
rspec-terraform-0.1.0.pre.48 lib/rspec/terraform/helpers/actions/validate.rb