Class: FakeSNS::TestIntegration

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_sns/test_integration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TestIntegration

Returns a new instance of TestIntegration.



9
10
11
# File 'lib/fake_sns/test_integration.rb', line 9

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/fake_sns/test_integration.rb', line 7

def options
  @options
end

Instance Method Details

#connectionObject



75
76
77
# File 'lib/fake_sns/test_integration.rb', line 75

def connection
  @connection ||= Faraday.new(url)
end

#dataObject



59
60
61
# File 'lib/fake_sns/test_integration.rb', line 59

def data
  YAML.load(connection.get("/").body)
end

#drain(message_id = nil, options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fake_sns/test_integration.rb', line 63

def drain(message_id = nil, options = {})
  path = message_id ? "/drain/#{message_id}" : "/drain"
  default = { aws_config: AWS.config.send(:supplied) }
  body = default.merge(options).to_json
  result = connection.post(path, body)
  if result.success?
    true
  else
    raise "Unable to drain messages: #{result.body}"
  end
end

#hostObject



17
18
19
# File 'lib/fake_sns/test_integration.rb', line 17

def host
  option :sns_endpoint
end

#portObject



21
22
23
# File 'lib/fake_sns/test_integration.rb', line 21

def port
  option :sns_port
end

#resetObject



45
46
47
# File 'lib/fake_sns/test_integration.rb', line 45

def reset
  connection.delete("/")
end

#startObject



25
26
27
28
# File 'lib/fake_sns/test_integration.rb', line 25

def start
  start! unless up?
  reset
end

#start!Object



30
31
32
33
# File 'lib/fake_sns/test_integration.rb', line 30

def start!
  @pid = Process.spawn(binfile, "-p", port.to_s, "--database", database, :out => out, :err => out)
  wait_until_up
end

#startup_timeoutObject



13
14
15
# File 'lib/fake_sns/test_integration.rb', line 13

def startup_timeout
  options.fetch(:startup_timeout) { 5 }
end

#stopObject



35
36
37
38
39
40
41
42
43
# File 'lib/fake_sns/test_integration.rb', line 35

def stop
  if @pid
    Process.kill("INT", @pid)
    Process.waitpid(@pid)
    @pid = nil
  else
    $stderr.puts "FakeSNS is not running"
  end
end

#up?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/fake_sns/test_integration.rb', line 53

def up?
  @pid && connection.get("/").success?
rescue Errno::ECONNREFUSED, Faraday::Error::ConnectionFailed
  false
end

#urlObject



49
50
51
# File 'lib/fake_sns/test_integration.rb', line 49

def url
  "http://#{host}:#{port}"
end