Remove parseAlerta
parent
928be9877c
commit
9cb793e66f
|
@ -1,46 +0,0 @@
|
|||
import {parseAlerta} from 'shared/parsing/parseAlerta'
|
||||
|
||||
it('can parse an alerta tick script', () => {
|
||||
const tickScript = `stream
|
||||
|alert()
|
||||
.alerta()
|
||||
.resource('Hostname or service')
|
||||
.event('Something went wrong')
|
||||
.environment('Development')
|
||||
.group('Dev. Servers')
|
||||
.services('a b c')
|
||||
`
|
||||
|
||||
let actualObj = parseAlerta(tickScript)
|
||||
|
||||
const expectedObj = [
|
||||
{
|
||||
name: 'resource',
|
||||
args: ['Hostname or service'],
|
||||
},
|
||||
{
|
||||
name: 'event',
|
||||
args: ['Something went wrong'],
|
||||
},
|
||||
{
|
||||
name: 'environment',
|
||||
args: ['Development'],
|
||||
},
|
||||
{
|
||||
name: 'group',
|
||||
args: ['Dev. Servers'],
|
||||
},
|
||||
{
|
||||
name: 'services',
|
||||
args: ['a', 'b', 'c'],
|
||||
},
|
||||
]
|
||||
|
||||
// Test data structure
|
||||
expect(actualObj).to.deep.equal(expectedObj)
|
||||
|
||||
// Test that data structure is the same if fed back in
|
||||
const expectedStr = `alerta().resource('Hostname or service').event('Something went wrong').environment('Development').group('Dev. Servers').services('a b c')`
|
||||
actualObj = parseAlerta(expectedStr)
|
||||
expect(actualObj).to.deep.equal(expectedObj)
|
||||
})
|
|
@ -1,21 +0,0 @@
|
|||
const alertaRegex = /(services)\('(.+?)'\)|(resource)\('(.+?)'\)|(event)\('(.+?)'\)|(environment)\('(.+?)'\)|(group)\('(.+?)'\)|(origin)\('(.+?)'\)|(token)\('(.+?)'\)/gi
|
||||
|
||||
export function parseAlerta(string) {
|
||||
const properties = []
|
||||
let match
|
||||
|
||||
while ((match = alertaRegex.exec(string))) {
|
||||
// eslint-disable-line no-cond-assign
|
||||
for (let m = 1; m < match.length; m += 2) {
|
||||
if (match[m]) {
|
||||
properties.push({
|
||||
name: match[m],
|
||||
args:
|
||||
match[m] === 'services' ? match[m + 1].split(' ') : [match[m + 1]],
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return properties
|
||||
}
|
Loading…
Reference in New Issue