Skip to content

Commit

Permalink
Merge pull request #4094 from owncloud/improve-error-handling
Browse files Browse the repository at this point in the history
[Tests-Only] Improve error handling in tests and update ocis commit id
  • Loading branch information
individual-it authored Sep 23, 2020
2 parents dd6ec7a + af75295 commit 2f6dae6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ config = {
'defaults': {
'acceptance': {
'ocisBranch': 'master',
'ocisCommit': '0c6478c9350f56ff6d7c402b5d9d60a68b0f6f75',
'ocisCommit': '7b8e9bc2981c0fd9917bc576a291ab5231c02685',
}
},

Expand Down
15 changes: 9 additions & 6 deletions tests/acceptance/helpers/httpHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,32 @@ const createOCSRequestHeaders = function(userId) {
* @throws Error
* @returns {node-fetch.Response}
*/
const checkStatus = function(response, message) {
const checkStatus = function(response, message = '') {
if (response.ok) {
// response.status >= 200 && response.status < 300
return response
} else {
throw Error(message + ' Status:' + response.status + ' ' + response.statusText)
throw Error(
`HTTP Request Failed: ${message}, Status: ${response.status} ${response.statusCode}`
)
}
}

/**
*
* @param {node-fetch.Response} response
* @param {Object} response the response body in json
* @param {string} message
*
* @throws Error
* @returns {node-fetch.Response}
* @returns {Object} the body of the response
*/
const checkOCSStatus = function(response, message) {
const checkOCSStatus = async function(response, message = '') {
const statusCode = _.get(response, 'ocs.meta.statuscode')
const ocsMessage = _.get(response, 'ocs.meta.message')
if (statusCode === 200) {
return response
} else {
throw Error(message + ' Status:' + statusCode)
throw Error(`OCS Request Failed: ${message}, Status: ${statusCode}, Message: ${ocsMessage}`)
}
}

Expand Down
18 changes: 15 additions & 3 deletions tests/acceptance/stepDefinitions/generalContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Given(
)

const getConfigJsonContent = function(fullPathOfConfigFile) {
if (!fs.existsSync(fullPathOfConfigFile)) {
throw Error('Could not find configfile')
}
const rawdata = fs.readFileSync(fullPathOfConfigFile)
return JSON.parse(rawdata)
}
Expand Down Expand Up @@ -265,12 +268,21 @@ After(async function(testCase) {
})

Before(function() {
this.fullPathOfConfigFile = client.globals.phoenix_config
initialConfigJsonSettings = getConfigJsonContent(client.globals.phoenix_config)
try {
this.fullPathOfConfigFile = client.globals.phoenix_config
initialConfigJsonSettings = getConfigJsonContent(client.globals.phoenix_config)
} catch (err) {
console.log(
'\x1b[33m%s\x1b[0m',
`\tCould not read config file.\n\tSet correct path of config file in PHOENIX_CONFIG env variable to fix this.\n\tSome tests may fail as a result.`
)
}
})

After(function() {
fs.writeFileSync(this.fullPathOfConfigFile, JSON.stringify(initialConfigJsonSettings, null, 4))
if (initialConfigJsonSettings) {
fs.writeFileSync(this.fullPathOfConfigFile, JSON.stringify(initialConfigJsonSettings, null, 4))
}
})

Given('the app {string} has been disabled', function(app) {
Expand Down
3 changes: 3 additions & 0 deletions tests/acceptance/stepDefinitions/provisioningContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function createUser(userId, password, displayName = false, email = false) {
const url = 'cloud/users'
return httpHelper
.postOCS(url, 'admin', body)
.then(res => httpHelper.checkStatus(res, 'Failed while creating user'))
.then(res => res.json())
.then(res => httpHelper.checkOCSStatus(res, 'Failed while creating user'))
.then(() => {
if (client.globals.ocis) {
const skelDir = client.globals.ocis_skeleton_dir
Expand Down

0 comments on commit 2f6dae6

Please sign in to comment.