|
|
|
@ -1,24 +1,26 @@ |
|
|
|
|
import {describe, beforeEach, it, expect, angularMocks} from 'test/lib/common'; |
|
|
|
|
import { describe, beforeEach, it, expect, angularMocks } from 'test/lib/common'; |
|
|
|
|
import moment from 'moment'; |
|
|
|
|
import helpers from 'test/specs/helpers'; |
|
|
|
|
import {MssqlDatasource} from '../datasource'; |
|
|
|
|
import {CustomVariable} from 'app/features/templating/custom_variable'; |
|
|
|
|
import { MssqlDatasource } from '../datasource'; |
|
|
|
|
import { CustomVariable } from 'app/features/templating/custom_variable'; |
|
|
|
|
|
|
|
|
|
describe('MSSQLDatasource', function() { |
|
|
|
|
var ctx = new helpers.ServiceTestContext(); |
|
|
|
|
var instanceSettings = {name: 'mssql'}; |
|
|
|
|
var instanceSettings = { name: 'mssql' }; |
|
|
|
|
|
|
|
|
|
beforeEach(angularMocks.module('grafana.core')); |
|
|
|
|
beforeEach(angularMocks.module('grafana.services')); |
|
|
|
|
beforeEach(ctx.providePhase(['backendSrv'])); |
|
|
|
|
|
|
|
|
|
beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) { |
|
|
|
|
ctx.$q = $q; |
|
|
|
|
ctx.$httpBackend = $httpBackend; |
|
|
|
|
ctx.$rootScope = $rootScope; |
|
|
|
|
ctx.ds = $injector.instantiate(MssqlDatasource, {instanceSettings: instanceSettings}); |
|
|
|
|
$httpBackend.when('GET', /\.html$/).respond(''); |
|
|
|
|
})); |
|
|
|
|
beforeEach( |
|
|
|
|
angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) { |
|
|
|
|
ctx.$q = $q; |
|
|
|
|
ctx.$httpBackend = $httpBackend; |
|
|
|
|
ctx.$rootScope = $rootScope; |
|
|
|
|
ctx.ds = $injector.instantiate(MssqlDatasource, { instanceSettings: instanceSettings }); |
|
|
|
|
$httpBackend.when('GET', /\.html$/).respond(''); |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
describe('When performing annotationQuery', function() { |
|
|
|
|
let results; |
|
|
|
@ -28,12 +30,12 @@ describe('MSSQLDatasource', function() { |
|
|
|
|
const options = { |
|
|
|
|
annotation: { |
|
|
|
|
name: annotationName, |
|
|
|
|
rawQuery: 'select time, text, tags from table;' |
|
|
|
|
rawQuery: 'select time, text, tags from table;', |
|
|
|
|
}, |
|
|
|
|
range: { |
|
|
|
|
from: moment(1432288354), |
|
|
|
|
to: moment(1432288401) |
|
|
|
|
} |
|
|
|
|
to: moment(1432288401), |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const response = { |
|
|
|
@ -42,23 +44,25 @@ describe('MSSQLDatasource', function() { |
|
|
|
|
refId: annotationName, |
|
|
|
|
tables: [ |
|
|
|
|
{ |
|
|
|
|
columns: [{text: 'time'}, {text: 'text'}, {text: 'tags'}], |
|
|
|
|
columns: [{ text: 'time' }, { text: 'text' }, { text: 'tags' }], |
|
|
|
|
rows: [ |
|
|
|
|
[1432288355, 'some text', 'TagA,TagB'], |
|
|
|
|
[1432288390, 'some text2', ' TagB , TagC'], |
|
|
|
|
[1432288400, 'some text3'] |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
[1521546171129, 'some text', 'TagA,TagB'], |
|
|
|
|
[1521546531404, 'some text2', ' TagB , TagC'], |
|
|
|
|
[1521546901702, 'some text3'], |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
beforeEach(function() { |
|
|
|
|
ctx.backendSrv.datasourceRequest = function(options) { |
|
|
|
|
return ctx.$q.when({data: response, status: 200}); |
|
|
|
|
return ctx.$q.when({ data: response, status: 200 }); |
|
|
|
|
}; |
|
|
|
|
ctx.ds.annotationQuery(options).then(function(data) { results = data; }); |
|
|
|
|
ctx.ds.annotationQuery(options).then(function(data) { |
|
|
|
|
results = data; |
|
|
|
|
}); |
|
|
|
|
ctx.$rootScope.$apply(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -83,28 +87,26 @@ describe('MSSQLDatasource', function() { |
|
|
|
|
results: { |
|
|
|
|
tempvar: { |
|
|
|
|
meta: { |
|
|
|
|
rowCount: 3 |
|
|
|
|
rowCount: 3, |
|
|
|
|
}, |
|
|
|
|
refId: 'tempvar', |
|
|
|
|
tables: [ |
|
|
|
|
{ |
|
|
|
|
columns: [{text: 'title'}, {text: 'text'}], |
|
|
|
|
rows: [ |
|
|
|
|
['aTitle', 'some text'], |
|
|
|
|
['aTitle2', 'some text2'], |
|
|
|
|
['aTitle3', 'some text3'] |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
columns: [{ text: 'title' }, { text: 'text' }], |
|
|
|
|
rows: [['aTitle', 'some text'], ['aTitle2', 'some text2'], ['aTitle3', 'some text3']], |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
beforeEach(function() { |
|
|
|
|
ctx.backendSrv.datasourceRequest = function(options) { |
|
|
|
|
return ctx.$q.when({data: response, status: 200}); |
|
|
|
|
return ctx.$q.when({ data: response, status: 200 }); |
|
|
|
|
}; |
|
|
|
|
ctx.ds.metricFindQuery(query).then(function(data) { results = data; }); |
|
|
|
|
ctx.ds.metricFindQuery(query).then(function(data) { |
|
|
|
|
results = data; |
|
|
|
|
}); |
|
|
|
|
ctx.$rootScope.$apply(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -122,28 +124,26 @@ describe('MSSQLDatasource', function() { |
|
|
|
|
results: { |
|
|
|
|
tempvar: { |
|
|
|
|
meta: { |
|
|
|
|
rowCount: 3 |
|
|
|
|
rowCount: 3, |
|
|
|
|
}, |
|
|
|
|
refId: 'tempvar', |
|
|
|
|
tables: [ |
|
|
|
|
{ |
|
|
|
|
columns: [{text: '__value'}, {text: '__text'}], |
|
|
|
|
rows: [ |
|
|
|
|
['value1', 'aTitle'], |
|
|
|
|
['value2', 'aTitle2'], |
|
|
|
|
['value3', 'aTitle3'] |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
columns: [{ text: '__value' }, { text: '__text' }], |
|
|
|
|
rows: [['value1', 'aTitle'], ['value2', 'aTitle2'], ['value3', 'aTitle3']], |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
beforeEach(function() { |
|
|
|
|
ctx.backendSrv.datasourceRequest = function(options) { |
|
|
|
|
return ctx.$q.when({data: response, status: 200}); |
|
|
|
|
return ctx.$q.when({ data: response, status: 200 }); |
|
|
|
|
}; |
|
|
|
|
ctx.ds.metricFindQuery(query).then(function(data) { results = data; }); |
|
|
|
|
ctx.ds.metricFindQuery(query).then(function(data) { |
|
|
|
|
results = data; |
|
|
|
|
}); |
|
|
|
|
ctx.$rootScope.$apply(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -163,28 +163,26 @@ describe('MSSQLDatasource', function() { |
|
|
|
|
results: { |
|
|
|
|
tempvar: { |
|
|
|
|
meta: { |
|
|
|
|
rowCount: 3 |
|
|
|
|
rowCount: 3, |
|
|
|
|
}, |
|
|
|
|
refId: 'tempvar', |
|
|
|
|
tables: [ |
|
|
|
|
{ |
|
|
|
|
columns: [{text: '__text'}, {text: '__value'}], |
|
|
|
|
rows: [ |
|
|
|
|
['aTitle', 'same'], |
|
|
|
|
['aTitle', 'same'], |
|
|
|
|
['aTitle', 'diff'] |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
columns: [{ text: '__text' }, { text: '__value' }], |
|
|
|
|
rows: [['aTitle', 'same'], ['aTitle', 'same'], ['aTitle', 'diff']], |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
beforeEach(function() { |
|
|
|
|
ctx.backendSrv.datasourceRequest = function(options) { |
|
|
|
|
return ctx.$q.when({data: response, status: 200}); |
|
|
|
|
return ctx.$q.when({ data: response, status: 200 }); |
|
|
|
|
}; |
|
|
|
|
ctx.ds.metricFindQuery(query).then(function(data) { results = data; }); |
|
|
|
|
ctx.ds.metricFindQuery(query).then(function(data) { |
|
|
|
|
results = data; |
|
|
|
|
}); |
|
|
|
|
ctx.$rootScope.$apply(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -197,7 +195,7 @@ describe('MSSQLDatasource', function() { |
|
|
|
|
|
|
|
|
|
describe('When interpolating variables', () => { |
|
|
|
|
beforeEach(function() { |
|
|
|
|
ctx.variable = new CustomVariable({},{}); |
|
|
|
|
ctx.variable = new CustomVariable({}, {}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('and value is a string', () => { |
|
|
|
@ -214,23 +212,22 @@ describe('MSSQLDatasource', function() { |
|
|
|
|
|
|
|
|
|
describe('and value is an array of strings', () => { |
|
|
|
|
it('should return comma separated quoted values', () => { |
|
|
|
|
expect(ctx.ds.interpolateVariable(['a', 'b', 'c'], ctx.variable)).to.eql('\'a\',\'b\',\'c\''); |
|
|
|
|
expect(ctx.ds.interpolateVariable(['a', 'b', 'c'], ctx.variable)).to.eql("'a','b','c'"); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('and variable allows multi-value and value is a string', () => { |
|
|
|
|
it('should return a quoted value', () => { |
|
|
|
|
ctx.variable.multi = true; |
|
|
|
|
expect(ctx.ds.interpolateVariable('abc', ctx.variable)).to.eql('\'abc\''); |
|
|
|
|
expect(ctx.ds.interpolateVariable('abc', ctx.variable)).to.eql("'abc'"); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('and variable allows all and value is a string', () => { |
|
|
|
|
it('should return a quoted value', () => { |
|
|
|
|
ctx.variable.includeAll = true; |
|
|
|
|
expect(ctx.ds.interpolateVariable('abc', ctx.variable)).to.eql('\'abc\''); |
|
|
|
|
expect(ctx.ds.interpolateVariable('abc', ctx.variable)).to.eql("'abc'"); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|