Skip to content

Commit

Permalink
feat(corellium): CORE-5555 - add corellium getInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
judy committed Dec 7, 2023
1 parent fa5b107 commit 96aca44
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/corellium.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,36 @@ class Corellium {
method: 'DELETE'
})
}

/**
* Attempts to retrieve Instance by iterating through all projects until the instance is found.
*
* @param {string} instanceId
* @returns {Promise<Instance>}
* @example
* await corellium.instance('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
*/
async getInstance (instanceId) {
let lastError
const projects = await this.projects()
for (const project of projects) {
try {
const instance = await project.getInstance(instanceId)
if (instance.info.state !== 'on') {
throw new Error('The instance is not turned on')
}
return instance
} catch (err) {
if (!(err instanceof CorelliumError)) {
throw err
} else {
lastError = err
}
}
}

throw lastError || new Error(`Could not retrieve instance! instanceId=${instanceId}`)
}
}

module.exports = {
Expand Down
7 changes: 7 additions & 0 deletions test/integration-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ describe('Corellium API', function () {
assert(roles, 'Roles should not be undefined, even if there have been no roles')
})

it('can get instance', async function () {
const instance = instanceMap.get(INSTANCE_VERSIONS[0])
await instance.waitForState('on')
const foundInstance = await corellium.getInstance(instance.id)
assert(foundInstance.id === instance.id)
})

// Not visible to cloud users with one project:
it('can add and remove keys', async function () {
const keyInfo = await project
Expand Down

0 comments on commit 96aca44

Please sign in to comment.