Skip to content

Commit 81ecd17

Browse files
committed
Check more error messages for testcases.
1 parent 6165f1e commit 81ecd17

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

tests/test-st2-invalid-auth.js

+66-3
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,44 @@ describe("invalid st2 credential configuration", function() {
129129
});
130130

131131
// Load script under test
132-
var stackstorm = require("../scripts/stackstorm.js");
132+
var i, stackstorm = require("../scripts/stackstorm.js");
133133
stackstorm(robot).then(function (stop) {
134134
expect(info_spy).to.have.been.calledTwice;
135135
expect(info_spy).to.have.been.calledWith('Using ST2_API_KEY as authentication. Expiry will lead to bot exit.');
136136
expect(info_spy).to.have.been.calledWith('Loading commands...');
137137

138+
// Check that it was called at some point with 'Failed to retrieve commands from'
139+
for (i = 0; i < error_spy.args.length; i++) {
140+
try {
141+
expect(error_spy.args[i][0]).to.be.a('string');
142+
expect(error_spy.args[i][0]).to.startWith('StackStorm event stream error: Event { type: \'error\', status: 401 }');
143+
break;
144+
} catch (err) {
145+
// If we have reached the last call and we still haven't found it
146+
if (i >= error_spy.args.length-1) {
147+
// Re-throw the assert exception
148+
throw(err);
149+
}
150+
// Implicit continue
151+
}
152+
}
153+
154+
// Check that it was called at some point with 'Failed to retrieve commands from'
155+
for (i = 0; i < error_spy.args.length; i++) {
156+
try {
157+
expect(error_spy.args[i][0]).to.be.a('string');
158+
expect(error_spy).to.have.been.calledWith('Implicitly attempting to reconnect to StackStorm event stream.');
159+
break;
160+
} catch (err) {
161+
// If we have reached the last call and we still haven't found it
162+
if (i >= error_spy.args.length-1) {
163+
// Re-throw the assert exception
164+
throw(err);
165+
}
166+
// Implicit continue
167+
}
168+
}
169+
138170
stop({shutdown: true});
139171

140172
done();
@@ -150,11 +182,42 @@ describe("invalid st2 credential configuration", function() {
150182
});
151183

152184
// Load script under test
153-
var stackstorm = require("../scripts/stackstorm.js");
185+
var i, stackstorm = require("../scripts/stackstorm.js");
154186
stackstorm(robot).then(function (stop) {
155187
expect(info_spy).to.have.been.calledTwice;
156188
expect(info_spy).to.have.been.calledWith('Using ST2_AUTH_TOKEN as authentication. Expiry will lead to bot exit.');
157-
expect(info_spy).to.have.been.calledWith('Loading commands...');
189+
190+
// Check that it was called at some point with 'Failed to retrieve commands from'
191+
for (i = 0; i < error_spy.args.length; i++) {
192+
try {
193+
expect(error_spy.args[i][0]).to.be.a('string');
194+
expect(error_spy.args[i][0]).to.startWith('StackStorm event stream error: Event { type: \'error\', status: 401 }');
195+
break;
196+
} catch (err) {
197+
// If we have reached the last call and we still haven't found it
198+
if (i >= error_spy.args.length-1) {
199+
// Re-throw the assert exception
200+
throw(err);
201+
}
202+
// Implicit continue
203+
}
204+
}
205+
206+
// Check that it was called at some point with 'Failed to retrieve commands from'
207+
for (i = 0; i < error_spy.args.length; i++) {
208+
try {
209+
expect(error_spy.args[i][0]).to.be.a('string');
210+
expect(error_spy).to.have.been.calledWith('Implicitly attempting to reconnect to StackStorm event stream.');
211+
break;
212+
} catch (err) {
213+
// If we have reached the last call and we still haven't found it
214+
if (i >= error_spy.args.length-1) {
215+
// Re-throw the assert exception
216+
throw(err);
217+
}
218+
// Implicit continue
219+
}
220+
}
158221

159222
stop({shutdown: true});
160223

0 commit comments

Comments
 (0)