2021-04-13 15:13:41 +00:00
|
|
|
import { getProsodyConfigContent, getProsodyConfigPath, getWorkingDir } from '../prosody/config'
|
2021-04-12 15:53:12 +00:00
|
|
|
import { newResult, TestResult } from './utils'
|
2021-04-13 15:13:41 +00:00
|
|
|
import * as fs from 'fs'
|
2021-04-12 15:53:12 +00:00
|
|
|
|
2021-04-12 18:52:21 +00:00
|
|
|
export async function diagProsody (test: string, options: RegisterServerOptions): Promise<TestResult> {
|
2021-04-12 15:53:12 +00:00
|
|
|
const result = newResult(test)
|
|
|
|
result.label = 'Builtin Prosody and ConverseJS'
|
2021-04-12 18:52:21 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
const dir = await getWorkingDir(options)
|
|
|
|
result.messages.push('The working dir is: ' + dir)
|
|
|
|
} catch (error) {
|
|
|
|
result.messages.push('Error when requiring the working dir: ' + (error as string))
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-04-13 15:13:41 +00:00
|
|
|
// Testing the prosody config file.
|
|
|
|
try {
|
|
|
|
const filePath = await getProsodyConfigPath(options)
|
|
|
|
await fs.promises.access(filePath, fs.constants.R_OK) // throw an error if file does not exist.
|
|
|
|
result.messages.push(`The prosody configuration file (${filePath}) exists`)
|
|
|
|
const actualContent = await fs.promises.readFile(filePath, {
|
|
|
|
encoding: 'utf-8'
|
|
|
|
})
|
|
|
|
const wantedContent = await getProsodyConfigContent(options)
|
|
|
|
if (actualContent === wantedContent) {
|
|
|
|
result.messages.push('Prosody configuration file content is correct.')
|
|
|
|
} else {
|
|
|
|
result.messages.push('Prosody configuration file content is not correct.')
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
result.messages.push('Error when requiring the prosody config file: ' + (error as string))
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-04-12 18:52:21 +00:00
|
|
|
result.ok = true
|
2021-04-12 15:53:12 +00:00
|
|
|
return result
|
|
|
|
}
|