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.



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

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#connectionObject



70
71
72
# File 'lib/fake_sns/test_integration.rb', line 70

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

#dataObject



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

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

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



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fake_sns/test_integration.rb', line 58

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



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

def host
  option :sns_endpoint
end

#portObject



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

def port
  option :sns_port
end

#resetObject



40
41
42
# File 'lib/fake_sns/test_integration.rb', line 40

def reset
  connection.delete("/")
end

#startObject



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

def start
  start! unless up?
  reset
end

#start!Object



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

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

#stopObject



30
31
32
33
34
35
36
37
38
# File 'lib/fake_sns/test_integration.rb', line 30

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)


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

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

#urlObject



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

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