-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtestUtilities.js
More file actions
39 lines (35 loc) · 1008 Bytes
/
testUtilities.js
File metadata and controls
39 lines (35 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { ensure } = require('arango-tools')
const { Database } = require('arangojs')
async function ensureDatabase(options) {
let variables
if (options.variables) {
variables = options.variables
variables.name = variables.dbname
} else {
variables = { ...options }
}
const systemDatabase = new Database({ url: variables.url, databaseName: '_system' })
await systemDatabase.login('root', variables.rootPassword)
const databases = await systemDatabase.listDatabases()
if (!databases.includes(variables.name)) {
try {
await systemDatabase.createDatabase(variables.name)
} catch (e) {
console.error(`Failed to create database ${variables.name}: ${e.message}`)
process.exit(1)
}
}
let ensureOptions
if (options.variables) {
ensureOptions = {
variables: options.variables,
schema: { ...options.schema },
}
} else {
ensureOptions = options
}
return await ensure(ensureOptions)
}
module.exports = {
ensureDatabase,
}