This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
/
loggregator_spec.rb
77 lines (61 loc) · 2.05 KB
/
loggregator_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require "spec_helper"
require "net/http"
require "securerandom"
require "timeout"
require "support/test_env"
require "support/app_crud_helpers"
describe "Loggregator", component: 'loggregator' do
include AppCrudHelpers
with_user_with_org
with_new_space
with_time_limit
let(:app_content) { "#{SecureRandom.uuid}_#{Time.now.to_i}" }
let(:language) { ENV["NYET_APP"] || "java" }
let(:app_name) { "crud-#{language}" }
attr_reader :route
it "gets log messages from an app" do
begin
regular_user.clean_up_app_from_previous_run(app_name)
@app = regular_user.create_app(@space, app_name, CUSTOM_VAR: app_content)
regular_user.clean_up_route_from_previous_run(app_name)
@route = regular_user.create_route(@app, app_name, TestEnv.default.apps_domain)
if path = APPS[language]
deploy_app(@app, path)
else
raise "NYET_APP was set to #{ENV["NYET_APP"].inspect}, must be one of #{APPS.keys.to_s} (or nil)"
end
start_app_and_wait_until_up(@app)
monitoring.record_action(:loggregator_works) do
initialize_gcf
check_loggregator_works
end
@route.delete!
@app.delete!
monitoring.record_metric("loggregator.health", 1)
rescue => e
monitoring.record_metric("loggregator.health", 0)
raise e
end
end
def check_loggregator_works
puts "starting #{__method__} (#{Time.now})"
BlueShell::Runner.run("gcf logs #{app_name}") do |runner|
runner.with_timeout 60 do
runner.should say "Connected, tailing logs for app #{app_name}"
# Hit twice to see that both router and app messages come through; order is not guaranteed
page_content
runner.should say "[RTR]"
page_content
runner.should say "[App/0]"
end
end
end
def initialize_gcf
username = ENV['NYET_REGULAR_USERNAME']
password = ENV['NYET_REGULAR_PASSWORD']
api_endpoint = ENV['NYET_TARGET']
`gcf api #{api_endpoint}`
`gcf auth #{username} #{password}`
`gcf target -o #{@org.name} -s #{@space.name}`
end
end