Class: Pangea::Magma::Matchers::PlanCleanlyUnderMagma
- Defined in:
- lib/pangea/magma/matchers.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize ⇒ PlanCleanlyUnderMagma
constructor
A new instance of PlanCleanlyUnderMagma.
- #matches?(workspace_path) ⇒ Boolean
-
#resource_changes ⇒ Object
No-op terminator — lets the chain read ‘.with_at_least(3).resource_changes` naturally.
-
#with_at_least(n) ⇒ Object
Alias to read more naturally before ‘.resource_changes`.
-
#with_provider(source) ⇒ Object
Self — chains: ‘with_provider(’hashicorp/aws’)‘.
-
#with_resource_type(type) ⇒ Object
Self — chains: ‘with_resource_type(’aws_vpc’)‘.
Constructor Details
#initialize ⇒ PlanCleanlyUnderMagma
Returns a new instance of PlanCleanlyUnderMagma.
37 38 39 40 41 |
# File 'lib/pangea/magma/matchers.rb', line 37 def initialize @required_providers = [] @min_resource_changes = nil @resource_types = [] end |
Instance Method Details
#description ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/pangea/magma/matchers.rb', line 114 def description desc = +"plan cleanly under magma" desc << " with providers #{@required_providers.inspect}" unless @required_providers.empty? desc << " emitting ≥#{@min_resource_changes} resource_changes" if @min_resource_changes desc << " declaring resource types #{@resource_types.inspect}" unless @resource_types.empty? desc end |
#failure_message ⇒ Object
106 107 108 |
# File 'lib/pangea/magma/matchers.rb', line 106 def @failure_message || "expected workspace to plan cleanly under magma" end |
#failure_message_when_negated ⇒ Object
110 111 112 |
# File 'lib/pangea/magma/matchers.rb', line 110 def "expected workspace not to plan cleanly under magma, but it did:\n#{@report.inspect}" end |
#matches?(workspace_path) ⇒ Boolean
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/pangea/magma/matchers.rb', line 67 def matches?(workspace_path) unless Pangea::Magma.installed? @failure_message = "magma binary not installed (set MAGMA_BINARY or install)" return false end @report = Pangea::Magma.verify_workspace(workspace_path) unless @report.dig('compatibility', 'plans_cleanly') @failure_message = "workspace #{workspace_path} did not plan cleanly: #{@report.inspect}" return false end @required_providers.each do |source| unless Array(@report['providers']).include?(source) @failure_message = "expected provider #{source.inspect}; got #{@report['providers']}" return false end end if @min_resource_changes actual = @report['resource_change_count'].to_i if actual < @min_resource_changes @failure_message = "expected ≥#{@min_resource_changes} resource changes; got #{actual}" return false end end @resource_types.each do |type| unless Array(@report['resource_types']).include?(type) @failure_message = "expected resource type #{type.inspect}; got #{@report['resource_types']}" return false end end true rescue Pangea::Magma::VerificationFailed => e @failure_message = "magma fixture verify raised: #{e.}" false end |
#resource_changes ⇒ Object
No-op terminator — lets the chain read ‘.with_at_least(3).resource_changes` naturally.
57 58 59 |
# File 'lib/pangea/magma/matchers.rb', line 57 def resource_changes self end |
#with_at_least(n) ⇒ Object
Alias to read more naturally before ‘.resource_changes`
50 51 52 53 |
# File 'lib/pangea/magma/matchers.rb', line 50 def with_at_least(n) @min_resource_changes = n self end |
#with_provider(source) ⇒ Object
Returns self — chains: ‘with_provider(’hashicorp/aws’)‘.
44 45 46 47 |
# File 'lib/pangea/magma/matchers.rb', line 44 def with_provider(source) @required_providers << source self end |
#with_resource_type(type) ⇒ Object
Returns self — chains: ‘with_resource_type(’aws_vpc’)‘.
62 63 64 65 |
# File 'lib/pangea/magma/matchers.rb', line 62 def with_resource_type(type) @resource_types << type self end |