/
cloudfoundry_spec.rb
207 lines (168 loc) · 6.2 KB
/
cloudfoundry_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require "logstash/filters/cloudfoundry"
describe LogStash::Filters::CloudFoundry do
subject(:plugin) { LogStash::Filters::CloudFoundry.new(config) }
let(:config) { Hash.new }
let(:doc) { "" }
let(:event) { LogStash::Event.new("message" => doc) }
#Received invalid config inputs
describe "registration" do
before(:each) do
plugin.register
end
describe "got blank required data" do
let(:config) do {
"cf_api" => "",
"cf_user" => "",
"cf_password" => "",
"cf_org" => "",
"cf_space" => ""}
end
it "failed variables are set" do
expect(plugin.instance_variable_get(:@cf_logged_in)).to eq(false)
expect(plugin.instance_variable_get(:@cf_retry_cli)).to eq(false)
end
end
describe "got bad data" do
let(:config) do {
"cf_api" => "bad data",
"cf_user" => "bad data",
"cf_password" => "bad data",
"cf_org" => "bad data",
"cf_space" => "bad data"}
end
it "failed variables are set" do
expect(plugin.instance_variable_get(:@cf_logged_in)).to eq(false)
expect(plugin.instance_variable_get(:@cf_retry_cli)).to eq(false)
end
it "CF HOME variable was set" do
expect(File.directory?(plugin.instance_variable_get(:@cf_path))).to be(true)
end
end
describe "got valid data without retry" do
let(:config) do {
"cf_api" => "https://api.run.pivotal.io",
"cf_user" => "username",
"cf_password" => "password",
"cf_org" => "ITCS",
"cf_space" => "development"}
end
it "successful variables are set" do
expect(plugin.instance_variable_get(:@cf_logged_in)).to eq(true)
expect(plugin.instance_variable_get(:@cf_retry_cli)).to eq(false)
end
it "CF HOME variable was set" do
expect(File.directory?(plugin.instance_variable_get(:@cf_path))).to be(true)
end
end
describe "got valid data with retry" do
let(:config) do {
"cf_api" => "https://api.run.pivotal.io",
"cf_user" => "username",
"cf_password" => "password",
"cf_org" => "ITCS",
"cf_space" => "development",
"cf_retry_cli_timeout" => 10}
end
it "successful variables are set" do
expect(plugin.instance_variable_get(:@cf_logged_in)).to eq(true)
expect(plugin.instance_variable_get(:@cf_retry_cli)).to eq(true)
end
it "CF HOME variable was set" do
expect(File.directory?(plugin.instance_variable_get(:@cf_path))).to be(true)
end
end
end
describe "filtering" do
before(:each) do
plugin.register
end
describe "got valid data" do
let(:config) do {
"cf_api" => "https://api.run.pivotal.io",
"cf_user" => "username",
"cf_password" => "password",
"cf_org" => "ITCS",
"cf_space" => "development"}
end
let(:doc) { "abc loggregator 964db4e9-4f9c-42a2-9296-f8381ce459eb sample log" }
it "extract all the values" do
plugin.filter(event)
expect(event.get("orgname")).to eq("ITCS")
expect(event.get("spacename")).to eq("development")
expect(event.get("appname")).to eq("spring-music")
expect(event.get("appguid")).to eq("964db4e9-4f9c-42a2-9296-f8381ce459eb")
end
it "extract all values from cache" do
plugin.filter(event)
expect(plugin.instance_variable_get(:@app_cache)[event.get("appguid")].nil?).to be(false)
end
end
describe "got valid data from different space" do
let(:config) do {
"cf_api" => "https://api.run.pivotal.io",
"cf_user" => "username",
"cf_password" => "password",
"cf_org" => "ITCS",
"cf_space" => "test"}
end
let(:doc) { "abc loggregator 964db4e9-4f9c-42a2-9296-f8381ce459eb sample log" }
it "extract all the values" do
plugin.filter(event)
expect(event.get("orgname")).to eq("ITCS")
expect(event.get("spacename")).to eq("development")
expect(event.get("appname")).to eq("spring-music")
expect(event.get("appguid")).to eq("964db4e9-4f9c-42a2-9296-f8381ce459eb")
end
it "extract all values from cache" do
plugin.filter(event)
expect(plugin.instance_variable_get(:@app_cache)[event.get("appguid")].nil?).to be(false)
end
end
describe "got valid data with invalid guid" do
let(:config) do {
"cf_api" => "https://api.run.pivotal.io",
"cf_user" => "username",
"cf_password" => "password",
"cf_org" => "ITCS",
"cf_space" => "test",
"cache_invalid_guids" => false}
end
let(:doc) { "abc loggregator aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee sample log" }
it "make sure cache is empty" do
plugin.filter(event)
expect(plugin.instance_variable_get(:@app_cache)[event.get("appguid")].nil?).to be(true)
end
end
describe "got valid data with invalid guid" do
let(:config) do {
"cf_api" => "https://api.run.pivotal.io",
"cf_user" => "username",
"cf_password" => "password",
"cf_org" => "ITCS",
"cf_space" => "test",
"cache_invalid_guids" => true}
end
let(:doc) { "abc loggregator aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee sample log" }
it "make sure cache has value" do
plugin.filter(event)
expect(plugin.instance_variable_get(:@app_cache)[event.get("appguid")].nil?).to be(false)
end
end
describe "got valid data with no guid" do
let(:config) do {
"cf_api" => "https://api.run.pivotal.io",
"cf_user" => "username",
"cf_password" => "password",
"cf_org" => "ITCS",
"cf_space" => "test"}
end
let(:doc) { "sample log" }
it "make sure flags are set" do
plugin.filter(event)
expect(event.get("appguid").nil?).to eq(true)
end
end
end
end