1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 02:09:32 +02:00

Add a new command to generate fake devices for testing.

This commit is contained in:
Simo Kinnunen 2014-06-04 18:56:56 +09:00
parent 1c45b6eb70
commit 6acfa5b528
2 changed files with 86 additions and 0 deletions

View file

@ -549,6 +549,39 @@ program
})
})
program
.command('generate-fake-device')
.description('generates a fake device for testing')
.option('-n, --number <n>'
, 'how many devices to create (defaults to 1)'
, Number
, 1)
.action(function(options) {
var log = logger.createLogger('cli:generate-fake-device')
, fake = require('./util/fakedevice')
, n = options.number
function next() {
return fake.generate()
.then(function(serial) {
log.info('Created fake device "%s"', serial)
if (--n) {
return next()
}
})
}
next()
.then(function() {
process.exit(0)
})
.catch(function(err) {
log.fatal('Fake device creation had an error:', err.stack)
process.exit(1)
})
})
program
.command('local [serial..]')
.description('start everything locally')

53
lib/util/fakedevice.js Normal file
View file

@ -0,0 +1,53 @@
var util = require('util')
var uuid = require('node-uuid')
var dbapi = require('../db/api')
module.exports.generate = function() {
var serial = util.format(
'fake-%s'
, uuid.v4(null, new Buffer(16)).toString('base64')
)
return dbapi.saveDevice(serial, {
provider: {
name: 'FAKE/1'
, channel: '*fake'
}
, status: 'OFFLINE'
})
.then(function() {
return dbapi.saveDeviceIdentity(serial, {
platform: 'Android'
, manufacturer: 'Foo Electronics'
, operator: 'Loss Networks'
, model: 'F00'
, version: '4.1.2'
, abi: 'armeabi-v7a'
, sdk: 8 + Math.floor(Math.random() * 12)
, display: {
density: 3
, fps: 60
, height: 1920
, id: 0
, orientation: 0
, secure: true
, url: '/404.jpg'
, width: 1080
, xdpi: 442
, ydpi: 439
}
, phone: {
iccid: '1234567890123456789'
, imei: '123456789012345'
, network: 'LTE'
, phoneNumber: '0000000000'
}
})
})
.then(function() {
return dbapi.setDeviceAbsent(serial)
})
.return(serial)
}