Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
bd417bed
Commit
bd417bed
authored
Jul 03, 2018
by
Tobias Skarhed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start elastic ds test conversion
parent
a8970a4d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
53 deletions
+67
-53
public/app/plugins/datasource/elasticsearch/specs/datasource.jest.ts
+67
-53
No files found.
public/app/plugins/datasource/elasticsearch/specs/datasource
_specs
.ts
→
public/app/plugins/datasource/elasticsearch/specs/datasource
.jest
.ts
View file @
bd417bed
...
...
@@ -2,31 +2,45 @@ import _ from 'lodash';
import
{
describe
,
beforeEach
,
it
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
moment
from
'moment'
;
import
angular
from
'angular'
;
import
helpers
from
'test/specs/helpers'
;
import
{
ElasticDatasource
}
from
'../datasource'
;
import
{
TimeSrv
}
from
'app/features/dashboard/time_srv'
;
import
$q
from
'q'
;
describe
(
'ElasticDatasource'
,
function
()
{
var
ctx
=
new
helpers
.
ServiceTestContext
();
beforeEach
(
angularMocks
.
module
(
'grafana.core'
));
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
ctx
.
providePhase
([
'templateSrv'
,
'backendSrv'
,
'timeSrv'
]));
beforeEach
(
angularMocks
.
inject
(
function
(
$q
,
$rootScope
,
$httpBackend
,
$injector
)
{
ctx
.
$q
=
$q
;
ctx
.
$httpBackend
=
$httpBackend
;
ctx
.
$rootScope
=
$rootScope
;
ctx
.
$injector
=
$injector
;
$httpBackend
.
when
(
'GET'
,
/
\.
html$/
).
respond
(
''
);
})
);
//var ctx = new helpers.ServiceTestContext();
let
backendSrv
=
{
datasourceRequest
:
jest
.
fn
()
};
let
$rootScope
=
{
$on
:
jest
.
fn
(),
appEvent
:
jest
.
fn
(),
};
let
timeSrv
=
new
TimeSrv
(
$rootScope
,
jest
.
fn
(),{},{},{});
let
ctx
=
<
any
>
{
$rootScope
,
backendSrv
,
$q
};
// beforeEach(angularMocks.module('grafana.core'));
// beforeEach(angularMocks.module('grafana.services'));
// beforeEach(ctx.providePhase(['templateSrv', 'backendSrv', 'timeSrv']));
// beforeEach(
// angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
// ctx.$q = $q;
// ctx.$httpBackend = $httpBackend;
// ctx.$rootScope = $rootScope;
// ctx.$injector = $injector;
// $httpBackend.when('GET', /\.html$/).respond('');
// })
// );
function
createDatasource
(
instanceSettings
)
{
instanceSettings
.
jsonData
=
instanceSettings
.
jsonData
||
{};
ctx
.
ds
=
ctx
.
$injector
.
instantiate
(
ElasticDatasource
,
{
instanceSettings
:
instanceSettings
,
});
ctx
.
ds
=
new
ElasticDatasource
(
instanceSettings
,
{},
backendSrv
,
{
replace
:
jest
.
fn
()
},
timeSrv
);
}
describe
(
'When testing datasource with index pattern'
,
function
()
{
...
...
@@ -40,13 +54,13 @@ describe('ElasticDatasource', function() {
it
(
'should translate index pattern to current day'
,
function
()
{
var
requestOptions
;
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
((
options
)
=>
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({
data
:
{}
});
};
return
Promise
.
resolve
({
data
:
{}
});
}
)
;
ctx
.
ds
.
testDatasource
();
ctx
.
$rootScope
.
$apply
();
//
ctx.$rootScope.$apply();
var
today
=
moment
.
utc
().
format
(
'YYYY.MM.DD'
);
expect
(
requestOptions
.
url
).
to
.
be
(
'http://es.com/asd-'
+
today
+
'/_mapping'
);
...
...
@@ -63,10 +77,10 @@ describe('ElasticDatasource', function() {
jsonData
:
{
interval
:
'Daily'
,
esVersion
:
'2'
},
});
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
((
options
)
=>
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({
data
:
{
responses
:
[]
}
});
};
return
Promise
.
resolve
({
data
:
{
responses
:
[]
}
});
}
)
;
ctx
.
ds
.
query
({
range
:
{
...
...
@@ -82,19 +96,19 @@ describe('ElasticDatasource', function() {
],
});
ctx
.
$rootScope
.
$apply
();
//
ctx.$rootScope.$apply();
parts
=
requestOptions
.
data
.
split
(
'
\
n'
);
header
=
angular
.
fromJson
(
parts
[
0
]);
});
it
(
'should translate index pattern to current day'
,
function
()
{
expect
(
header
.
index
).
to
.
eq
l
([
'asd-2015.05.30'
,
'asd-2015.05.31'
,
'asd-2015.06.01'
]);
expect
(
header
.
index
).
to
Equa
l
([
'asd-2015.05.30'
,
'asd-2015.05.31'
,
'asd-2015.06.01'
]);
});
it
(
'should json escape lucene query'
,
function
()
{
var
body
=
angular
.
fromJson
(
parts
[
1
]);
expect
(
body
.
query
.
bool
.
filter
[
1
].
query_string
.
query
).
to
.
b
e
(
'escape
\\
:test'
);
expect
(
body
.
query
.
bool
.
filter
[
1
].
query_string
.
query
).
to
B
e
(
'escape
\\
:test'
);
});
});
...
...
@@ -108,10 +122,10 @@ describe('ElasticDatasource', function() {
jsonData
:
{
esVersion
:
'2'
},
});
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
((
options
)
=>
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({
data
:
{
responses
:
[]
}
});
};
return
Promise
.
resolve
({
data
:
{
responses
:
[]
}
});
}
)
;
ctx
.
ds
.
query
({
range
:
{
...
...
@@ -127,18 +141,18 @@ describe('ElasticDatasource', function() {
],
});
ctx
.
$rootScope
.
$apply
();
//
ctx.$rootScope.$apply();
parts
=
requestOptions
.
data
.
split
(
'
\
n'
);
header
=
angular
.
fromJson
(
parts
[
0
]);
});
it
(
'should set search type to query_then_fetch'
,
function
()
{
expect
(
header
.
search_type
).
to
.
eq
l
(
'query_then_fetch'
);
expect
(
header
.
search_type
).
to
Equa
l
(
'query_then_fetch'
);
});
it
(
'should set size'
,
function
()
{
var
body
=
angular
.
fromJson
(
parts
[
1
]);
expect
(
body
.
size
).
to
.
b
e
(
500
);
expect
(
body
.
size
).
to
B
e
(
500
);
});
});
...
...
@@ -146,8 +160,8 @@ describe('ElasticDatasource', function() {
beforeEach
(
function
()
{
createDatasource
({
url
:
'http://es.com'
,
index
:
'metricbeat'
});
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
return
ctx
.
$q
.
when
({
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
((
options
)
=>
{
return
Promise
.
resolve
({
data
:
{
metricbeat
:
{
mappings
:
{
...
...
@@ -190,7 +204,7 @@ describe('ElasticDatasource', function() {
},
},
});
}
;
}
)
});
it
(
'should return nested fields'
,
function
()
{
...
...
@@ -201,7 +215,7 @@ describe('ElasticDatasource', function() {
})
.
then
(
fieldObjects
=>
{
var
fields
=
_
.
map
(
fieldObjects
,
'text'
);
expect
(
fields
).
to
.
eq
l
([
expect
(
fields
).
to
Equa
l
([
'@timestamp'
,
'beat.name.raw'
,
'beat.name'
,
...
...
@@ -212,7 +226,7 @@ describe('ElasticDatasource', function() {
'system.process.name'
,
]);
});
ctx
.
$rootScope
.
$apply
();
//
ctx.$rootScope.$apply();
});
it
(
'should return fields related to query type'
,
function
()
{
...
...
@@ -224,7 +238,7 @@ describe('ElasticDatasource', function() {
})
.
then
(
fieldObjects
=>
{
var
fields
=
_
.
map
(
fieldObjects
,
'text'
);
expect
(
fields
).
to
.
eq
l
([
'system.cpu.system'
,
'system.cpu.user'
,
'system.process.cpu.total'
]);
expect
(
fields
).
to
Equa
l
([
'system.cpu.system'
,
'system.cpu.user'
,
'system.process.cpu.total'
]);
});
ctx
.
ds
...
...
@@ -235,10 +249,10 @@ describe('ElasticDatasource', function() {
})
.
then
(
fieldObjects
=>
{
var
fields
=
_
.
map
(
fieldObjects
,
'text'
);
expect
(
fields
).
to
.
eq
l
([
'@timestamp'
]);
expect
(
fields
).
to
Equa
l
([
'@timestamp'
]);
});
ctx
.
$rootScope
.
$apply
();
//
ctx.$rootScope.$apply();
});
});
...
...
@@ -271,18 +285,18 @@ describe('ElasticDatasource', function() {
],
});
ctx
.
$rootScope
.
$apply
();
//
ctx.$rootScope.$apply();
parts
=
requestOptions
.
data
.
split
(
'
\
n'
);
header
=
angular
.
fromJson
(
parts
[
0
]);
});
it
(
'should not set search type to count'
,
function
()
{
expect
(
header
.
search_type
).
to
.
not
.
eq
l
(
'count'
);
expect
(
header
.
search_type
).
not
.
toEqua
l
(
'count'
);
});
it
(
'should set size to 0'
,
function
()
{
var
body
=
angular
.
fromJson
(
parts
[
1
]);
expect
(
body
.
size
).
to
.
b
e
(
0
);
expect
(
body
.
size
).
to
B
e
(
0
);
});
});
...
...
@@ -324,7 +338,7 @@ describe('ElasticDatasource', function() {
results
=
res
;
});
ctx
.
$rootScope
.
$apply
();
//
ctx.$rootScope.$apply();
parts
=
requestOptions
.
data
.
split
(
'
\
n'
);
header
=
angular
.
fromJson
(
parts
[
0
]);
...
...
@@ -332,24 +346,24 @@ describe('ElasticDatasource', function() {
});
it
(
'should get results'
,
function
()
{
expect
(
results
.
length
).
to
.
eq
l
(
2
);
expect
(
results
.
length
).
to
Equa
l
(
2
);
});
it
(
'should use key or key_as_string'
,
function
()
{
expect
(
results
[
0
].
text
).
to
.
eq
l
(
'test'
);
expect
(
results
[
1
].
text
).
to
.
eq
l
(
'test2_as_string'
);
expect
(
results
[
0
].
text
).
to
Equa
l
(
'test'
);
expect
(
results
[
1
].
text
).
to
Equa
l
(
'test2_as_string'
);
});
it
(
'should not set search type to count'
,
function
()
{
expect
(
header
.
search_type
).
to
.
not
.
eq
l
(
'count'
);
expect
(
header
.
search_type
).
not
.
toEqua
l
(
'count'
);
});
it
(
'should set size to 0'
,
function
()
{
expect
(
body
.
size
).
to
.
b
e
(
0
);
expect
(
body
.
size
).
to
B
e
(
0
);
});
it
(
'should not set terms aggregation size to 0'
,
function
()
{
expect
(
body
[
'aggs'
][
'1'
][
'terms'
].
size
).
to
.
not
.
b
e
(
0
);
expect
(
body
[
'aggs'
][
'1'
][
'terms'
].
size
).
not
.
toB
e
(
0
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment