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
d1d5e9f7
Unverified
Commit
d1d5e9f7
authored
Oct 28, 2018
by
Michael Huynh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests to cover PlaceholdersBuffer and sum hint
Related: #13615
parent
c255b5da
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
1 deletions
+92
-1
public/app/features/explore/PlaceholdersBuffer.test.ts
+72
-0
public/app/plugins/datasource/prometheus/specs/query_hints.test.ts
+20
-1
No files found.
public/app/features/explore/PlaceholdersBuffer.test.ts
0 → 100644
View file @
d1d5e9f7
import
PlaceholdersBuffer
from
'./PlaceholdersBuffer'
;
describe
(
'PlaceholdersBuffer'
,
()
=>
{
it
(
'does nothing if no placeholders are defined'
,
()
=>
{
const
text
=
'metric'
;
const
buffer
=
new
PlaceholdersBuffer
(
text
);
expect
(
buffer
.
hasPlaceholders
()).
toBe
(
false
);
expect
(
buffer
.
toString
()).
toBe
(
text
);
expect
(
buffer
.
getNextMoveOffset
()).
toBe
(
0
);
});
it
(
'respects the traversal order of placeholders'
,
()
=>
{
const
text
=
'sum($2 offset $1) by ($3)'
;
const
buffer
=
new
PlaceholdersBuffer
(
text
);
expect
(
buffer
.
hasPlaceholders
()).
toBe
(
true
);
expect
(
buffer
.
toString
()).
toBe
(
'sum( offset ) by ()'
);
expect
(
buffer
.
getNextMoveOffset
()).
toBe
(
12
);
buffer
.
setNextPlaceholderValue
(
'1h'
);
expect
(
buffer
.
hasPlaceholders
()).
toBe
(
true
);
expect
(
buffer
.
toString
()).
toBe
(
'sum( offset 1h) by ()'
);
expect
(
buffer
.
getNextMoveOffset
()).
toBe
(
-
10
);
buffer
.
setNextPlaceholderValue
(
'metric'
);
expect
(
buffer
.
hasPlaceholders
()).
toBe
(
true
);
expect
(
buffer
.
toString
()).
toBe
(
'sum(metric offset 1h) by ()'
);
expect
(
buffer
.
getNextMoveOffset
()).
toBe
(
16
);
buffer
.
setNextPlaceholderValue
(
'label'
);
expect
(
buffer
.
hasPlaceholders
()).
toBe
(
false
);
expect
(
buffer
.
toString
()).
toBe
(
'sum(metric offset 1h) by (label)'
);
expect
(
buffer
.
getNextMoveOffset
()).
toBe
(
0
);
});
it
(
'respects the traversal order of adjacent placeholders'
,
()
=>
{
const
text
=
'$1$3$2$4'
;
const
buffer
=
new
PlaceholdersBuffer
(
text
);
expect
(
buffer
.
hasPlaceholders
()).
toBe
(
true
);
expect
(
buffer
.
toString
()).
toBe
(
''
);
expect
(
buffer
.
getNextMoveOffset
()).
toBe
(
0
);
buffer
.
setNextPlaceholderValue
(
'1'
);
expect
(
buffer
.
hasPlaceholders
()).
toBe
(
true
);
expect
(
buffer
.
toString
()).
toBe
(
'1'
);
expect
(
buffer
.
getNextMoveOffset
()).
toBe
(
0
);
buffer
.
setNextPlaceholderValue
(
'2'
);
expect
(
buffer
.
hasPlaceholders
()).
toBe
(
true
);
expect
(
buffer
.
toString
()).
toBe
(
'12'
);
expect
(
buffer
.
getNextMoveOffset
()).
toBe
(
-
1
);
buffer
.
setNextPlaceholderValue
(
'3'
);
expect
(
buffer
.
hasPlaceholders
()).
toBe
(
true
);
expect
(
buffer
.
toString
()).
toBe
(
'132'
);
expect
(
buffer
.
getNextMoveOffset
()).
toBe
(
1
);
buffer
.
setNextPlaceholderValue
(
'4'
);
expect
(
buffer
.
hasPlaceholders
()).
toBe
(
false
);
expect
(
buffer
.
toString
()).
toBe
(
'1324'
);
expect
(
buffer
.
getNextMoveOffset
()).
toBe
(
0
);
});
});
public/app/plugins/datasource/prometheus/specs/query_hints.test.ts
View file @
d1d5e9f7
import
{
getQueryHints
}
from
'../query_hints'
;
import
{
getQueryHints
,
SUM_HINT_THRESHOLD_COUNT
}
from
'../query_hints'
;
describe
(
'getQueryHints()'
,
()
=>
{
it
(
'returns no hints for no series'
,
()
=>
{
...
...
@@ -79,4 +79,23 @@ describe('getQueryHints()', () => {
},
});
});
it
(
'returns a sum hint when many time series results are returned for a simple metric'
,
()
=>
{
const
seriesCount
=
SUM_HINT_THRESHOLD_COUNT
;
const
series
=
Array
.
from
({
length
:
seriesCount
},
_
=>
({
datapoints
:
[[
0
,
0
],
[
0
,
0
]],
}));
const
hints
=
getQueryHints
(
'metric'
,
series
);
expect
(
hints
.
length
).
toBe
(
seriesCount
);
expect
(
hints
[
0
]).
toMatchObject
({
label
:
'Many time series results returned.'
,
index
:
0
,
fix
:
{
action
:
{
type
:
'ADD_SUM'
,
query
:
'metric'
,
},
},
});
});
});
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