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
b90e4057
Commit
b90e4057
authored
Sep 30, 2015
by
Jimmi Dyson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert prometheus specs to typescript
parent
67f25383
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
94 deletions
+81
-94
public/app/plugins/datasource/prometheus/specs/datasource_specs.ts
+81
-94
No files found.
public/
test/specs/prometheus-datasource-specs.j
s
→
public/
app/plugins/datasource/prometheus/specs/datasource_specs.t
s
View file @
b90e4057
define
([
///<amd-dependency path="app/plugins/datasource/prometheus/datasource" />
'./helpers'
,
///<amd-dependency path="test/specs/helpers" name="helpers" />
'moment'
,
'app/plugins/datasource/prometheus/datasource'
],
function
(
helpers
,
moment
)
{
'use strict'
;
describe
(
'PrometheusDatasource'
,
function
()
{
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'test/lib/common'
;
var
ctx
=
new
helpers
.
ServiceTestContext
();
import
moment
=
require
(
'moment'
);
declare
var
helpers
:
any
;
beforeEach
(
module
(
'grafana.services'
));
describe
(
'PrometheusDatasource'
,
function
()
{
beforeEach
(
ctx
.
createService
(
'PrometheusDatasource'
));
var
ctx
=
new
helpers
.
ServiceTestContext
();
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
ctx
.
createService
(
'PrometheusDatasource'
));
beforeEach
(
function
()
{
ctx
.
ds
=
new
ctx
.
service
({
url
:
''
,
user
:
'test'
,
password
:
'mupp'
});
});
describe
(
'When querying prometheus with one target using query editor target spec'
,
function
()
{
var
results
;
var
urlExpected
=
'/api/v1/query_range?query='
+
encodeURIComponent
(
'test{job="testjob"}'
)
+
'&start=1443438675&end=1443460275&step=60s'
;
var
query
=
{
range
:
{
from
:
moment
(
1443438674760
),
to
:
moment
(
1443460274760
)
},
targets
:
[{
expr
:
'test{job="testjob"}'
}],
interval
:
'60s'
};
var
response
=
{
status
:
"success"
,
data
:
{
resultType
:
"matrix"
,
result
:
[{
metric
:
{
"__name__"
:
"test"
,
job
:
"testjob"
},
values
:
[[
1443454528
,
"3846"
]]
}]
}
};
beforeEach
(
function
()
{
beforeEach
(
function
()
{
ctx
.
ds
=
new
ctx
.
service
({
url
:
''
,
user
:
'test'
,
password
:
'mupp'
});
ctx
.
$httpBackend
.
expect
(
'GET'
,
urlExpected
).
respond
(
response
);
ctx
.
ds
.
query
(
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$httpBackend
.
flush
();
});
});
it
(
'should generate the correct query'
,
function
()
{
describe
(
'When querying prometheus with one target using query editor target spec'
,
function
()
{
ctx
.
$httpBackend
.
verifyNoOutstandingExpectation
();
var
results
;
});
var
urlExpected
=
'/api/v1/query_range?query='
+
it
(
'should return series list'
,
function
()
{
encodeURIComponent
(
'test{job="testjob"}'
)
+
expect
(
results
.
data
.
length
).
to
.
be
(
1
);
'&start=1443438675&end=1443460275&step=60s'
;
expect
(
results
.
data
[
0
].
target
).
to
.
be
(
'test{job="testjob"}'
);
var
query
=
{
});
range
:
{
from
:
moment
(
1443438674760
),
to
:
moment
(
1443460274760
)
},
});
targets
:
[{
expr
:
'test{job="testjob"}'
}],
describe
(
'When performing metricFindQuery'
,
function
()
{
interval
:
'60s'
var
results
;
var
response
;
it
(
'label_values(resource) should generate label search query'
,
function
()
{
response
=
{
status
:
"success"
,
data
:
[
"value1"
,
"value2"
,
"value3"
]
};
};
ctx
.
$httpBackend
.
expect
(
'GET'
,
'/api/v1/label/resource/values'
).
respond
(
response
);
var
response
=
{
ctx
.
ds
.
metricFindQuery
(
'label_values(resource)'
).
then
(
function
(
data
)
{
results
=
data
;
});
"status"
:
"success"
,
ctx
.
$httpBackend
.
flush
();
"data"
:{
ctx
.
$rootScope
.
$apply
();
"resultType"
:
"matrix"
,
expect
(
results
.
length
).
to
.
be
(
3
);
"result"
:[{
});
"metric"
:{
"__name__"
:
"test"
,
"job"
:
"testjob"
},
it
(
'label_values(metric, resource) should generate count metric query'
,
function
()
{
"values"
:[[
1443454528
,
"3846"
]]
response
=
{
}]
status
:
"success"
,
data
:
{
resultType
:
"vector"
,
result
:
[
{
metric
:
{
resource
:
"value1"
},
value
:
[]},
{
metric
:
{
resource
:
"value2"
},
value
:
[]},
{
metric
:
{
resource
:
"value3"
},
value
:
[]}
]
}
}
};
};
ctx
.
$httpBackend
.
expect
(
'GET'
,
/
\/
api
\/
v1
\/
query
\?
query=count
\(
metric
\)
%20by%20
\(
resource
\)
&time=.*/
).
respond
(
response
);
beforeEach
(
function
()
{
ctx
.
ds
.
metricFindQuery
(
'label_values(metric, resource)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$httpBackend
.
expect
(
'GET'
,
urlExpected
).
respond
(
response
);
ctx
.
$httpBackend
.
flush
();
ctx
.
ds
.
query
(
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
ctx
.
$httpBackend
.
flush
();
expect
(
results
.
length
).
to
.
be
(
3
);
});
it
(
'should generate the correct query'
,
function
()
{
ctx
.
$httpBackend
.
verifyNoOutstandingExpectation
();
});
it
(
'should return series list'
,
function
()
{
expect
(
results
.
data
.
length
).
to
.
be
(
1
);
expect
(
results
.
data
[
0
].
target
).
to
.
be
(
'test{job="testjob"}'
);
});
});
});
it
(
'metrics(metric.*) should generate metric name query'
,
function
()
{
describe
(
'When performing metricFindQuery'
,
function
()
{
response
=
{
var
results
;
status
:
"success"
,
var
response
;
data
:
[
"metric1"
,
"metric2"
,
"metric3"
,
"nomatch"
]
};
it
(
'label_values(resource) should generate label search query'
,
function
()
{
ctx
.
$httpBackend
.
expect
(
'GET'
,
'/api/v1/label/__name__/values'
).
respond
(
response
);
response
=
{
ctx
.
ds
.
metricFindQuery
(
'metrics(metric.*)'
).
then
(
function
(
data
)
{
results
=
data
;
});
status
:
"success"
,
ctx
.
$httpBackend
.
flush
();
data
:
[
"value1"
,
"value2"
,
"value3"
]
ctx
.
$rootScope
.
$apply
();
};
expect
(
results
.
length
).
to
.
be
(
3
);
ctx
.
$httpBackend
.
expect
(
'GET'
,
'/api/v1/label/resource/values'
).
respond
(
response
);
ctx
.
ds
.
metricFindQuery
(
'label_values(resource)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$httpBackend
.
flush
();
ctx
.
$rootScope
.
$apply
();
expect
(
results
.
length
).
to
.
be
(
3
);
});
it
(
'label_values(metric, resource) should generate count metric query'
,
function
()
{
response
=
{
status
:
"success"
,
data
:{
resultType
:
"vector"
,
result
:[
{
metric
:{
resource
:
"value1"
},
value
:[]},
{
metric
:{
resource
:
"value2"
},
value
:[]},
{
metric
:{
resource
:
"value3"
},
value
:[]}
]
}
};
ctx
.
$httpBackend
.
expect
(
'GET'
,
/
\/
api
\/
v1
\/
query
\?
query=count
\(
metric
\)
%20by%20
\(
resource
\)
&time=.*/
).
respond
(
response
);
ctx
.
ds
.
metricFindQuery
(
'label_values(metric, resource)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$httpBackend
.
flush
();
ctx
.
$rootScope
.
$apply
();
expect
(
results
.
length
).
to
.
be
(
3
);
});
it
(
'metrics(metric.*) should generate metric name query'
,
function
()
{
response
=
{
status
:
"success"
,
data
:[
"metric1"
,
"metric2"
,
"metric3"
,
"nomatch"
]
};
ctx
.
$httpBackend
.
expect
(
'GET'
,
'/api/v1/label/__name__/values'
).
respond
(
response
);
ctx
.
ds
.
metricFindQuery
(
'metrics(metric.*)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$httpBackend
.
flush
();
ctx
.
$rootScope
.
$apply
();
expect
(
results
.
length
).
to
.
be
(
3
);
});
});
});
});
});
});
});
...
...
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