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.



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

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#connectionObject



80
81
82
# File 'lib/fake_sns/test_integration.rb', line 80

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

#dataObject



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

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

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



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/fake_sns/test_integration.rb', line 64

def drain(message_id = nil, options = {})
  path = message_id ? "/drain/#{message_id}" : "/drain"
  default = {
    region:             Aws.config[:region],
    access_key_id:      Aws.config[:credentials].access_key_id,
    secret_access_key:  Aws.config[:credentials].secret_access_key,
  }
  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



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

def host
  option :sns_endpoint
end

#portObject



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

def port
  option :sns_port
end

#resetObject



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

def reset
  connection.delete("/")
end

#startObject



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

def start
  start! unless up?
  reset
end

#start!Object



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

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

#startup_timeoutObject



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

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

#stopObject



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

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)


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

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

#urlObject



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

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