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
ca0339fb
Unverified
Commit
ca0339fb
authored
Aug 06, 2018
by
Marcus Efraimsson
Committed by
GitHub
Aug 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12819 from dehrax/12224-opentsdb-ds
Karma to Jest: OpenTSDB datasource
parents
6f1b125c
ccd964e1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
160 deletions
+126
-160
public/app/plugins/datasource/opentsdb/specs/datasource-specs.ts
+0
-105
public/app/plugins/datasource/opentsdb/specs/datasource.jest.ts
+91
-0
public/app/plugins/datasource/opentsdb/specs/query_ctrl.jest.ts
+35
-55
No files found.
public/app/plugins/datasource/opentsdb/specs/datasource-specs.ts
deleted
100644 → 0
View file @
6f1b125c
import
{
describe
,
beforeEach
,
it
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
helpers
from
'test/specs/helpers'
;
import
OpenTsDatasource
from
'../datasource'
;
describe
(
'opentsdb'
,
function
()
{
var
ctx
=
new
helpers
.
ServiceTestContext
();
var
instanceSettings
=
{
url
:
''
,
jsonData
:
{
tsdbVersion
:
1
}
};
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
(
OpenTsDatasource
,
{
instanceSettings
:
instanceSettings
,
});
$httpBackend
.
when
(
'GET'
,
/
\.
html$/
).
respond
(
''
);
})
);
describe
(
'When performing metricFindQuery'
,
function
()
{
var
results
;
var
requestOptions
;
beforeEach
(
function
()
{
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({
data
:
[{
target
:
'prod1.count'
,
datapoints
:
[[
10
,
1
],
[
12
,
1
]]
}],
});
};
});
it
(
'metrics() should generate api suggest query'
,
function
()
{
ctx
.
ds
.
metricFindQuery
(
'metrics(pew)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
expect
(
requestOptions
.
url
).
to
.
be
(
'/api/suggest'
);
expect
(
requestOptions
.
params
.
type
).
to
.
be
(
'metrics'
);
expect
(
requestOptions
.
params
.
q
).
to
.
be
(
'pew'
);
expect
(
results
).
not
.
to
.
be
(
null
);
});
it
(
'tag_names(cpu) should generate lookup query'
,
function
()
{
ctx
.
ds
.
metricFindQuery
(
'tag_names(cpu)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
expect
(
requestOptions
.
url
).
to
.
be
(
'/api/search/lookup'
);
expect
(
requestOptions
.
params
.
m
).
to
.
be
(
'cpu'
);
});
it
(
'tag_values(cpu, test) should generate lookup query'
,
function
()
{
ctx
.
ds
.
metricFindQuery
(
'tag_values(cpu, hostname)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
expect
(
requestOptions
.
url
).
to
.
be
(
'/api/search/lookup'
);
expect
(
requestOptions
.
params
.
m
).
to
.
be
(
'cpu{hostname=*}'
);
});
it
(
'tag_values(cpu, test) should generate lookup query'
,
function
()
{
ctx
.
ds
.
metricFindQuery
(
'tag_values(cpu, hostname, env=$env)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
expect
(
requestOptions
.
url
).
to
.
be
(
'/api/search/lookup'
);
expect
(
requestOptions
.
params
.
m
).
to
.
be
(
'cpu{hostname=*,env=$env}'
);
});
it
(
'tag_values(cpu, test) should generate lookup query'
,
function
()
{
ctx
.
ds
.
metricFindQuery
(
'tag_values(cpu, hostname, env=$env, region=$region)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
expect
(
requestOptions
.
url
).
to
.
be
(
'/api/search/lookup'
);
expect
(
requestOptions
.
params
.
m
).
to
.
be
(
'cpu{hostname=*,env=$env,region=$region}'
);
});
it
(
'suggest_tagk() should generate api suggest query'
,
function
()
{
ctx
.
ds
.
metricFindQuery
(
'suggest_tagk(foo)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
expect
(
requestOptions
.
url
).
to
.
be
(
'/api/suggest'
);
expect
(
requestOptions
.
params
.
type
).
to
.
be
(
'tagk'
);
expect
(
requestOptions
.
params
.
q
).
to
.
be
(
'foo'
);
});
it
(
'suggest_tagv() should generate api suggest query'
,
function
()
{
ctx
.
ds
.
metricFindQuery
(
'suggest_tagv(bar)'
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$rootScope
.
$apply
();
expect
(
requestOptions
.
url
).
to
.
be
(
'/api/suggest'
);
expect
(
requestOptions
.
params
.
type
).
to
.
be
(
'tagv'
);
expect
(
requestOptions
.
params
.
q
).
to
.
be
(
'bar'
);
});
});
});
public/app/plugins/datasource/opentsdb/specs/datasource.jest.ts
0 → 100644
View file @
ca0339fb
import
OpenTsDatasource
from
'../datasource'
;
import
$q
from
'q'
;
describe
(
'opentsdb'
,
()
=>
{
let
ctx
=
<
any
>
{
backendSrv
:
{},
ds
:
{},
templateSrv
:
{
replace
:
str
=>
str
,
},
};
let
instanceSettings
=
{
url
:
''
,
jsonData
:
{
tsdbVersion
:
1
}
};
beforeEach
(()
=>
{
ctx
.
ctrl
=
new
OpenTsDatasource
(
instanceSettings
,
$q
,
ctx
.
backendSrv
,
ctx
.
templateSrv
);
});
describe
(
'When performing metricFindQuery'
,
()
=>
{
var
results
;
var
requestOptions
;
beforeEach
(
async
()
=>
{
ctx
.
backendSrv
.
datasourceRequest
=
await
function
(
options
)
{
requestOptions
=
options
;
return
Promise
.
resolve
({
data
:
[{
target
:
'prod1.count'
,
datapoints
:
[[
10
,
1
],
[
12
,
1
]]
}],
});
};
});
it
(
'metrics() should generate api suggest query'
,
()
=>
{
ctx
.
ctrl
.
metricFindQuery
(
'metrics(pew)'
).
then
(
function
(
data
)
{
results
=
data
;
});
expect
(
requestOptions
.
url
).
toBe
(
'/api/suggest'
);
expect
(
requestOptions
.
params
.
type
).
toBe
(
'metrics'
);
expect
(
requestOptions
.
params
.
q
).
toBe
(
'pew'
);
expect
(
results
).
not
.
toBe
(
null
);
});
it
(
'tag_names(cpu) should generate lookup query'
,
()
=>
{
ctx
.
ctrl
.
metricFindQuery
(
'tag_names(cpu)'
).
then
(
function
(
data
)
{
results
=
data
;
});
expect
(
requestOptions
.
url
).
toBe
(
'/api/search/lookup'
);
expect
(
requestOptions
.
params
.
m
).
toBe
(
'cpu'
);
});
it
(
'tag_values(cpu, test) should generate lookup query'
,
()
=>
{
ctx
.
ctrl
.
metricFindQuery
(
'tag_values(cpu, hostname)'
).
then
(
function
(
data
)
{
results
=
data
;
});
expect
(
requestOptions
.
url
).
toBe
(
'/api/search/lookup'
);
expect
(
requestOptions
.
params
.
m
).
toBe
(
'cpu{hostname=*}'
);
});
it
(
'tag_values(cpu, test) should generate lookup query'
,
()
=>
{
ctx
.
ctrl
.
metricFindQuery
(
'tag_values(cpu, hostname, env=$env)'
).
then
(
function
(
data
)
{
results
=
data
;
});
expect
(
requestOptions
.
url
).
toBe
(
'/api/search/lookup'
);
expect
(
requestOptions
.
params
.
m
).
toBe
(
'cpu{hostname=*,env=$env}'
);
});
it
(
'tag_values(cpu, test) should generate lookup query'
,
()
=>
{
ctx
.
ctrl
.
metricFindQuery
(
'tag_values(cpu, hostname, env=$env, region=$region)'
).
then
(
function
(
data
)
{
results
=
data
;
});
expect
(
requestOptions
.
url
).
toBe
(
'/api/search/lookup'
);
expect
(
requestOptions
.
params
.
m
).
toBe
(
'cpu{hostname=*,env=$env,region=$region}'
);
});
it
(
'suggest_tagk() should generate api suggest query'
,
()
=>
{
ctx
.
ctrl
.
metricFindQuery
(
'suggest_tagk(foo)'
).
then
(
function
(
data
)
{
results
=
data
;
});
expect
(
requestOptions
.
url
).
toBe
(
'/api/suggest'
);
expect
(
requestOptions
.
params
.
type
).
toBe
(
'tagk'
);
expect
(
requestOptions
.
params
.
q
).
toBe
(
'foo'
);
});
it
(
'suggest_tagv() should generate api suggest query'
,
()
=>
{
ctx
.
ctrl
.
metricFindQuery
(
'suggest_tagv(bar)'
).
then
(
function
(
data
)
{
results
=
data
;
});
expect
(
requestOptions
.
url
).
toBe
(
'/api/suggest'
);
expect
(
requestOptions
.
params
.
type
).
toBe
(
'tagv'
);
expect
(
requestOptions
.
params
.
q
).
toBe
(
'bar'
);
});
});
});
public/app/plugins/datasource/opentsdb/specs/query
-ctrl-specs
.ts
→
public/app/plugins/datasource/opentsdb/specs/query
_ctrl.jest
.ts
View file @
ca0339fb
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
helpers
from
'test/specs/helpers'
;
import
{
OpenTsQueryCtrl
}
from
'../query_ctrl'
;
import
{
OpenTsQueryCtrl
}
from
'../query_ctrl'
;
describe
(
'OpenTsQueryCtrl'
,
function
()
{
describe
(
'OpenTsQueryCtrl'
,
()
=>
{
var
ctx
=
new
helpers
.
ControllerTestContext
();
var
ctx
=
<
any
>
{
target
:
{
target
:
''
},
beforeEach
(
angularMocks
.
module
(
'grafana.core'
));
datasource
:
{
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
tsdbVersion
:
''
,
beforeEach
(
getAggregators
:
()
=>
Promise
.
resolve
([]),
angularMocks
.
module
(
function
(
$compileProvider
)
{
getFilterTypes
:
()
=>
Promise
.
resolve
([]),
$compileProvider
.
preAssignBindingsEnabled
(
true
);
},
})
};
);
beforeEach
(
ctx
.
providePhase
([
'backendSrv'
,
'templateSrv'
]));
beforeEach
(
ctx
.
providePhase
());
beforeEach
(
angularMocks
.
inject
((
$rootScope
,
$controller
,
$q
)
=>
{
ctx
.
$q
=
$q
;
ctx
.
scope
=
$rootScope
.
$new
();
ctx
.
target
=
{
target
:
''
};
ctx
.
panelCtrl
=
{
ctx
.
panelCtrl
=
{
panel
:
{
panel
:
{
targets
:
[
ctx
.
target
],
targets
:
[
ctx
.
target
],
},
},
refresh
:
()
=>
{},
};
};
ctx
.
panelCtrl
.
refresh
=
sinon
.
spy
();
ctx
.
datasource
.
getAggregators
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([]));
ctx
.
datasource
.
getFilterTypes
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([]));
ctx
.
ctrl
=
$controller
(
OpenTsQueryCtrl
.
prototype
=
Object
.
assign
(
OpenTsQueryCtrl
.
prototype
,
ctx
);
OpenTsQueryCtrl
,
{
$scope
:
ctx
.
scope
},
beforeEach
(()
=>
{
{
ctx
.
ctrl
=
new
OpenTsQueryCtrl
({},
{});
panelCtrl
:
ctx
.
panelCtrl
,
});
datasource
:
ctx
.
datasource
,
target
:
ctx
.
target
,
}
);
ctx
.
scope
.
$digest
();
})
);
describe
(
'init query_ctrl variables'
,
function
()
{
describe
(
'init query_ctrl variables'
,
()
=>
{
it
(
'filter types should be initialized'
,
function
()
{
it
(
'filter types should be initialized'
,
()
=>
{
expect
(
ctx
.
ctrl
.
filterTypes
.
length
).
to
.
b
e
(
7
);
expect
(
ctx
.
ctrl
.
filterTypes
.
length
).
to
B
e
(
7
);
});
});
it
(
'aggregators should be initialized'
,
function
()
{
it
(
'aggregators should be initialized'
,
()
=>
{
expect
(
ctx
.
ctrl
.
aggregators
.
length
).
to
.
b
e
(
8
);
expect
(
ctx
.
ctrl
.
aggregators
.
length
).
to
B
e
(
8
);
});
});
it
(
'fill policy options should be initialized'
,
function
()
{
it
(
'fill policy options should be initialized'
,
()
=>
{
expect
(
ctx
.
ctrl
.
fillPolicies
.
length
).
to
.
b
e
(
4
);
expect
(
ctx
.
ctrl
.
fillPolicies
.
length
).
to
B
e
(
4
);
});
});
});
});
describe
(
'when adding filters and tags'
,
function
()
{
describe
(
'when adding filters and tags'
,
()
=>
{
it
(
'addTagMode should be false when closed'
,
function
()
{
it
(
'addTagMode should be false when closed'
,
()
=>
{
ctx
.
ctrl
.
addTagMode
=
true
;
ctx
.
ctrl
.
addTagMode
=
true
;
ctx
.
ctrl
.
closeAddTagMode
();
ctx
.
ctrl
.
closeAddTagMode
();
expect
(
ctx
.
ctrl
.
addTagMode
).
to
.
b
e
(
false
);
expect
(
ctx
.
ctrl
.
addTagMode
).
to
B
e
(
false
);
});
});
it
(
'addFilterMode should be false when closed'
,
function
()
{
it
(
'addFilterMode should be false when closed'
,
()
=>
{
ctx
.
ctrl
.
addFilterMode
=
true
;
ctx
.
ctrl
.
addFilterMode
=
true
;
ctx
.
ctrl
.
closeAddFilterMode
();
ctx
.
ctrl
.
closeAddFilterMode
();
expect
(
ctx
.
ctrl
.
addFilterMode
).
to
.
b
e
(
false
);
expect
(
ctx
.
ctrl
.
addFilterMode
).
to
B
e
(
false
);
});
});
it
(
'removing a tag from the tags list'
,
function
()
{
it
(
'removing a tag from the tags list'
,
()
=>
{
ctx
.
ctrl
.
target
.
tags
=
{
tagk
:
'tag_key'
,
tagk2
:
'tag_value2'
};
ctx
.
ctrl
.
target
.
tags
=
{
tagk
:
'tag_key'
,
tagk2
:
'tag_value2'
};
ctx
.
ctrl
.
removeTag
(
'tagk'
);
ctx
.
ctrl
.
removeTag
(
'tagk'
);
expect
(
Object
.
keys
(
ctx
.
ctrl
.
target
.
tags
).
length
).
to
.
b
e
(
1
);
expect
(
Object
.
keys
(
ctx
.
ctrl
.
target
.
tags
).
length
).
to
B
e
(
1
);
});
});
it
(
'removing a filter from the filters list'
,
function
()
{
it
(
'removing a filter from the filters list'
,
()
=>
{
ctx
.
ctrl
.
target
.
filters
=
[
ctx
.
ctrl
.
target
.
filters
=
[
{
{
tagk
:
'tag_key'
,
tagk
:
'tag_key'
,
...
@@ -86,18 +66,18 @@ describe('OpenTsQueryCtrl', function() {
...
@@ -86,18 +66,18 @@ describe('OpenTsQueryCtrl', function() {
},
},
];
];
ctx
.
ctrl
.
removeFilter
(
0
);
ctx
.
ctrl
.
removeFilter
(
0
);
expect
(
ctx
.
ctrl
.
target
.
filters
.
length
).
to
.
b
e
(
0
);
expect
(
ctx
.
ctrl
.
target
.
filters
.
length
).
to
B
e
(
0
);
});
});
it
(
'adding a filter when tags exist should generate error'
,
function
()
{
it
(
'adding a filter when tags exist should generate error'
,
()
=>
{
ctx
.
ctrl
.
target
.
tags
=
{
tagk
:
'tag_key'
,
tagk2
:
'tag_value2'
};
ctx
.
ctrl
.
target
.
tags
=
{
tagk
:
'tag_key'
,
tagk2
:
'tag_value2'
};
ctx
.
ctrl
.
addFilter
();
ctx
.
ctrl
.
addFilter
();
expect
(
ctx
.
ctrl
.
errors
.
filters
).
to
.
b
e
(
expect
(
ctx
.
ctrl
.
errors
.
filters
).
to
B
e
(
'Please remove tags to use filters, tags and filters are mutually exclusive.'
'Please remove tags to use filters, tags and filters are mutually exclusive.'
);
);
});
});
it
(
'adding a tag when filters exist should generate error'
,
function
()
{
it
(
'adding a tag when filters exist should generate error'
,
()
=>
{
ctx
.
ctrl
.
target
.
filters
=
[
ctx
.
ctrl
.
target
.
filters
=
[
{
{
tagk
:
'tag_key'
,
tagk
:
'tag_key'
,
...
@@ -107,7 +87,7 @@ describe('OpenTsQueryCtrl', function() {
...
@@ -107,7 +87,7 @@ describe('OpenTsQueryCtrl', function() {
},
},
];
];
ctx
.
ctrl
.
addTag
();
ctx
.
ctrl
.
addTag
();
expect
(
ctx
.
ctrl
.
errors
.
tags
).
to
.
b
e
(
'Please remove filters to use tags, tags and filters are mutually exclusive.'
);
expect
(
ctx
.
ctrl
.
errors
.
tags
).
to
B
e
(
'Please remove filters to use tags, tags and filters are mutually exclusive.'
);
});
});
});
});
});
});
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