Class: FakeCtl

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeFakeCtl

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

#commandsObject (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