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
95056ad5
Unverified
Commit
95056ad5
authored
Oct 20, 2020
by
Kamal Galrani
Committed by
GitHub
Oct 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes windows crlf warning (#28346)
parent
04c06f22
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
171 additions
and
171 deletions
+171
-171
public/app/plugins/datasource/influxdb/specs/datasource.test.ts
+171
-171
No files found.
public/app/plugins/datasource/influxdb/specs/datasource.test.ts
View file @
95056ad5
import
InfluxDatasource
from
'../datasource'
;
import
InfluxDatasource
from
'../datasource'
;
import
{
TemplateSrvStub
}
from
'test/specs/helpers'
;
import
{
TemplateSrvStub
}
from
'test/specs/helpers'
;
import
{
backendSrv
}
from
'app/core/services/backend_srv'
;
// will use the version in __mocks__
import
{
backendSrv
}
from
'app/core/services/backend_srv'
;
// will use the version in __mocks__
//@ts-ignore
//@ts-ignore
const
templateSrv
=
new
TemplateSrvStub
();
const
templateSrv
=
new
TemplateSrvStub
();
jest
.
mock
(
'@grafana/runtime'
,
()
=>
({
jest
.
mock
(
'@grafana/runtime'
,
()
=>
({
...((
jest
.
requireActual
(
'@grafana/runtime'
)
as
unknown
)
as
object
),
...((
jest
.
requireActual
(
'@grafana/runtime'
)
as
unknown
)
as
object
),
getBackendSrv
:
()
=>
backendSrv
,
getBackendSrv
:
()
=>
backendSrv
,
}));
}));
describe
(
'InfluxDataSource'
,
()
=>
{
describe
(
'InfluxDataSource'
,
()
=>
{
const
ctx
:
any
=
{
const
ctx
:
any
=
{
instanceSettings
:
{
url
:
'url'
,
name
:
'influxDb'
,
jsonData
:
{
httpMode
:
'GET'
}
},
instanceSettings
:
{
url
:
'url'
,
name
:
'influxDb'
,
jsonData
:
{
httpMode
:
'GET'
}
},
};
};
const
datasourceRequestMock
=
jest
.
spyOn
(
backendSrv
,
'datasourceRequest'
);
const
datasourceRequestMock
=
jest
.
spyOn
(
backendSrv
,
'datasourceRequest'
);
beforeEach
(()
=>
{
beforeEach
(()
=>
{
jest
.
clearAllMocks
();
jest
.
clearAllMocks
();
ctx
.
instanceSettings
.
url
=
'/api/datasources/proxy/1'
;
ctx
.
instanceSettings
.
url
=
'/api/datasources/proxy/1'
;
ctx
.
ds
=
new
InfluxDatasource
(
ctx
.
instanceSettings
,
templateSrv
);
ctx
.
ds
=
new
InfluxDatasource
(
ctx
.
instanceSettings
,
templateSrv
);
});
});
describe
(
'When issuing metricFindQuery'
,
()
=>
{
describe
(
'When issuing metricFindQuery'
,
()
=>
{
const
query
=
'SELECT max(value) FROM measurement WHERE $timeFilter'
;
const
query
=
'SELECT max(value) FROM measurement WHERE $timeFilter'
;
const
queryOptions
:
any
=
{
const
queryOptions
:
any
=
{
range
:
{
range
:
{
from
:
'2018-01-01T00:00:00Z'
,
from
:
'2018-01-01T00:00:00Z'
,
to
:
'2018-01-02T00:00:00Z'
,
to
:
'2018-01-02T00:00:00Z'
,
},
},
};
};
let
requestQuery
:
any
,
requestMethod
:
any
,
requestData
:
any
,
response
:
any
;
let
requestQuery
:
any
,
requestMethod
:
any
,
requestData
:
any
,
response
:
any
;
beforeEach
(
async
()
=>
{
beforeEach
(
async
()
=>
{
datasourceRequestMock
.
mockImplementation
((
req
:
any
)
=>
{
datasourceRequestMock
.
mockImplementation
((
req
:
any
)
=>
{
requestMethod
=
req
.
method
;
requestMethod
=
req
.
method
;
requestQuery
=
req
.
params
.
q
;
requestQuery
=
req
.
params
.
q
;
requestData
=
req
.
data
;
requestData
=
req
.
data
;
return
Promise
.
resolve
({
return
Promise
.
resolve
({
data
:
{
data
:
{
results
:
[
results
:
[
{
{
series
:
[
series
:
[
{
{
name
:
'measurement'
,
name
:
'measurement'
,
columns
:
[
'name'
],
columns
:
[
'name'
],
values
:
[[
'cpu'
]],
values
:
[[
'cpu'
]],
},
},
],
],
},
},
],
],
},
},
});
});
});
});
response
=
await
ctx
.
ds
.
metricFindQuery
(
query
,
queryOptions
);
response
=
await
ctx
.
ds
.
metricFindQuery
(
query
,
queryOptions
);
});
});
it
(
'should replace $timefilter'
,
()
=>
{
it
(
'should replace $timefilter'
,
()
=>
{
expect
(
requestQuery
).
toMatch
(
'time >= 1514764800000ms and time <= 1514851200000ms'
);
expect
(
requestQuery
).
toMatch
(
'time >= 1514764800000ms and time <= 1514851200000ms'
);
});
});
it
(
'should use the HTTP GET method'
,
()
=>
{
it
(
'should use the HTTP GET method'
,
()
=>
{
expect
(
requestMethod
).
toBe
(
'GET'
);
expect
(
requestMethod
).
toBe
(
'GET'
);
});
});
it
(
'should not have any data in request body'
,
()
=>
{
it
(
'should not have any data in request body'
,
()
=>
{
expect
(
requestData
).
toBeNull
();
expect
(
requestData
).
toBeNull
();
});
});
it
(
'parse response correctly'
,
()
=>
{
it
(
'parse response correctly'
,
()
=>
{
expect
(
response
).
toEqual
([{
text
:
'cpu'
}]);
expect
(
response
).
toEqual
([{
text
:
'cpu'
}]);
});
});
});
});
describe
(
'When getting error on 200 after issuing a query'
,
()
=>
{
describe
(
'When getting error on 200 after issuing a query'
,
()
=>
{
const
queryOptions
:
any
=
{
const
queryOptions
:
any
=
{
range
:
{
range
:
{
from
:
'2018-01-01T00:00:00Z'
,
from
:
'2018-01-01T00:00:00Z'
,
to
:
'2018-01-02T00:00:00Z'
,
to
:
'2018-01-02T00:00:00Z'
,
},
},
rangeRaw
:
{
rangeRaw
:
{
from
:
'2018-01-01T00:00:00Z'
,
from
:
'2018-01-01T00:00:00Z'
,
to
:
'2018-01-02T00:00:00Z'
,
to
:
'2018-01-02T00:00:00Z'
,
},
},
targets
:
[{}],
targets
:
[{}],
timezone
:
'UTC'
,
timezone
:
'UTC'
,
scopedVars
:
{
scopedVars
:
{
interval
:
{
text
:
'1m'
,
value
:
'1m'
},
interval
:
{
text
:
'1m'
,
value
:
'1m'
},
__interval
:
{
text
:
'1m'
,
value
:
'1m'
},
__interval
:
{
text
:
'1m'
,
value
:
'1m'
},
__interval_ms
:
{
text
:
60000
,
value
:
60000
},
__interval_ms
:
{
text
:
60000
,
value
:
60000
},
},
},
};
};
it
(
'throws an error'
,
async
()
=>
{
it
(
'throws an error'
,
async
()
=>
{
datasourceRequestMock
.
mockImplementation
((
req
:
any
)
=>
{
datasourceRequestMock
.
mockImplementation
((
req
:
any
)
=>
{
return
Promise
.
resolve
({
return
Promise
.
resolve
({
data
:
{
data
:
{
results
:
[
results
:
[
{
{
error
:
'Query timeout'
,
error
:
'Query timeout'
,
},
},
],
],
},
},
});
});
});
});
try
{
try
{
await
ctx
.
ds
.
query
(
queryOptions
).
toPromise
();
await
ctx
.
ds
.
query
(
queryOptions
).
toPromise
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
message
).
toBe
(
'InfluxDB Error: Query timeout'
);
expect
(
err
.
message
).
toBe
(
'InfluxDB Error: Query timeout'
);
}
}
});
});
});
});
describe
(
'InfluxDataSource in POST query mode'
,
()
=>
{
describe
(
'InfluxDataSource in POST query mode'
,
()
=>
{
const
ctx
:
any
=
{
const
ctx
:
any
=
{
instanceSettings
:
{
url
:
'url'
,
name
:
'influxDb'
,
jsonData
:
{
httpMode
:
'POST'
}
},
instanceSettings
:
{
url
:
'url'
,
name
:
'influxDb'
,
jsonData
:
{
httpMode
:
'POST'
}
},
};
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
ctx
.
instanceSettings
.
url
=
'/api/datasources/proxy/1'
;
ctx
.
instanceSettings
.
url
=
'/api/datasources/proxy/1'
;
ctx
.
ds
=
new
InfluxDatasource
(
ctx
.
instanceSettings
,
templateSrv
);
ctx
.
ds
=
new
InfluxDatasource
(
ctx
.
instanceSettings
,
templateSrv
);
});
});
describe
(
'When issuing metricFindQuery'
,
()
=>
{
describe
(
'When issuing metricFindQuery'
,
()
=>
{
const
query
=
'SELECT max(value) FROM measurement'
;
const
query
=
'SELECT max(value) FROM measurement'
;
const
queryOptions
:
any
=
{};
const
queryOptions
:
any
=
{};
let
requestMethod
:
any
,
requestQueryParameter
:
any
,
queryEncoded
:
any
,
requestQuery
:
any
;
let
requestMethod
:
any
,
requestQueryParameter
:
any
,
queryEncoded
:
any
,
requestQuery
:
any
;
beforeEach
(
async
()
=>
{
beforeEach
(
async
()
=>
{
datasourceRequestMock
.
mockImplementation
((
req
:
any
)
=>
{
datasourceRequestMock
.
mockImplementation
((
req
:
any
)
=>
{
requestMethod
=
req
.
method
;
requestMethod
=
req
.
method
;
requestQueryParameter
=
req
.
params
;
requestQueryParameter
=
req
.
params
;
requestQuery
=
req
.
data
;
requestQuery
=
req
.
data
;
return
Promise
.
resolve
({
return
Promise
.
resolve
({
results
:
[
results
:
[
{
{
series
:
[
series
:
[
{
{
name
:
'measurement'
,
name
:
'measurement'
,
columns
:
[
'max'
],
columns
:
[
'max'
],
values
:
[[
1
]],
values
:
[[
1
]],
},
},
],
],
},
},
],
],
});
});
});
});
queryEncoded
=
await
ctx
.
ds
.
serializeParams
({
q
:
query
});
queryEncoded
=
await
ctx
.
ds
.
serializeParams
({
q
:
query
});
await
ctx
.
ds
.
metricFindQuery
(
query
,
queryOptions
).
then
(()
=>
{});
await
ctx
.
ds
.
metricFindQuery
(
query
,
queryOptions
).
then
(()
=>
{});
});
});
it
(
'should have the query form urlencoded'
,
()
=>
{
it
(
'should have the query form urlencoded'
,
()
=>
{
expect
(
requestQuery
).
toBe
(
queryEncoded
);
expect
(
requestQuery
).
toBe
(
queryEncoded
);
});
});
it
(
'should use the HTTP POST method'
,
()
=>
{
it
(
'should use the HTTP POST method'
,
()
=>
{
expect
(
requestMethod
).
toBe
(
'POST'
);
expect
(
requestMethod
).
toBe
(
'POST'
);
});
});
it
(
'should not have q as a query parameter'
,
()
=>
{
it
(
'should not have q as a query parameter'
,
()
=>
{
expect
(
requestQueryParameter
).
not
.
toHaveProperty
(
'q'
);
expect
(
requestQueryParameter
).
not
.
toHaveProperty
(
'q'
);
});
});
});
});
});
});
});
});
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