Skip to content

Commit 979c3d2

Browse files
Switch on logging with a env var
1 parent ae57bd7 commit 979c3d2

File tree

8 files changed

+40
-30
lines changed

8 files changed

+40
-30
lines changed

selenium/.node-xmlhttprequest-sync-88011

Whitespace-only changes.

selenium/fakeportal/proxy.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var http = require('http'),
22
httpProxy = require('http-proxy');
3+
const {log, error} = require('./utils.js')
34
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest
45

56
const rabbitmq_url = process.env.RABBITMQ_URL || 'http://0.0.0.0:15672/';
@@ -14,7 +15,7 @@ const port = process.env.PORT;
1415
var proxy = httpProxy.createProxyServer({});
1516

1617
proxy.on('proxyReq', function(proxyReq, req, res, options) {
17-
console.log("proxing " + req.url)
18+
log("proxing " + req.url)
1819
if (req.url.endsWith("bootstrap.js")) {
1920
proxyReq.setHeader('Authorization', 'Bearer ' + access_token(client_id, client_secret));
2021
}
@@ -30,7 +31,7 @@ var server = http.createServer(function(req, res) {
3031
target: rabbitmq_url
3132
});
3233
});
33-
console.log("fakeproxy listening on port " + port + ". RABBITMQ_URL=" + rabbitmq_url)
34+
log("fakeproxy listening on port " + port + ". RABBITMQ_URL=" + rabbitmq_url)
3435
server.listen(port);
3536

3637

@@ -51,18 +52,19 @@ function access_token(id, secret) {
5152
'&token_format=jwt' +
5253
'&response_type=token';
5354

54-
console.debug("Sending " + url + " with params "+ params);
55+
log("Sending " + url + " with params "+ params);
5556

5657
req.open('POST', url, false);
5758
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
5859
req.setRequestHeader('Accept', 'application/json');
5960
req.send(params);
60-
console.log("Ret " + req.status)
61+
log("Ret " + req.status)
6162
if (req.status == 200) {
6263
const token = JSON.parse(req.responseText).access_token;
63-
console.log("Token => " + token)
64+
log("Token => " + token)
6465
return token;
6566
} else {
67+
error("Failed to get access token due to " + req.responseText)
6668
throw new Error(req.status + " : " + req.responseText);
6769
}
6870
}

selenium/test/amqp.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var container = require('rhea') // https://github.com/amqp/rhea
22
var fs = require('fs');
33
var path = require('path');
4+
const {log, error} = require('./utils.js')
5+
46
var connectionOptions = getConnectionOptions()
57

68
function getAmqpConnectionOptions() {
@@ -28,7 +30,7 @@ function getAmqpsConnectionOptions() {
2830
}
2931
function getConnectionOptions() {
3032
let scheme = process.env.RABBITMQ_AMQP_SCHEME || 'amqp'
31-
console.log("Using AMQP protocol: " + scheme)
33+
log("Using AMQP protocol: " + scheme)
3234
switch(scheme){
3335
case "amqp":
3436
return getAmqpConnectionOptions()

selenium/test/authnz-msg-protocols/amqp10.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const assert = require('assert')
2-
const { tokenFor, openIdConfiguration } = require('../utils')
2+
const { log, tokenFor, openIdConfiguration } = require('../utils')
33
const { reset, expectUser, expectVhost, expectResource, allow, verifyAll } = require('../mock_http_backend')
44
const { open: openAmqp, once: onceAmqp, on: onAmqp, close: closeAmqp } = require('../amqp')
55

@@ -48,11 +48,11 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' +
4848
let oauthProviderUrl = process.env.OAUTH_PROVIDER_URL
4949
let oauthClientId = process.env.OAUTH_CLIENT_ID
5050
let oauthClientSecret = process.env.OAUTH_CLIENT_SECRET
51-
console.log("oauthProviderUrl : " + oauthProviderUrl)
51+
log("oauthProviderUrl : " + oauthProviderUrl)
5252
let openIdConfig = openIdConfiguration(oauthProviderUrl)
53-
console.log("Obtained token_endpoint : " + openIdConfig.token_endpoint)
53+
log("Obtained token_endpoint : " + openIdConfig.token_endpoint)
5454
password = tokenFor(oauthClientId, oauthClientSecret, openIdConfig.token_endpoint)
55-
console.log("Obtained access token : " + password)
55+
log("Obtained access token : " + password)
5656
}
5757
})
5858

@@ -78,7 +78,7 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' +
7878
closeAmqp(amqp.connection)
7979
}
8080
} catch (error) {
81-
console.error("Failed to close amqp10 connection due to " + error);
81+
error("Failed to close amqp10 connection due to " + error);
8282
}
8383
})
8484
})

selenium/test/authnz-msg-protocols/mqtt.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs')
22
const assert = require('assert')
3-
const { tokenFor, openIdConfiguration } = require('../utils')
3+
const { tokenFor, openIdConfiguration, log } = require('../utils')
44
const { reset, expectUser, expectVhost, expectResource, allow, verifyAll } = require('../mock_http_backend')
55
const mqtt = require('mqtt');
66

@@ -45,9 +45,9 @@ describe('Having MQTT protocol enbled and the following auth_backends: ' + backe
4545
let oauthClientId = process.env.OAUTH_CLIENT_ID
4646
let oauthClientSecret = process.env.OAUTH_CLIENT_SECRET
4747
let openIdConfig = openIdConfiguration(oauthProviderUrl)
48-
console.log("Obtained token_endpoint : " + openIdConfig.token_endpoint)
48+
log("Obtained token_endpoint : " + openIdConfig.token_endpoint)
4949
password = tokenFor(oauthClientId, oauthClientSecret, openIdConfig.token_endpoint)
50-
console.log("Obtained access token : " + password)
50+
log("Obtained access token : " + password)
5151
}
5252
mqttOptions = {
5353
clientId: client_id,

selenium/test/exchanges/management.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { By, Key, until, Builder } = require('selenium-webdriver')
22
require('chromedriver')
33
const assert = require('assert')
4-
const { buildDriver, goToHome, captureScreensFor, teardown, doWhile } = require('../utils')
4+
const { buildDriver, goToHome, captureScreensFor, teardown, doWhile, log } = require('../utils')
55

66
const LoginPage = require('../pageobjects/LoginPage')
77
const OverviewPage = require('../pageobjects/OverviewPage')
@@ -56,7 +56,6 @@ describe('Exchange management', function () {
5656
["other", "amq.topic", "topic"]
5757
]
5858

59-
console.log("e :" + actual_table)
6059
assert.deepEqual(actual_table, expected_table)
6160
})
6261

selenium/test/pageobjects/BasePage.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = class BasePage {
5656
}
5757

5858
async clickOnOverviewTab () {
59-
return this.click(CONNECTIONS_TAB)
59+
return this.click(OVERVIEW_TAB)
6060
}
6161

6262
async clickOnConnectionsTab () {
@@ -363,9 +363,6 @@ module.exports = class BasePage {
363363
await this.driver.sleep(250)
364364
return alert.accept();
365365
}
366-
log(message) {
367-
console.log(new Date() + " " + message)
368-
}
369366

370367
capture () {
371368
this.driver.takeScreenshot().then(

selenium/test/utils.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const hostname = process.env.RABBITMQ_HOSTNAME || 'localhost'
1717
const seleniumUrl = process.env.SELENIUM_URL || 'http://selenium:4444'
1818
const screenshotsDir = process.env.SCREENSHOTS_DIR || '/screens'
1919
const profiles = process.env.PROFILES || ''
20+
const debug = process.env.DEBUG || false
2021

2122
function randomly_pick_baseurl(baseUrl) {
2223
urls = baseUrl.split(",")
@@ -46,7 +47,7 @@ class CaptureScreenshot {
4647

4748
module.exports = {
4849
log: (message) => {
49-
console.log(new Date() + " " + message)
50+
if (debug) console.log(new Date() + " " + message)
5051
},
5152
error: (message) => {
5253
console.error(new Date() + " " + message)
@@ -103,8 +104,9 @@ module.exports = {
103104
}
104105
},
105106

106-
goToHome: (driver) => {
107-
return driver.get(baseUrl)
107+
goToHome: (driver, url = baseUrl) => {
108+
module.exports.log("goToHome on " + url)
109+
return driver.get(url)
108110
},
109111

110112
goToLogin: (driver, token) => {
@@ -135,16 +137,16 @@ module.exports = {
135137
let ret
136138
do {
137139
try {
138-
//console.log("Calling doCallback (attempts:" + attempts + ") ... ")
140+
module.exports.log("Calling doCallback (attempts:" + attempts + ") ... ")
139141
ret = await doCallback()
140-
//console.log("Calling booleanCallback (attempts:" + attempts + ") with arg " + ret + " ... ")
142+
module.exports.log("Calling booleanCallback (attempts:" + attempts + ") with arg " + ret + " ... ")
141143
done = booleanCallback(ret)
142144
}catch(error) {
143-
console.log("Caught " + error + " on doWhile callback...")
145+
module.exports.error("Caught " + error + " on doWhile callback...")
144146

145147
}finally {
146148
if (!done) {
147-
//console.log("Waiting until next attempt")
149+
module.exports.log("Waiting until next attempt")
148150
await module.exports.delay(delayMs)
149151
}
150152
}
@@ -179,7 +181,7 @@ module.exports = {
179181
req.send()
180182
if (req.status == 200) return JSON.parse(req.responseText)
181183
else {
182-
console.error(req.responseText)
184+
module.exports.error(req.responseText)
183185
throw new Error(req.responseText)
184186
}
185187
},
@@ -198,7 +200,7 @@ module.exports = {
198200
req.send(params)
199201
if (req.status == 200) return JSON.parse(req.responseText).access_token
200202
else {
201-
console.error(req.responseText)
203+
module.exports.error(req.responseText)
202204
throw new Error(req.responseText)
203205
}
204206
},
@@ -215,7 +217,7 @@ module.exports = {
215217
teardown: async (driver, test, captureScreen = null) => {
216218
driver.manage().logs().get(logging.Type.BROWSER).then(function(entries) {
217219
entries.forEach(function(entry) {
218-
console.log('[%s] %s', entry.level.name, entry.message);
220+
module.exports.log('[%s] %s', entry.level.name, entry.message);
219221
})
220222
})
221223
if (test.currentTest) {
@@ -227,6 +229,14 @@ module.exports = {
227229
}
228230
}
229231
await driver.quit()
232+
},
233+
234+
findTableRow: (table, booleanCallback) => {
235+
if (!table) return false
236+
237+
let i = 0
238+
while (i < table.length && !booleanCallback(table[i])) i++;
239+
return i < table.length ? table[i] : undefined
230240
}
231241

232242
}

0 commit comments

Comments
 (0)