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
9595f992
Unverified
Commit
9595f992
authored
Jul 10, 2018
by
David
Committed by
GitHub
Jul 10, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12496 from dehrax/12224-prostgres-ds
Karma to Jest: 3 data sources
parents
8b32dc58
e51f208a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
174 additions
and
291 deletions
+174
-291
public/app/plugins/datasource/cloudwatch/datasource.ts
+1
-0
public/app/plugins/datasource/cloudwatch/specs/datasource.jest.ts
+75
-172
public/app/plugins/datasource/mysql/specs/datasource.jest.ts
+48
-59
public/app/plugins/datasource/postgres/specs/datasource.jest.ts
+50
-60
No files found.
public/app/plugins/datasource/cloudwatch/datasource.ts
View file @
9595f992
...
...
@@ -404,6 +404,7 @@ export default class CloudWatchDatasource {
}
expandTemplateVariable
(
targets
,
scopedVars
,
templateSrv
)
{
// Datasource and template srv logic uber-complected. This should be cleaned up.
return
_
.
chain
(
targets
)
.
map
(
target
=>
{
var
dimensionKey
=
_
.
findKey
(
target
.
dimensions
,
v
=>
{
...
...
public/app/plugins/datasource/cloudwatch/specs/datasource
_specs
.ts
→
public/app/plugins/datasource/cloudwatch/specs/datasource
.jest
.ts
View file @
9595f992
import
'../datasource'
;
import
{
describe
,
beforeEach
,
it
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
helpers
from
'test/specs/helpers'
;
import
CloudWatchDatasource
from
'../datasource'
;
import
'app/features/dashboard/time_srv'
;
import
*
as
dateMath
from
'app/core/utils/datemath'
;
import
_
from
'lodash'
;
describe
(
'CloudWatchDatasource'
,
function
()
{
var
ctx
=
new
helpers
.
ServiceTestContext
();
var
instanceSettings
=
{
let
instanceSettings
=
{
jsonData
:
{
defaultRegion
:
'us-east-1'
,
access
:
'proxy'
},
};
beforeEach
(
angularMocks
.
module
(
'grafana.core'
));
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
angularMocks
.
module
(
'grafana.controllers'
));
beforeEach
(
ctx
.
providePhase
([
'templateSrv'
,
'backendSrv'
]));
beforeEach
(
ctx
.
createService
(
'timeSrv'
));
beforeEach
(
angularMocks
.
inject
(
function
(
$q
,
$rootScope
,
$httpBackend
,
$injector
)
{
ctx
.
$q
=
$q
;
ctx
.
$httpBackend
=
$httpBackend
;
ctx
.
$rootScope
=
$rootScope
;
ctx
.
ds
=
$injector
.
instantiate
(
CloudWatchDatasource
,
{
instanceSettings
:
instanceSettings
,
});
$httpBackend
.
when
(
'GET'
,
/
\.
html$/
).
respond
(
''
);
})
);
let
templateSrv
=
{
data
:
{},
templateSettings
:
{
interpolate
:
/
\[\[([\s\S]
+
?)\]\]
/g
},
replace
:
text
=>
_
.
template
(
text
,
templateSrv
.
templateSettings
)(
templateSrv
.
data
),
variableExists
:
()
=>
false
,
};
let
timeSrv
=
{
time
:
{
from
:
'now-1h'
,
to
:
'now'
},
timeRange
:
()
=>
{
return
{
from
:
dateMath
.
parse
(
timeSrv
.
time
.
from
,
false
),
to
:
dateMath
.
parse
(
timeSrv
.
time
.
to
,
true
),
};
},
};
let
backendSrv
=
{};
let
ctx
=
<
any
>
{
backendSrv
,
templateSrv
,
};
beforeEach
(()
=>
{
ctx
.
ds
=
new
CloudWatchDatasource
(
instanceSettings
,
{},
backendSrv
,
templateSrv
,
timeSrv
);
});
describe
(
'When performing CloudWatch query'
,
function
()
{
var
requestParams
;
...
...
@@ -67,24 +73,23 @@ describe('CloudWatchDatasource', function() {
},
};
beforeEach
(
function
()
{
ctx
.
backendSrv
.
datasourceRequest
=
function
(
params
)
{
beforeEach
(
()
=>
{
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
(
params
=>
{
requestParams
=
params
.
data
;
return
ctx
.
$q
.
when
({
data
:
response
});
};
return
Promise
.
resolve
({
data
:
response
});
}
)
;
});
it
(
'should generate the correct query'
,
function
(
done
)
{
ctx
.
ds
.
query
(
query
).
then
(
function
()
{
var
params
=
requestParams
.
queries
[
0
];
expect
(
params
.
namespace
).
to
.
b
e
(
query
.
targets
[
0
].
namespace
);
expect
(
params
.
metricName
).
to
.
b
e
(
query
.
targets
[
0
].
metricName
);
expect
(
params
.
dimensions
[
'InstanceId'
]).
to
.
b
e
(
'i-12345678'
);
expect
(
params
.
statistics
).
to
.
eq
l
(
query
.
targets
[
0
].
statistics
);
expect
(
params
.
period
).
to
.
b
e
(
query
.
targets
[
0
].
period
);
expect
(
params
.
namespace
).
to
B
e
(
query
.
targets
[
0
].
namespace
);
expect
(
params
.
metricName
).
to
B
e
(
query
.
targets
[
0
].
metricName
);
expect
(
params
.
dimensions
[
'InstanceId'
]).
to
B
e
(
'i-12345678'
);
expect
(
params
.
statistics
).
to
Equa
l
(
query
.
targets
[
0
].
statistics
);
expect
(
params
.
period
).
to
B
e
(
query
.
targets
[
0
].
period
);
done
();
});
ctx
.
$rootScope
.
$apply
();
});
it
(
'should generate the correct query with interval variable'
,
function
(
done
)
{
...
...
@@ -111,116 +116,17 @@ describe('CloudWatchDatasource', function() {
ctx
.
ds
.
query
(
query
).
then
(
function
()
{
var
params
=
requestParams
.
queries
[
0
];
expect
(
params
.
period
).
to
.
b
e
(
'600'
);
expect
(
params
.
period
).
to
B
e
(
'600'
);
done
();
});
ctx
.
$rootScope
.
$apply
();
});
it
(
'should return series list'
,
function
(
done
)
{
ctx
.
ds
.
query
(
query
).
then
(
function
(
result
)
{
expect
(
result
.
data
[
0
].
target
).
to
.
b
e
(
response
.
results
.
A
.
series
[
0
].
name
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
0
]).
to
.
b
e
(
response
.
results
.
A
.
series
[
0
].
points
[
0
][
0
]);
expect
(
result
.
data
[
0
].
target
).
to
B
e
(
response
.
results
.
A
.
series
[
0
].
name
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
0
]).
to
B
e
(
response
.
results
.
A
.
series
[
0
].
points
[
0
][
0
]);
done
();
});
ctx
.
$rootScope
.
$apply
();
});
it
(
'should generate the correct targets by expanding template variables'
,
function
()
{
var
templateSrv
=
{
variables
:
[
{
name
:
'instance_id'
,
options
:
[
{
text
:
'i-23456789'
,
value
:
'i-23456789'
,
selected
:
false
},
{
text
:
'i-34567890'
,
value
:
'i-34567890'
,
selected
:
true
},
],
current
:
{
text
:
'i-34567890'
,
value
:
'i-34567890'
,
},
},
],
replace
:
function
(
target
,
scopedVars
)
{
if
(
target
===
'$instance_id'
&&
scopedVars
[
'instance_id'
][
'text'
]
===
'i-34567890'
)
{
return
'i-34567890'
;
}
else
{
return
''
;
}
},
getVariableName
:
function
(
e
)
{
return
'instance_id'
;
},
variableExists
:
function
(
e
)
{
return
true
;
},
containsVariable
:
function
(
str
,
variableName
)
{
return
str
.
indexOf
(
'$'
+
variableName
)
!==
-
1
;
},
};
var
targets
=
[
{
region
:
'us-east-1'
,
namespace
:
'AWS/EC2'
,
metricName
:
'CPUUtilization'
,
dimensions
:
{
InstanceId
:
'$instance_id'
,
},
statistics
:
[
'Average'
],
period
:
300
,
},
];
var
result
=
ctx
.
ds
.
expandTemplateVariable
(
targets
,
{},
templateSrv
);
expect
(
result
[
0
].
dimensions
.
InstanceId
).
to
.
be
(
'i-34567890'
);
});
it
(
'should generate the correct targets by expanding template variables from url'
,
function
()
{
var
templateSrv
=
{
variables
:
[
{
name
:
'instance_id'
,
options
:
[
{
text
:
'i-23456789'
,
value
:
'i-23456789'
,
selected
:
false
},
{
text
:
'i-34567890'
,
value
:
'i-34567890'
,
selected
:
false
},
],
current
:
'i-45678901'
,
},
],
replace
:
function
(
target
,
scopedVars
)
{
if
(
target
===
'$instance_id'
)
{
return
'i-45678901'
;
}
else
{
return
''
;
}
},
getVariableName
:
function
(
e
)
{
return
'instance_id'
;
},
variableExists
:
function
(
e
)
{
return
true
;
},
containsVariable
:
function
(
str
,
variableName
)
{
return
str
.
indexOf
(
'$'
+
variableName
)
!==
-
1
;
},
};
var
targets
=
[
{
region
:
'us-east-1'
,
namespace
:
'AWS/EC2'
,
metricName
:
'CPUUtilization'
,
dimensions
:
{
InstanceId
:
'$instance_id'
,
},
statistics
:
[
'Average'
],
period
:
300
,
},
];
var
result
=
ctx
.
ds
.
expandTemplateVariable
(
targets
,
{},
templateSrv
);
expect
(
result
[
0
].
dimensions
.
InstanceId
).
to
.
be
(
'i-45678901'
);
});
});
...
...
@@ -228,21 +134,21 @@ describe('CloudWatchDatasource', function() {
it
(
'should return the datasource region if empty or "default"'
,
function
()
{
var
defaultRegion
=
instanceSettings
.
jsonData
.
defaultRegion
;
expect
(
ctx
.
ds
.
getActualRegion
()).
to
.
b
e
(
defaultRegion
);
expect
(
ctx
.
ds
.
getActualRegion
(
''
)).
to
.
b
e
(
defaultRegion
);
expect
(
ctx
.
ds
.
getActualRegion
(
'default'
)).
to
.
b
e
(
defaultRegion
);
expect
(
ctx
.
ds
.
getActualRegion
()).
to
B
e
(
defaultRegion
);
expect
(
ctx
.
ds
.
getActualRegion
(
''
)).
to
B
e
(
defaultRegion
);
expect
(
ctx
.
ds
.
getActualRegion
(
'default'
)).
to
B
e
(
defaultRegion
);
});
it
(
'should return the specified region if specified'
,
function
()
{
expect
(
ctx
.
ds
.
getActualRegion
(
'some-fake-region-1'
)).
to
.
b
e
(
'some-fake-region-1'
);
expect
(
ctx
.
ds
.
getActualRegion
(
'some-fake-region-1'
)).
to
B
e
(
'some-fake-region-1'
);
});
var
requestParams
;
beforeEach
(
function
()
{
ctx
.
ds
.
performTimeSeriesQuery
=
function
(
request
)
{
ctx
.
ds
.
performTimeSeriesQuery
=
jest
.
fn
(
request
=>
{
requestParams
=
request
;
return
ctx
.
$q
.
when
({
data
:
{}
});
};
return
Promise
.
resolve
({
data
:
{}
});
}
)
;
});
it
(
'should query for the datasource region if empty or "default"'
,
function
(
done
)
{
...
...
@@ -264,10 +170,9 @@ describe('CloudWatchDatasource', function() {
};
ctx
.
ds
.
query
(
query
).
then
(
function
(
result
)
{
expect
(
requestParams
.
queries
[
0
].
region
).
to
.
b
e
(
instanceSettings
.
jsonData
.
defaultRegion
);
expect
(
requestParams
.
queries
[
0
].
region
).
to
B
e
(
instanceSettings
.
jsonData
.
defaultRegion
);
done
();
});
ctx
.
$rootScope
.
$apply
();
});
});
...
...
@@ -311,18 +216,17 @@ describe('CloudWatchDatasource', function() {
};
beforeEach
(
function
()
{
ctx
.
backendSrv
.
datasourceRequest
=
function
(
params
)
{
return
ctx
.
$q
.
when
({
data
:
response
});
};
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
(
params
=>
{
return
Promise
.
resolve
({
data
:
response
});
}
)
;
});
it
(
'should return series list'
,
function
(
done
)
{
ctx
.
ds
.
query
(
query
).
then
(
function
(
result
)
{
expect
(
result
.
data
[
0
].
target
).
to
.
b
e
(
response
.
results
.
A
.
series
[
0
].
name
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
0
]).
to
.
b
e
(
response
.
results
.
A
.
series
[
0
].
points
[
0
][
0
]);
expect
(
result
.
data
[
0
].
target
).
to
B
e
(
response
.
results
.
A
.
series
[
0
].
name
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
0
]).
to
B
e
(
response
.
results
.
A
.
series
[
0
].
points
[
0
][
0
]);
done
();
});
ctx
.
$rootScope
.
$apply
();
});
});
...
...
@@ -332,14 +236,13 @@ describe('CloudWatchDatasource', function() {
scenario
.
setup
=
setupCallback
=>
{
beforeEach
(()
=>
{
setupCallback
();
ctx
.
backendSrv
.
datasourceRequest
=
args
=>
{
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
(
args
=>
{
scenario
.
request
=
args
.
data
;
return
ctx
.
$q
.
when
({
data
:
scenario
.
requestResponse
});
};
return
Promise
.
resolve
({
data
:
scenario
.
requestResponse
});
}
)
;
ctx
.
ds
.
metricFindQuery
(
query
).
then
(
args
=>
{
scenario
.
result
=
args
;
});
ctx
.
$rootScope
.
$apply
();
});
};
...
...
@@ -359,9 +262,9 @@ describe('CloudWatchDatasource', function() {
});
it
(
'should call __GetRegions and return result'
,
()
=>
{
expect
(
scenario
.
result
[
0
].
text
).
to
.
c
ontain
(
'us-east-1'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
.
b
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
.
b
e
(
'regions'
);
expect
(
scenario
.
result
[
0
].
text
).
to
C
ontain
(
'us-east-1'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
B
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
B
e
(
'regions'
);
});
});
...
...
@@ -377,9 +280,9 @@ describe('CloudWatchDatasource', function() {
});
it
(
'should call __GetNamespaces and return result'
,
()
=>
{
expect
(
scenario
.
result
[
0
].
text
).
to
.
c
ontain
(
'AWS/EC2'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
.
b
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
.
b
e
(
'namespaces'
);
expect
(
scenario
.
result
[
0
].
text
).
to
C
ontain
(
'AWS/EC2'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
B
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
B
e
(
'namespaces'
);
});
});
...
...
@@ -395,9 +298,9 @@ describe('CloudWatchDatasource', function() {
});
it
(
'should call __GetMetrics and return result'
,
()
=>
{
expect
(
scenario
.
result
[
0
].
text
).
to
.
b
e
(
'CPUUtilization'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
.
b
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
.
b
e
(
'metrics'
);
expect
(
scenario
.
result
[
0
].
text
).
to
B
e
(
'CPUUtilization'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
B
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
B
e
(
'metrics'
);
});
});
...
...
@@ -413,9 +316,9 @@ describe('CloudWatchDatasource', function() {
});
it
(
'should call __GetDimensions and return result'
,
()
=>
{
expect
(
scenario
.
result
[
0
].
text
).
to
.
b
e
(
'InstanceId'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
.
b
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
.
b
e
(
'dimension_keys'
);
expect
(
scenario
.
result
[
0
].
text
).
to
B
e
(
'InstanceId'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
B
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
B
e
(
'dimension_keys'
);
});
});
...
...
@@ -431,9 +334,9 @@ describe('CloudWatchDatasource', function() {
});
it
(
'should call __ListMetrics and return result'
,
()
=>
{
expect
(
scenario
.
result
[
0
].
text
).
to
.
c
ontain
(
'i-12345678'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
.
b
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
.
b
e
(
'dimension_values'
);
expect
(
scenario
.
result
[
0
].
text
).
to
C
ontain
(
'i-12345678'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
B
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
B
e
(
'dimension_values'
);
});
});
...
...
@@ -449,9 +352,9 @@ describe('CloudWatchDatasource', function() {
});
it
(
'should call __ListMetrics and return result'
,
()
=>
{
expect
(
scenario
.
result
[
0
].
text
).
to
.
c
ontain
(
'i-12345678'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
.
b
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
.
b
e
(
'dimension_values'
);
expect
(
scenario
.
result
[
0
].
text
).
to
C
ontain
(
'i-12345678'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
to
B
e
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
to
B
e
(
'dimension_values'
);
});
});
...
...
@@ -544,7 +447,7 @@ describe('CloudWatchDatasource', function() {
let
now
=
new
Date
(
options
.
range
.
from
.
valueOf
()
+
t
[
2
]
*
1000
);
let
expected
=
t
[
3
];
let
actual
=
ctx
.
ds
.
getPeriod
(
target
,
options
,
now
);
expect
(
actual
).
to
.
b
e
(
expected
);
expect
(
actual
).
to
B
e
(
expected
);
}
});
});
public/app/plugins/datasource/mysql/specs/datasource
_specs
.ts
→
public/app/plugins/datasource/mysql/specs/datasource
.jest
.ts
View file @
9595f992
import
{
describe
,
beforeEach
,
it
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
moment
from
'moment'
;
import
helpers
from
'test/specs/helpers'
;
import
{
MysqlDatasource
}
from
'../datasource'
;
import
{
CustomVariable
}
from
'app/features/templating/custom_variable'
;
describe
(
'MySQLDatasource'
,
function
()
{
var
ctx
=
new
helpers
.
ServiceTestContext
();
var
instanceSettings
=
{
name
:
'mysql'
};
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
(
MysqlDatasource
,
{
instanceSettings
:
instanceSettings
,
});
$httpBackend
.
when
(
'GET'
,
/
\.
html$/
).
respond
(
''
);
})
);
let
instanceSettings
=
{
name
:
'mysql'
};
let
backendSrv
=
{};
let
templateSrv
=
{
replace
:
jest
.
fn
(
text
=>
text
),
};
let
ctx
=
<
any
>
{
backendSrv
,
};
beforeEach
(()
=>
{
ctx
.
ds
=
new
MysqlDatasource
(
instanceSettings
,
backendSrv
,
{},
templateSrv
);
});
describe
(
'When performing annotationQuery'
,
function
()
{
let
results
;
...
...
@@ -59,26 +52,25 @@ describe('MySQLDatasource', function() {
};
beforeEach
(
function
()
{
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
return
ctx
.
$q
.
when
({
data
:
response
,
status
:
200
});
};
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
(
options
=>
{
return
Promise
.
resolve
({
data
:
response
,
status
:
200
});
}
)
;
ctx
.
ds
.
annotationQuery
(
options
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
});
it
(
'should return annotation list'
,
function
()
{
expect
(
results
.
length
).
to
.
b
e
(
3
);
expect
(
results
.
length
).
to
B
e
(
3
);
expect
(
results
[
0
].
text
).
to
.
b
e
(
'some text'
);
expect
(
results
[
0
].
tags
[
0
]).
to
.
b
e
(
'TagA'
);
expect
(
results
[
0
].
tags
[
1
]).
to
.
b
e
(
'TagB'
);
expect
(
results
[
0
].
text
).
to
B
e
(
'some text'
);
expect
(
results
[
0
].
tags
[
0
]).
to
B
e
(
'TagA'
);
expect
(
results
[
0
].
tags
[
1
]).
to
B
e
(
'TagB'
);
expect
(
results
[
1
].
tags
[
0
]).
to
.
b
e
(
'TagB'
);
expect
(
results
[
1
].
tags
[
1
]).
to
.
b
e
(
'TagC'
);
expect
(
results
[
1
].
tags
[
0
]).
to
B
e
(
'TagB'
);
expect
(
results
[
1
].
tags
[
1
]).
to
B
e
(
'TagC'
);
expect
(
results
[
2
].
tags
.
length
).
to
.
b
e
(
0
);
expect
(
results
[
2
].
tags
.
length
).
to
B
e
(
0
);
});
});
...
...
@@ -103,19 +95,18 @@ describe('MySQLDatasource', function() {
};
beforeEach
(
function
()
{
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
return
ctx
.
$q
.
when
({
data
:
response
,
status
:
200
});
};
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
(
options
=>
{
return
Promise
.
resolve
({
data
:
response
,
status
:
200
});
}
)
;
ctx
.
ds
.
metricFindQuery
(
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
});
it
(
'should return list of all column values'
,
function
()
{
expect
(
results
.
length
).
to
.
b
e
(
6
);
expect
(
results
[
0
].
text
).
to
.
b
e
(
'aTitle'
);
expect
(
results
[
5
].
text
).
to
.
b
e
(
'some text3'
);
expect
(
results
.
length
).
to
B
e
(
6
);
expect
(
results
[
0
].
text
).
to
B
e
(
'aTitle'
);
expect
(
results
[
5
].
text
).
to
B
e
(
'some text3'
);
});
});
...
...
@@ -140,21 +131,20 @@ describe('MySQLDatasource', function() {
};
beforeEach
(
function
()
{
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
return
ctx
.
$q
.
when
({
data
:
response
,
status
:
200
});
};
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
(
options
=>
{
return
Promise
.
resolve
({
data
:
response
,
status
:
200
});
}
)
;
ctx
.
ds
.
metricFindQuery
(
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
});
it
(
'should return list of as text, value'
,
function
()
{
expect
(
results
.
length
).
to
.
b
e
(
3
);
expect
(
results
[
0
].
text
).
to
.
b
e
(
'aTitle'
);
expect
(
results
[
0
].
value
).
to
.
b
e
(
'value1'
);
expect
(
results
[
2
].
text
).
to
.
b
e
(
'aTitle3'
);
expect
(
results
[
2
].
value
).
to
.
b
e
(
'value3'
);
expect
(
results
.
length
).
to
B
e
(
3
);
expect
(
results
[
0
].
text
).
to
B
e
(
'aTitle'
);
expect
(
results
[
0
].
value
).
to
B
e
(
'value1'
);
expect
(
results
[
2
].
text
).
to
B
e
(
'aTitle3'
);
expect
(
results
[
2
].
value
).
to
B
e
(
'value3'
);
});
});
...
...
@@ -179,19 +169,18 @@ describe('MySQLDatasource', function() {
};
beforeEach
(
function
()
{
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
return
ctx
.
$q
.
when
({
data
:
response
,
status
:
200
});
};
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
(
options
=>
{
return
Promise
.
resolve
({
data
:
response
,
status
:
200
});
}
)
;
ctx
.
ds
.
metricFindQuery
(
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
});
it
(
'should return list of unique keys'
,
function
()
{
expect
(
results
.
length
).
to
.
b
e
(
1
);
expect
(
results
[
0
].
text
).
to
.
b
e
(
'aTitle'
);
expect
(
results
[
0
].
value
).
to
.
b
e
(
'same'
);
expect
(
results
.
length
).
to
B
e
(
1
);
expect
(
results
[
0
].
text
).
to
B
e
(
'aTitle'
);
expect
(
results
[
0
].
value
).
to
B
e
(
'same'
);
});
});
...
...
@@ -202,33 +191,33 @@ describe('MySQLDatasource', function() {
describe
(
'and value is a string'
,
()
=>
{
it
(
'should return an unquoted value'
,
()
=>
{
expect
(
ctx
.
ds
.
interpolateVariable
(
'abc'
,
ctx
.
variable
)).
to
.
eq
l
(
'abc'
);
expect
(
ctx
.
ds
.
interpolateVariable
(
'abc'
,
ctx
.
variable
)).
to
Equa
l
(
'abc'
);
});
});
describe
(
'and value is a number'
,
()
=>
{
it
(
'should return an unquoted value'
,
()
=>
{
expect
(
ctx
.
ds
.
interpolateVariable
(
1000
,
ctx
.
variable
)).
to
.
eq
l
(
1000
);
expect
(
ctx
.
ds
.
interpolateVariable
(
1000
,
ctx
.
variable
)).
to
Equa
l
(
1000
);
});
});
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
.
eq
l
(
"'a','b','c'"
);
expect
(
ctx
.
ds
.
interpolateVariable
([
'a'
,
'b'
,
'c'
],
ctx
.
variable
)).
to
Equa
l
(
"'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
.
eq
l
(
"'abc'"
);
expect
(
ctx
.
ds
.
interpolateVariable
(
'abc'
,
ctx
.
variable
)).
to
Equa
l
(
"'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
.
eq
l
(
"'abc'"
);
expect
(
ctx
.
ds
.
interpolateVariable
(
'abc'
,
ctx
.
variable
)).
to
Equa
l
(
"'abc'"
);
});
});
});
...
...
public/app/plugins/datasource/postgres/specs/datasource
_specs
.ts
→
public/app/plugins/datasource/postgres/specs/datasource
.jest
.ts
View file @
9595f992
import
{
describe
,
beforeEach
,
it
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
moment
from
'moment'
;
import
helpers
from
'test/specs/helpers'
;
import
{
PostgresDatasource
}
from
'../datasource'
;
import
{
CustomVariable
}
from
'app/features/templating/custom_variable'
;
describe
(
'PostgreSQLDatasource'
,
function
()
{
var
ctx
=
new
helpers
.
ServiceTestContext
();
var
instanceSettings
=
{
name
:
'postgresql'
};
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
(
PostgresDatasource
,
{
instanceSettings
:
instanceSettings
,
});
$httpBackend
.
when
(
'GET'
,
/
\.
html$/
).
respond
(
''
);
})
);
let
instanceSettings
=
{
name
:
'postgresql'
};
let
backendSrv
=
{};
let
templateSrv
=
{
replace
:
jest
.
fn
(
text
=>
text
),
};
let
ctx
=
<
any
>
{
backendSrv
,
};
beforeEach
(()
=>
{
ctx
.
ds
=
new
PostgresDatasource
(
instanceSettings
,
backendSrv
,
{},
templateSrv
);
});
describe
(
'When performing annotationQuery'
,
function
()
{
let
results
;
...
...
@@ -59,26 +52,25 @@ describe('PostgreSQLDatasource', function() {
};
beforeEach
(
function
()
{
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
return
ctx
.
$q
.
when
({
data
:
response
,
status
:
200
});
};
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
(
options
=>
{
return
Promise
.
resolve
({
data
:
response
,
status
:
200
});
}
)
;
ctx
.
ds
.
annotationQuery
(
options
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
});
it
(
'should return annotation list'
,
function
()
{
expect
(
results
.
length
).
to
.
b
e
(
3
);
expect
(
results
.
length
).
to
B
e
(
3
);
expect
(
results
[
0
].
text
).
to
.
b
e
(
'some text'
);
expect
(
results
[
0
].
tags
[
0
]).
to
.
b
e
(
'TagA'
);
expect
(
results
[
0
].
tags
[
1
]).
to
.
b
e
(
'TagB'
);
expect
(
results
[
0
].
text
).
to
B
e
(
'some text'
);
expect
(
results
[
0
].
tags
[
0
]).
to
B
e
(
'TagA'
);
expect
(
results
[
0
].
tags
[
1
]).
to
B
e
(
'TagB'
);
expect
(
results
[
1
].
tags
[
0
]).
to
.
b
e
(
'TagB'
);
expect
(
results
[
1
].
tags
[
1
]).
to
.
b
e
(
'TagC'
);
expect
(
results
[
1
].
tags
[
0
]).
to
B
e
(
'TagB'
);
expect
(
results
[
1
].
tags
[
1
]).
to
B
e
(
'TagC'
);
expect
(
results
[
2
].
tags
.
length
).
to
.
b
e
(
0
);
expect
(
results
[
2
].
tags
.
length
).
to
B
e
(
0
);
});
});
...
...
@@ -103,19 +95,18 @@ describe('PostgreSQLDatasource', function() {
};
beforeEach
(
function
()
{
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
return
ctx
.
$q
.
when
({
data
:
response
,
status
:
200
});
};
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
(
options
=>
{
return
Promise
.
resolve
({
data
:
response
,
status
:
200
});
}
)
;
ctx
.
ds
.
metricFindQuery
(
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
});
it
(
'should return list of all column values'
,
function
()
{
expect
(
results
.
length
).
to
.
b
e
(
6
);
expect
(
results
[
0
].
text
).
to
.
b
e
(
'aTitle'
);
expect
(
results
[
5
].
text
).
to
.
b
e
(
'some text3'
);
expect
(
results
.
length
).
to
B
e
(
6
);
expect
(
results
[
0
].
text
).
to
B
e
(
'aTitle'
);
expect
(
results
[
5
].
text
).
to
B
e
(
'some text3'
);
});
});
...
...
@@ -140,21 +131,20 @@ describe('PostgreSQLDatasource', function() {
};
beforeEach
(
function
()
{
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
return
ctx
.
$q
.
when
({
data
:
response
,
status
:
200
});
};
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
(
options
=>
{
return
Promise
.
resolve
({
data
:
response
,
status
:
200
});
}
)
;
ctx
.
ds
.
metricFindQuery
(
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
});
it
(
'should return list of as text, value'
,
function
()
{
expect
(
results
.
length
).
to
.
b
e
(
3
);
expect
(
results
[
0
].
text
).
to
.
b
e
(
'aTitle'
);
expect
(
results
[
0
].
value
).
to
.
b
e
(
'value1'
);
expect
(
results
[
2
].
text
).
to
.
b
e
(
'aTitle3'
);
expect
(
results
[
2
].
value
).
to
.
b
e
(
'value3'
);
expect
(
results
.
length
).
to
B
e
(
3
);
expect
(
results
[
0
].
text
).
to
B
e
(
'aTitle'
);
expect
(
results
[
0
].
value
).
to
B
e
(
'value1'
);
expect
(
results
[
2
].
text
).
to
B
e
(
'aTitle3'
);
expect
(
results
[
2
].
value
).
to
B
e
(
'value3'
);
});
});
...
...
@@ -178,20 +168,20 @@ describe('PostgreSQLDatasource', function() {
},
};
beforeEach
(
function
()
{
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
return
ctx
.
$q
.
when
({
data
:
response
,
status
:
200
});
};
beforeEach
(
()
=>
{
ctx
.
backendSrv
.
datasourceRequest
=
jest
.
fn
(
options
=>
{
return
Promise
.
resolve
({
data
:
response
,
status
:
200
});
}
)
;
ctx
.
ds
.
metricFindQuery
(
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
//
ctx.$rootScope.$apply();
});
it
(
'should return list of unique keys'
,
function
()
{
expect
(
results
.
length
).
to
.
b
e
(
1
);
expect
(
results
[
0
].
text
).
to
.
b
e
(
'aTitle'
);
expect
(
results
[
0
].
value
).
to
.
b
e
(
'same'
);
expect
(
results
.
length
).
to
B
e
(
1
);
expect
(
results
[
0
].
text
).
to
B
e
(
'aTitle'
);
expect
(
results
[
0
].
value
).
to
B
e
(
'same'
);
});
});
...
...
@@ -202,33 +192,33 @@ describe('PostgreSQLDatasource', function() {
describe
(
'and value is a string'
,
()
=>
{
it
(
'should return an unquoted value'
,
()
=>
{
expect
(
ctx
.
ds
.
interpolateVariable
(
'abc'
,
ctx
.
variable
)).
to
.
eq
l
(
'abc'
);
expect
(
ctx
.
ds
.
interpolateVariable
(
'abc'
,
ctx
.
variable
)).
to
Equa
l
(
'abc'
);
});
});
describe
(
'and value is a number'
,
()
=>
{
it
(
'should return an unquoted value'
,
()
=>
{
expect
(
ctx
.
ds
.
interpolateVariable
(
1000
,
ctx
.
variable
)).
to
.
eq
l
(
1000
);
expect
(
ctx
.
ds
.
interpolateVariable
(
1000
,
ctx
.
variable
)).
to
Equa
l
(
1000
);
});
});
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
.
eq
l
(
"'a','b','c'"
);
expect
(
ctx
.
ds
.
interpolateVariable
([
'a'
,
'b'
,
'c'
],
ctx
.
variable
)).
to
Equa
l
(
"'a','b','c'"
);
});
});
describe
(
'and variable allows multi-value and is a string'
,
()
=>
{
it
(
'should return a quoted value'
,
()
=>
{
ctx
.
variable
.
multi
=
true
;
expect
(
ctx
.
ds
.
interpolateVariable
(
'abc'
,
ctx
.
variable
)).
to
.
eq
l
(
"'abc'"
);
expect
(
ctx
.
ds
.
interpolateVariable
(
'abc'
,
ctx
.
variable
)).
to
Equa
l
(
"'abc'"
);
});
});
describe
(
'and variable allows all and is a string'
,
()
=>
{
it
(
'should return a quoted value'
,
()
=>
{
ctx
.
variable
.
includeAll
=
true
;
expect
(
ctx
.
ds
.
interpolateVariable
(
'abc'
,
ctx
.
variable
)).
to
.
eq
l
(
"'abc'"
);
expect
(
ctx
.
ds
.
interpolateVariable
(
'abc'
,
ctx
.
variable
)).
to
Equa
l
(
"'abc'"
);
});
});
});
...
...
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