Class: Kitsune::Kit::Adapters::FakeTransport

Inherits:
Transport
  • Object
show all
Defined in:
lib/kitsune/kit/adapters/fake_transport.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Transport

#with_session

Constructor Details

#initialize(reachable: true, failures: {}) ⇒ FakeTransport

Returns a new instance of FakeTransport.



11
12
13
14
15
16
17
18
# File 'lib/kitsune/kit/adapters/fake_transport.rb', line 11

def initialize(reachable: true, failures: {})
  super()
  @reachable = reachable
  @failures = failures
  @stubs = {}
  @calls = []
  @uploads = {}
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



9
10
11
# File 'lib/kitsune/kit/adapters/fake_transport.rb', line 9

def calls
  @calls
end

#uploadsObject (readonly)

Returns the value of attribute uploads.



9
10
11
# File 'lib/kitsune/kit/adapters/fake_transport.rb', line 9

def uploads
  @uploads
end

Instance Method Details

#execute(command, arguments: [], timeout: 30, stdin: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/kitsune/kit/adapters/fake_transport.rb', line 36

def execute(command, arguments: [], timeout: 30, stdin: nil)
  @calls << [:execute, { command: command, arguments: arguments, timeout: timeout, stdin: stdin }]
  raise @failures[:execute] if @failures[:execute]

  @stubs.fetch([command, arguments]) do
    status = command == "test" ? 1 : 0
    CommandResult.new(stdout: "", stderr: "", exit_status: status, duration_ms: 1)
  end
end

#reachable?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/kitsune/kit/adapters/fake_transport.rb', line 29

def reachable?
  @calls << [:reachable, {}]
  raise @failures[:reachable] if @failures[:reachable]

  @reachable
end

#stub(command, arguments: [], stdout: "", stderr: "", exit_status: 0, duration_ms: 1) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/kitsune/kit/adapters/fake_transport.rb', line 20

def stub(command, arguments: [], stdout: "", stderr: "", exit_status: 0, duration_ms: 1)
  @stubs[[command, arguments]] = CommandResult.new(
    stdout: stdout,
    stderr: stderr,
    exit_status: exit_status,
    duration_ms: duration_ms
  )
end

#upload(content:, remote_path:, mode: "0600") ⇒ Object



46
47
48
49
50
51
52
# File 'lib/kitsune/kit/adapters/fake_transport.rb', line 46

def upload(content:, remote_path:, mode: "0600")
  @calls << [:upload, { remote_path: remote_path, mode: mode }]
  raise @failures[:upload] if @failures[:upload]

  @uploads[remote_path] = { content: content, mode: mode }
  true
end