Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test cases related to Firmware Upgrade plugin #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/commonMethods/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default {
provisioningPlugin: 'Provisioning',
dhcpserver: 'DHCPServer',
traceControlPlugin: 'TraceControl',
firmwareUpgradePlugin: 'FirmwareControl',
WPEProcess: 'WPEProcess',
remoteControlPlugin: 'RemoteControl',
invalidAddress: 'invalidstring',
Expand Down
30 changes: 30 additions & 0 deletions src/commonMethods/firmwarecontrol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* This function is used to upgrade the firmware
* @param name
* @param location
* @param type
* @param progressinterval
* @param hmac
* @returns {Promise<T>}
*/
export const firmwareUpgrade = function(name, location, type, progressinterval, hmac) {
return this.$thunder.api.FirmwareControl.upgrade({
name: name,
location: location,
type: type,
progressinterval: progressinterval,
hmac: hmac,
})
.then(result => result)
.catch(err => err)
}

/**
* This function is used to get the status of firmware upgrade
* @returns {Promise<T>}
*/
export const upgradeStatus = function() {
return this.$thunder.api.FirmwareControl.status()
.then(result => result)
.catch(err => err)
}
80 changes: 80 additions & 0 deletions src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_001.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { firmwareUpgrade, upgradeStatus } from '../../commonMethods/firmwarecontrol'
import { pluginActivate, pluginDeactivate } from '../../commonMethods/controller'
import constants from '../../commonMethods/constants'

let listener

export default {
title: 'Firmware Upgrade - 001',
description: 'Check the Upgrade of the device to the specified firmware',
context: {
state: 'completed',
},
setup() {
return this.$sequence([
() => pluginDeactivate.call(this, constants.firmwareUpgradePlugin),
() => pluginActivate.call(this, constants.firmwareUpgradePlugin),
() => {
listener = this.$thunder.api.FirmwareControl.on(
'upgradeprogress',
data => {
this.$data.write('upgradeStatus', data.status)
},
e => {
this.$log('Error subscribing to upgradeprogress: ', e)
}
)
return true
},
])
},
steps: [
{
description: 'Upgrade the firmware and check whether it is completed',
sleep: 5,
test() {
//TODO - Update the test to enter the 'name', 'location', 'type', 'progressinterval', 'hmac' through User prompt
return firmwareUpgrade.call(this, 'name', 'location', 'type', 'progressinterval', 'hmac')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to merge this already or wait for an ability to fill this in with meaningful values?

},
validate(res) {
if (res == null) {
return true
} else {
throw new Error(`FirmwareUpgrade is not invoked properly and the result is ${res}`)
}
},
},
{
description: 'Sleep until Completed event is detected',
sleep() {
// Purpose of this sleep is to wait until current step gets 'upgradeprogress' response from the listener
return new Promise((resolve, reject) => {
let attempts = 0
const interval = setInterval(() => {
attempts++
if (this.$data.read('upgradeStatus') === this.$context.read('state')) {
clearInterval(interval)
setTimeout(resolve, 5000) //give it some time to load
} else if (attempts > 100) {
clearInterval(interval)
reject('Upgrade Not completed')
}
}, 1000)
})
},
},
{
description: 'Get Upgrade Status and validate the result',
test() {
return upgradeStatus.call(this)
},
validate(res) {
if (res == 'completed') {
return true
} else {
throw new Error('Firmware upgrade not completed successfully')
}
},
},
],
}
34 changes: 34 additions & 0 deletions src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_002.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { firmwareUpgrade } from '../../commonMethods/firmwarecontrol'
import { pluginActivate, pluginDeactivate } from '../../commonMethods/controller'
import constants from '../../commonMethods/constants'

export default {
title: 'Firmware Upgrade - 002',
description: 'Check the upgrade Functionality when upgrade is already in progress',
setup() {
return this.$sequence([
() => pluginDeactivate.call(this, constants.firmwareUpgradePlugin),
() => pluginActivate.call(this, constants.firmwareUpgradePlugin),
])
},
steps: [
{
description:
'Invoke Upgrade firmware when already firmware upgrade in progres and validate the result',
sleep: 5,
test() {
//TODO - Update the test to enter the 'name', 'location', 'type', 'progressinterval', 'hmac' through User prompt
firmwareUpgrade.call(this, 'name', 'location', 'type', 'progressinterval', 'hmac')
return firmwareUpgrade.call(this, 'name', 'location', 'type', 'progressinterval', 'hmac')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to use promise.all to run 2 promises in parallel, for reference:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all

And same here, guess we wait until we can fill in something meaninful to avoid false negative results?

},
validate(res) {
if (res.code === 12 && res.message === 'ERROR_INPROGRESS') {
return true
} else {
this.$log('Proper error message is not shown')
return false
}
},
},
],
}
42 changes: 42 additions & 0 deletions src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_003.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { firmwareUpgrade } from '../../commonMethods/firmwarecontrol'
import { pluginActivate, pluginDeactivate } from '../../commonMethods/controller'
import constants from '../../commonMethods/constants'

export default {
title: 'Firmware Upgrade - 002',
description: 'Check the upgrade Functionality when upgrade is already in progress',
context: {
invalidURL: 'incorrectURL',
},
setup() {
return this.$sequence([
() => pluginDeactivate.call(this, constants.firmwareUpgradePlugin),
() => pluginActivate.call(this, constants.firmwareUpgradePlugin),
])
},
steps: [
{
description:
'Invoke Upgrade firmware when already firmware upgrade in progres and validate the result',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to update description

sleep: 5,
test() {
return firmwareUpgrade.call(
this,
'firmware_v.0',
this.$context.read('invalidURL'),
'CDL',
'10',
'hmac'
)
},
validate(res) {
if (res.code === 15 && res.message === 'ERROR_INCORRECT_URL') {
return true
} else {
this.$log('Proper error message is not shown')
return false
}
},
},
],
}