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
92f50ca3
Commit
92f50ca3
authored
Sep 27, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: add unit tests to resolve unit function
parent
251bb09a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
2 deletions
+54
-2
public/app/plugins/datasource/stackdriver/datasource.ts
+2
-2
public/app/plugins/datasource/stackdriver/specs/datasource.test.ts
+52
-0
No files found.
public/app/plugins/datasource/stackdriver/datasource.ts
View file @
92f50ca3
...
...
@@ -86,7 +86,7 @@ export default class StackdriverDatasource {
return
interpolatedGroupBys
;
}
resolve
Unit
(
targets
:
any
[])
{
resolve
PanelUnitFromTargets
(
targets
:
any
[])
{
let
unit
=
'none'
;
if
(
targets
.
length
>
0
&&
targets
.
every
(
t
=>
t
.
unit
===
targets
[
0
].
unit
))
{
if
(
stackdriverUnitMappings
.
hasOwnProperty
(
targets
[
0
].
unit
))
{
...
...
@@ -105,7 +105,7 @@ export default class StackdriverDatasource {
return
;
}
const
unit
=
this
.
resolve
Unit
(
options
.
targets
);
const
unit
=
this
.
resolve
PanelUnitFromTargets
(
options
.
targets
);
queryRes
.
series
.
forEach
(
series
=>
{
result
.
push
({
target
:
series
.
name
,
...
...
public/app/plugins/datasource/stackdriver/specs/datasource.test.ts
View file @
92f50ca3
...
...
@@ -219,4 +219,56 @@ describe('StackdriverDataSource', () => {
});
});
});
describe
(
'unit parsing'
,
()
=>
{
let
ds
,
res
;
beforeEach
(()
=>
{
ds
=
new
StackdriverDataSource
(
instanceSettings
,
{},
templateSrv
,
timeSrv
);
});
describe
(
'when theres only one target'
,
()
=>
{
describe
(
'and the stackdriver unit doesnt have a corresponding grafana unit'
,
()
=>
{
beforeEach
(()
=>
{
res
=
ds
.
resolvePanelUnitFromTargets
([{
unit
:
'megaseconds'
}]);
});
it
(
'should return none'
,
()
=>
{
expect
(
res
).
toEqual
(
'none'
);
});
});
describe
(
'and the stackdriver unit has a corresponding grafana unit'
,
()
=>
{
beforeEach
(()
=>
{
res
=
ds
.
resolvePanelUnitFromTargets
([{
unit
:
'bit'
}]);
});
it
(
'should return bits'
,
()
=>
{
expect
(
res
).
toEqual
(
'bits'
);
});
});
});
describe
(
'when theres more than one target'
,
()
=>
{
describe
(
'and all target units are the same'
,
()
=>
{
beforeEach
(()
=>
{
res
=
ds
.
resolvePanelUnitFromTargets
([{
unit
:
'bit'
},
{
unit
:
'bit'
}]);
});
it
(
'should return bits'
,
()
=>
{
expect
(
res
).
toEqual
(
'bits'
);
});
});
describe
(
'and all target units are the same but doesnt have grafana mappings'
,
()
=>
{
beforeEach
(()
=>
{
res
=
ds
.
resolvePanelUnitFromTargets
([{
unit
:
'megaseconds'
},
{
unit
:
'megaseconds'
}]);
});
it
(
'should return the default value - none'
,
()
=>
{
expect
(
res
).
toEqual
(
'none'
);
});
});
describe
(
'and all target units are not the same'
,
()
=>
{
beforeEach
(()
=>
{
res
=
ds
.
resolvePanelUnitFromTargets
([{
unit
:
'bit'
},
{
unit
:
'min'
}]);
});
it
(
'should return the default value - none'
,
()
=>
{
expect
(
res
).
toEqual
(
'none'
);
});
});
});
});
});
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