Class: FakeCtl
- Inherits:
-
Object
- Object
- FakeCtl
- Defined in:
- lib/kube/cluster/resource/dirty_tracking.rb
Overview
Fake ctl that records every command and returns canned responses. The test wires this into the cluster → connection → ctl chain so that Persistence#kubectl goes through it without touching a real cluster.
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
-
#initialize ⇒ FakeCtl
constructor
A new instance of FakeCtl.
- #run(string) ⇒ Object
-
#stub_response(substring, response) ⇒ Object
Queue a response for the next command that includes
substring.
Constructor Details
#initialize ⇒ FakeCtl
Returns a new instance of FakeCtl.
132 133 134 135 |
# File 'lib/kube/cluster/resource/dirty_tracking.rb', line 132 def initialize @commands = [] @responses = {} end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
130 131 132 |
# File 'lib/kube/cluster/resource/dirty_tracking.rb', line 130 def commands @commands end |
Instance Method Details
#run(string) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/kube/cluster/resource/dirty_tracking.rb', line 142 def run(string) @commands << string @responses.each do |substring, response| if string.include?(substring) return response end end "" # default: empty response end |
#stub_response(substring, response) ⇒ Object
Queue a response for the next command that includes substring.
138 139 140 |
# File 'lib/kube/cluster/resource/dirty_tracking.rb', line 138 def stub_response(substring, response) @responses[substring] = response end |