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
b904e0c6
Unverified
Commit
b904e0c6
authored
Nov 26, 2020
by
Hugo Häggmark
Committed by
GitHub
Nov 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Removes observableTester (#29369)
parent
465735a7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
81 additions
and
271 deletions
+81
-271
packages/grafana-data/src/utils/index.ts
+0
-1
packages/grafana-data/src/utils/tests/observableTester.ts
+0
-108
public/app/features/variables/query/operators.test.ts
+34
-62
public/app/features/variables/query/queryRunners.test.ts
+20
-38
public/app/plugins/datasource/cloud-monitoring/specs/datasource.test.ts
+4
-7
public/app/plugins/datasource/cloudwatch/datasource.test.ts
+19
-24
public/app/plugins/datasource/cloudwatch/specs/datasource.test.ts
+0
-0
public/app/plugins/datasource/loki/datasource.test.ts
+1
-14
public/app/plugins/datasource/mssql/specs/datasource.test.ts
+1
-15
public/test/helpers/createFetchResponse.ts
+2
-2
No files found.
packages/grafana-data/src/utils/index.ts
View file @
b904e0c6
...
@@ -17,4 +17,3 @@ export { locationUtil } from './location';
...
@@ -17,4 +17,3 @@ export { locationUtil } from './location';
export
{
urlUtil
,
UrlQueryMap
,
UrlQueryValue
}
from
'./url'
;
export
{
urlUtil
,
UrlQueryMap
,
UrlQueryValue
}
from
'./url'
;
export
{
DataLinkBuiltInVars
,
mapInternalLinkToExplore
}
from
'./dataLinks'
;
export
{
DataLinkBuiltInVars
,
mapInternalLinkToExplore
}
from
'./dataLinks'
;
export
{
DocsId
}
from
'./docs'
;
export
{
DocsId
}
from
'./docs'
;
export
{
observableTester
}
from
'./tests/observableTester'
;
packages/grafana-data/src/utils/tests/observableTester.ts
deleted
100644 → 0
View file @
465735a7
import
{
Observable
}
from
'rxjs'
;
interface
ObservableTester
<
T
>
{
observable
:
Observable
<
T
>
;
done
:
{
(...
args
:
any
[]):
any
;
fail
(
error
?:
string
|
{
message
:
string
}):
any
;
};
}
interface
SubscribeAndExpectOnNext
<
T
>
extends
ObservableTester
<
T
>
{
expect
:
(
value
:
T
)
=>
void
;
}
interface
SubscribeAndExpectOnNextAndComplete
<
T
>
extends
ObservableTester
<
T
>
{
expectOnNext
:
(
value
:
T
)
=>
void
;
expectOnComplete
:
()
=>
void
;
}
interface
SubscribeAndExpectOnComplete
<
T
>
extends
ObservableTester
<
T
>
{
expect
:
()
=>
void
;
}
interface
SubscribeAndExpectOnError
<
T
>
extends
ObservableTester
<
T
>
{
expect
:
(
err
:
any
)
=>
void
;
}
export
const
observableTester
=
()
=>
{
const
subscribeAndExpectOnNext
=
<
T
>
({
observable
,
expect
,
done
}:
SubscribeAndExpectOnNext
<
T
>
):
void
=>
{
observable
.
subscribe
({
next
:
value
=>
{
try
{
expect
(
value
);
}
catch
(
err
)
{
done
.
fail
(
err
);
}
},
error
:
err
=>
done
.
fail
(
err
),
complete
:
()
=>
done
(),
});
};
const
subscribeAndExpectOnComplete
=
<
T
>
({
observable
,
expect
,
done
}:
SubscribeAndExpectOnComplete
<
T
>
):
void
=>
{
observable
.
subscribe
({
next
:
()
=>
{},
error
:
err
=>
done
.
fail
(
err
),
complete
:
()
=>
{
try
{
expect
();
done
();
}
catch
(
err
)
{
done
.
fail
(
err
);
}
},
});
};
const
subscribeAndExpectOnNextAndComplete
=
<
T
>
({
observable
,
expectOnComplete
,
expectOnNext
,
done
,
}:
SubscribeAndExpectOnNextAndComplete
<
T
>
):
void
=>
{
observable
.
subscribe
({
next
:
(
value
:
T
)
=>
{
try
{
expectOnNext
(
value
);
done
();
}
catch
(
err
)
{
done
.
fail
(
err
);
}
},
error
:
err
=>
done
.
fail
(
err
),
complete
:
()
=>
{
try
{
expectOnComplete
();
done
();
}
catch
(
err
)
{
done
.
fail
(
err
);
}
},
});
};
const
subscribeAndExpectOnError
=
<
T
>
({
observable
,
expect
,
done
}:
SubscribeAndExpectOnError
<
T
>
):
void
=>
{
observable
.
subscribe
({
next
:
()
=>
{},
error
:
err
=>
{
try
{
expect
(
err
);
done
();
}
catch
(
err
)
{
done
.
fail
(
err
);
}
},
complete
:
()
=>
{
done
();
},
});
};
return
{
subscribeAndExpectOnNext
,
subscribeAndExpectOnComplete
,
subscribeAndExpectOnNextAndComplete
,
subscribeAndExpectOnError
,
};
};
public/app/features/variables/query/operators.test.ts
View file @
b904e0c6
import
{
of
}
from
'rxjs'
;
import
{
of
}
from
'rxjs'
;
import
{
queryBuilder
}
from
'../shared/testing/builders'
;
import
{
queryBuilder
}
from
'../shared/testing/builders'
;
import
{
FieldType
,
observableTester
,
toDataFrame
}
from
'@grafana/data'
;
import
{
FieldType
,
toDataFrame
}
from
'@grafana/data'
;
import
{
initialQueryVariableModelState
,
updateVariableOptions
,
updateVariableTags
}
from
'./reducer'
;
import
{
initialQueryVariableModelState
,
updateVariableOptions
,
updateVariableTags
}
from
'./reducer'
;
import
{
toVariablePayload
}
from
'../state/types'
;
import
{
toVariablePayload
}
from
'../state/types'
;
import
{
VariableRefresh
}
from
'../types'
;
import
{
VariableRefresh
}
from
'../types'
;
...
@@ -14,24 +14,22 @@ import {
...
@@ -14,24 +14,22 @@ import {
}
from
'./operators'
;
}
from
'./operators'
;
describe
(
'operators'
,
()
=>
{
describe
(
'operators'
,
()
=>
{
beforeEach
(()
=>
{
jest
.
clearAllMocks
();
});
describe
(
'validateVariableSelection'
,
()
=>
{
describe
(
'validateVariableSelection'
,
()
=>
{
describe
(
'when called'
,
()
=>
{
describe
(
'when called'
,
()
=>
{
it
(
'then the correct observable should be created'
,
done
=>
{
it
(
'then the correct observable should be created'
,
async
()
=>
{
const
variable
=
queryBuilder
()
const
variable
=
queryBuilder
()
.
withId
(
'query'
)
.
withId
(
'query'
)
.
build
();
.
build
();
const
dispatch
=
jest
.
fn
().
mockResolvedValue
({});
const
dispatch
=
jest
.
fn
().
mockResolvedValue
({});
const
observable
=
of
(
undefined
).
pipe
(
const
observable
=
of
(
undefined
).
pipe
(
validateVariableSelection
({
variable
,
dispatch
}));
validateVariableSelection
({
variable
,
dispatch
,
searchFilter
:
'A search filter'
})
);
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
expect
(
received
[
0
]).
toEqual
({});
expect
:
value
=>
{
expect
(
value
).
toEqual
({});
expect
(
dispatch
).
toHaveBeenCalledTimes
(
1
);
expect
(
dispatch
).
toHaveBeenCalledTimes
(
1
);
},
done
,
});
});
});
});
});
});
...
@@ -39,7 +37,7 @@ describe('operators', () => {
...
@@ -39,7 +37,7 @@ describe('operators', () => {
describe
(
'updateTagsState'
,
()
=>
{
describe
(
'updateTagsState'
,
()
=>
{
describe
(
'when called with a variable that uses Tags'
,
()
=>
{
describe
(
'when called with a variable that uses Tags'
,
()
=>
{
it
(
'then the correct observable should be created'
,
done
=>
{
it
(
'then the correct observable should be created'
,
async
()
=>
{
const
variable
=
queryBuilder
()
const
variable
=
queryBuilder
()
.
withId
(
'query'
)
.
withId
(
'query'
)
.
withTags
(
true
)
.
withTags
(
true
)
...
@@ -47,22 +45,17 @@ describe('operators', () => {
...
@@ -47,22 +45,17 @@ describe('operators', () => {
const
dispatch
=
jest
.
fn
().
mockResolvedValue
({});
const
dispatch
=
jest
.
fn
().
mockResolvedValue
({});
const
observable
=
of
([{
text
:
'A text'
}]).
pipe
(
updateTagsState
({
variable
,
dispatch
}));
const
observable
=
of
([{
text
:
'A text'
}]).
pipe
(
updateTagsState
({
variable
,
dispatch
}));
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
expect
(
value
).
toEqual
(
undefined
);
expect
(
value
).
toEqual
(
undefined
);
expect
(
dispatch
).
toHaveBeenCalledTimes
(
1
);
expect
(
dispatch
).
toHaveBeenCalledTimes
(
1
);
expect
(
dispatch
).
toHaveBeenCalledWith
(
expect
(
dispatch
).
toHaveBeenCalledWith
(
updateVariableTags
(
toVariablePayload
(
variable
,
[{
text
:
'A text'
}])));
updateVariableTags
(
toVariablePayload
(
variable
,
[{
text
:
'A text'
}]))
);
},
done
,
});
});
});
});
});
});
describe
(
'when called with a variable that does not use Tags'
,
()
=>
{
describe
(
'when called with a variable that does not use Tags'
,
()
=>
{
it
(
'then the correct observable should be created'
,
done
=>
{
it
(
'then the correct observable should be created'
,
async
()
=>
{
const
variable
=
queryBuilder
()
const
variable
=
queryBuilder
()
.
withId
(
'query'
)
.
withId
(
'query'
)
.
withTags
(
false
)
.
withTags
(
false
)
...
@@ -70,13 +63,10 @@ describe('operators', () => {
...
@@ -70,13 +63,10 @@ describe('operators', () => {
const
dispatch
=
jest
.
fn
().
mockResolvedValue
({});
const
dispatch
=
jest
.
fn
().
mockResolvedValue
({});
const
observable
=
of
([{
text
:
'A text'
}]).
pipe
(
updateTagsState
({
variable
,
dispatch
}));
const
observable
=
of
([{
text
:
'A text'
}]).
pipe
(
updateTagsState
({
variable
,
dispatch
}));
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
expect
(
value
).
toEqual
(
undefined
);
expect
(
value
).
toEqual
(
undefined
);
expect
(
dispatch
).
not
.
toHaveBeenCalled
();
expect
(
dispatch
).
not
.
toHaveBeenCalled
();
},
done
,
});
});
});
});
});
});
...
@@ -84,7 +74,7 @@ describe('operators', () => {
...
@@ -84,7 +74,7 @@ describe('operators', () => {
describe
(
'runUpdateTagsRequest'
,
()
=>
{
describe
(
'runUpdateTagsRequest'
,
()
=>
{
describe
(
'when called with a datasource with metricFindQuery and variable that uses Tags and refreshes on time range changes'
,
()
=>
{
describe
(
'when called with a datasource with metricFindQuery and variable that uses Tags and refreshes on time range changes'
,
()
=>
{
it
(
'then the correct observable should be created'
,
done
=>
{
it
(
'then the correct observable should be created'
,
async
()
=>
{
const
variable
=
queryBuilder
()
const
variable
=
queryBuilder
()
.
withId
(
'query'
)
.
withId
(
'query'
)
.
withTags
(
true
)
.
withTags
(
true
)
...
@@ -98,9 +88,8 @@ describe('operators', () => {
...
@@ -98,9 +88,8 @@ describe('operators', () => {
const
searchFilter
=
'A search filter'
;
const
searchFilter
=
'A search filter'
;
const
observable
=
of
(
undefined
).
pipe
(
runUpdateTagsRequest
({
variable
,
datasource
,
searchFilter
},
timeSrv
));
const
observable
=
of
(
undefined
).
pipe
(
runUpdateTagsRequest
({
variable
,
datasource
,
searchFilter
},
timeSrv
));
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
const
{
index
,
global
,
...
rest
}
=
initialQueryVariableModelState
;
const
{
index
,
global
,
...
rest
}
=
initialQueryVariableModelState
;
expect
(
value
).
toEqual
([{
text
:
'A text'
}]);
expect
(
value
).
toEqual
([{
text
:
'A text'
}]);
expect
(
timeSrv
.
timeRange
).
toHaveBeenCalledTimes
(
1
);
expect
(
timeSrv
.
timeRange
).
toHaveBeenCalledTimes
(
1
);
...
@@ -117,14 +106,12 @@ describe('operators', () => {
...
@@ -117,14 +106,12 @@ describe('operators', () => {
refresh
:
VariableRefresh
.
onTimeRangeChanged
,
refresh
:
VariableRefresh
.
onTimeRangeChanged
,
},
},
});
});
},
done
,
});
});
});
});
});
});
describe
(
'when called with a datasource without metricFindQuery and variable that uses Tags and refreshes on time range changes'
,
()
=>
{
describe
(
'when called with a datasource without metricFindQuery and variable that uses Tags and refreshes on time range changes'
,
()
=>
{
it
(
'then the correct observable should be created'
,
done
=>
{
it
(
'then the correct observable should be created'
,
async
()
=>
{
const
variable
=
queryBuilder
()
const
variable
=
queryBuilder
()
.
withId
(
'query'
)
.
withId
(
'query'
)
.
withTags
(
true
)
.
withTags
(
true
)
...
@@ -138,19 +125,16 @@ describe('operators', () => {
...
@@ -138,19 +125,16 @@ describe('operators', () => {
const
searchFilter
=
'A search filter'
;
const
searchFilter
=
'A search filter'
;
const
observable
=
of
(
undefined
).
pipe
(
runUpdateTagsRequest
({
variable
,
datasource
,
searchFilter
},
timeSrv
));
const
observable
=
of
(
undefined
).
pipe
(
runUpdateTagsRequest
({
variable
,
datasource
,
searchFilter
},
timeSrv
));
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
expect
(
value
).
toEqual
([]);
expect
(
value
).
toEqual
([]);
expect
(
timeSrv
.
timeRange
).
not
.
toHaveBeenCalled
();
expect
(
timeSrv
.
timeRange
).
not
.
toHaveBeenCalled
();
},
done
,
});
});
});
});
});
});
describe
(
'when called with a datasource with metricFindQuery and variable that does not use Tags but refreshes on time range changes'
,
()
=>
{
describe
(
'when called with a datasource with metricFindQuery and variable that does not use Tags but refreshes on time range changes'
,
()
=>
{
it
(
'then the correct observable should be created'
,
done
=>
{
it
(
'then the correct observable should be created'
,
async
()
=>
{
const
variable
=
queryBuilder
()
const
variable
=
queryBuilder
()
.
withId
(
'query'
)
.
withId
(
'query'
)
.
withTags
(
false
)
.
withTags
(
false
)
...
@@ -163,14 +147,11 @@ describe('operators', () => {
...
@@ -163,14 +147,11 @@ describe('operators', () => {
const
searchFilter
=
'A search filter'
;
const
searchFilter
=
'A search filter'
;
const
observable
=
of
(
undefined
).
pipe
(
runUpdateTagsRequest
({
variable
,
datasource
,
searchFilter
},
timeSrv
));
const
observable
=
of
(
undefined
).
pipe
(
runUpdateTagsRequest
({
variable
,
datasource
,
searchFilter
},
timeSrv
));
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
expect
(
value
).
toEqual
([]);
expect
(
value
).
toEqual
([]);
expect
(
timeSrv
.
timeRange
).
not
.
toHaveBeenCalled
();
expect
(
timeSrv
.
timeRange
).
not
.
toHaveBeenCalled
();
expect
(
datasource
.
metricFindQuery
).
not
.
toHaveBeenCalled
();
expect
(
datasource
.
metricFindQuery
).
not
.
toHaveBeenCalled
();
},
done
,
});
});
});
});
});
});
...
@@ -178,7 +159,7 @@ describe('operators', () => {
...
@@ -178,7 +159,7 @@ describe('operators', () => {
describe
(
'updateOptionsState'
,
()
=>
{
describe
(
'updateOptionsState'
,
()
=>
{
describe
(
'when called'
,
()
=>
{
describe
(
'when called'
,
()
=>
{
it
(
'then the correct observable should be created'
,
done
=>
{
it
(
'then the correct observable should be created'
,
async
()
=>
{
const
variable
=
queryBuilder
()
const
variable
=
queryBuilder
()
.
withId
(
'query'
)
.
withId
(
'query'
)
.
build
();
.
build
();
...
@@ -187,9 +168,8 @@ describe('operators', () => {
...
@@ -187,9 +168,8 @@ describe('operators', () => {
const
observable
=
of
([{
text
:
'A'
}]).
pipe
(
updateOptionsState
({
variable
,
dispatch
,
getTemplatedRegexFunc
}));
const
observable
=
of
([{
text
:
'A'
}]).
pipe
(
updateOptionsState
({
variable
,
dispatch
,
getTemplatedRegexFunc
}));
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
expect
(
value
).
toEqual
(
undefined
);
expect
(
value
).
toEqual
(
undefined
);
expect
(
getTemplatedRegexFunc
).
toHaveBeenCalledTimes
(
1
);
expect
(
getTemplatedRegexFunc
).
toHaveBeenCalledTimes
(
1
);
expect
(
dispatch
).
toHaveBeenCalledTimes
(
1
);
expect
(
dispatch
).
toHaveBeenCalledTimes
(
1
);
...
@@ -200,8 +180,6 @@ describe('operators', () => {
...
@@ -200,8 +180,6 @@ describe('operators', () => {
data
:
{
results
:
[{
text
:
'A'
}],
templatedRegex
:
'getTemplatedRegexFunc result'
},
data
:
{
results
:
[{
text
:
'A'
}],
templatedRegex
:
'getTemplatedRegexFunc result'
},
})
})
);
);
},
done
,
});
});
});
});
});
});
...
@@ -278,23 +256,20 @@ describe('operators', () => {
...
@@ -278,23 +256,20 @@ describe('operators', () => {
],
],
},
},
].
map
(
scenario
=>
{
].
map
(
scenario
=>
{
it
(
`when called with series:
${
JSON
.
stringify
(
scenario
.
series
,
null
,
0
)}
`
,
done
=>
{
it
(
`when called with series:
${
JSON
.
stringify
(
scenario
.
series
,
null
,
0
)}
`
,
async
()
=>
{
const
{
series
,
expected
}
=
scenario
;
const
{
series
,
expected
}
=
scenario
;
const
panelData
:
any
=
{
series
};
const
panelData
:
any
=
{
series
};
const
observable
=
of
(
panelData
).
pipe
(
toMetricFindValues
());
const
observable
=
of
(
panelData
).
pipe
(
toMetricFindValues
());
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
expect
(
value
).
toEqual
(
expected
);
expect
(
value
).
toEqual
(
expected
);
},
done
,
});
});
});
});
});
});
describe
(
'when called without metric find values and string fields'
,
()
=>
{
describe
(
'when called without metric find values and string fields'
,
()
=>
{
it
(
'then the observable throws'
,
done
=>
{
it
(
'then the observable throws'
,
async
()
=>
{
const
frameWithTimeField
=
toDataFrame
({
const
frameWithTimeField
=
toDataFrame
({
fields
:
[{
name
:
'time'
,
type
:
FieldType
.
time
,
values
:
[
1
,
2
,
3
]
}],
fields
:
[{
name
:
'time'
,
type
:
FieldType
.
time
,
values
:
[
1
,
2
,
3
]
}],
});
});
...
@@ -302,12 +277,9 @@ describe('operators', () => {
...
@@ -302,12 +277,9 @@ describe('operators', () => {
const
panelData
:
any
=
{
series
:
[
frameWithTimeField
]
};
const
panelData
:
any
=
{
series
:
[
frameWithTimeField
]
};
const
observable
=
of
(
panelData
).
pipe
(
toMetricFindValues
());
const
observable
=
of
(
panelData
).
pipe
(
toMetricFindValues
());
observableTester
().
subscribeAndExpectOnError
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
expect
(
value
).
toEqual
(
new
Error
(
"Couldn't find any field of type string in the results."
));
expect
(
value
).
toEqual
(
new
Error
(
"Couldn't find any field of type string in the results."
));
},
done
,
});
});
});
});
});
});
...
...
public/app/features/variables/query/queryRunners.test.ts
View file @
b904e0c6
import
{
QueryRunners
}
from
'./queryRunners'
;
import
{
QueryRunners
}
from
'./queryRunners'
;
import
{
DefaultTimeRange
,
observableTester
,
VariableSupportType
}
from
'@grafana/data'
;
import
{
DefaultTimeRange
,
VariableSupportType
}
from
'@grafana/data'
;
import
{
VariableRefresh
}
from
'../types'
;
import
{
VariableRefresh
}
from
'../types'
;
import
{
of
}
from
'rxjs'
;
import
{
of
}
from
'rxjs'
;
...
@@ -41,17 +41,14 @@ describe('QueryRunners', () => {
...
@@ -41,17 +41,14 @@ describe('QueryRunners', () => {
});
});
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
it
(
'then it should return correct observable'
,
done
=>
{
it
(
'then it should return correct observable'
,
async
()
=>
{
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
values
=>
{
expect
(
value
).
toEqual
({
expect
(
values
).
toEqual
({
series
:
[{
text
:
'A'
,
value
:
'A'
}],
series
:
[{
text
:
'A'
,
value
:
'A'
}],
state
:
'Done'
,
state
:
'Done'
,
timeRange
:
{
from
:
{},
raw
:
{
from
:
'6h'
,
to
:
'now'
},
to
:
{}
},
timeRange
:
{
from
:
{},
raw
:
{
from
:
'6h'
,
to
:
'now'
},
to
:
{}
},
});
});
},
done
,
});
});
});
});
...
@@ -86,17 +83,14 @@ describe('QueryRunners', () => {
...
@@ -86,17 +83,14 @@ describe('QueryRunners', () => {
});
});
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
it
(
'then it should return correct observable'
,
done
=>
{
it
(
'then it should return correct observable'
,
async
()
=>
{
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
values
=
received
[
0
];
expect
:
values
=>
{
expect
(
values
).
toEqual
({
expect
(
values
).
toEqual
({
series
:
[{
text
:
'A'
,
value
:
'A'
}],
series
:
[{
text
:
'A'
,
value
:
'A'
}],
state
:
'Done'
,
state
:
'Done'
,
timeRange
:
{
from
:
{},
raw
:
{
from
:
'6h'
,
to
:
'now'
},
to
:
{}
},
timeRange
:
{
from
:
{},
raw
:
{
from
:
'6h'
,
to
:
'now'
},
to
:
{}
},
});
});
},
done
,
});
});
});
});
...
@@ -161,13 +155,10 @@ describe('QueryRunners', () => {
...
@@ -161,13 +155,10 @@ describe('QueryRunners', () => {
});
});
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
it
(
'then it should return correct observable'
,
done
=>
{
it
(
'then it should return correct observable'
,
async
()
=>
{
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
expect
(
value
).
toEqual
({});
expect
(
value
).
toEqual
({});
},
done
,
});
});
});
});
...
@@ -183,13 +174,10 @@ describe('QueryRunners', () => {
...
@@ -183,13 +174,10 @@ describe('QueryRunners', () => {
});
});
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
it
(
'then it should return correct observable'
,
done
=>
{
it
(
'then it should return correct observable'
,
async
()
=>
{
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
expect
(
value
).
toEqual
({});
expect
(
value
).
toEqual
({});
},
done
,
});
});
});
});
...
@@ -234,13 +222,10 @@ describe('QueryRunners', () => {
...
@@ -234,13 +222,10 @@ describe('QueryRunners', () => {
const
{
runner
,
request
,
runnerArgs
,
runRequest
,
datasource
}
=
getCustomTestContext
();
const
{
runner
,
request
,
runnerArgs
,
runRequest
,
datasource
}
=
getCustomTestContext
();
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
it
(
'then it should return correct observable'
,
done
=>
{
it
(
'then it should return correct observable'
,
async
()
=>
{
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
expect
(
value
).
toEqual
({});
expect
(
value
).
toEqual
({});
},
done
,
});
});
});
});
...
@@ -285,13 +270,10 @@ describe('QueryRunners', () => {
...
@@ -285,13 +270,10 @@ describe('QueryRunners', () => {
const
{
runner
,
request
,
runnerArgs
,
runRequest
,
datasource
}
=
getDatasourceTestContext
();
const
{
runner
,
request
,
runnerArgs
,
runRequest
,
datasource
}
=
getDatasourceTestContext
();
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
const
observable
=
runner
.
runRequest
(
runnerArgs
,
request
);
it
(
'then it should return correct observable'
,
done
=>
{
it
(
'then it should return correct observable'
,
async
()
=>
{
observableTester
().
subscribeAndExpectOnNext
({
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
observable
,
const
value
=
received
[
0
];
expect
:
value
=>
{
expect
(
value
).
toEqual
({});
expect
(
value
).
toEqual
({});
},
done
,
});
});
});
});
...
...
public/app/plugins/datasource/cloud-monitoring/specs/datasource.test.ts
View file @
b904e0c6
import
{
of
,
throwError
}
from
'rxjs'
;
import
{
of
,
throwError
}
from
'rxjs'
;
import
{
DataSourceInstanceSettings
,
observableTester
,
toUtc
}
from
'@grafana/data'
;
import
{
DataSourceInstanceSettings
,
toUtc
}
from
'@grafana/data'
;
import
CloudMonitoringDataSource
from
'../datasource'
;
import
CloudMonitoringDataSource
from
'../datasource'
;
import
{
metricDescriptors
}
from
'./testData'
;
import
{
metricDescriptors
}
from
'./testData'
;
...
@@ -84,7 +84,7 @@ describe('CloudMonitoringDataSource', () => {
...
@@ -84,7 +84,7 @@ describe('CloudMonitoringDataSource', () => {
describe
(
'When performing query'
,
()
=>
{
describe
(
'When performing query'
,
()
=>
{
describe
(
'and no time series data is returned'
,
()
=>
{
describe
(
'and no time series data is returned'
,
()
=>
{
it
(
'should return a list of datapoints'
,
done
=>
{
it
(
'should return a list of datapoints'
,
async
()
=>
{
const
options
=
{
const
options
=
{
range
:
{
range
:
{
from
:
toUtc
(
'2017-08-22T20:00:00Z'
),
from
:
toUtc
(
'2017-08-22T20:00:00Z'
),
...
@@ -116,12 +116,9 @@ describe('CloudMonitoringDataSource', () => {
...
@@ -116,12 +116,9 @@ describe('CloudMonitoringDataSource', () => {
const
{
ds
}
=
getTestcontext
({
response
});
const
{
ds
}
=
getTestcontext
({
response
});
observableTester
().
subscribeAndExpectOnNext
(
{
await
expect
(
ds
.
query
(
options
as
any
)).
toEmitValuesWith
(
received
=>
{
expect
:
results
=>
{
const
results
=
received
[
0
];
expect
(
results
.
data
.
length
).
toBe
(
0
);
expect
(
results
.
data
.
length
).
toBe
(
0
);
},
observable
:
ds
.
query
(
options
as
any
),
done
,
});
});
});
});
});
});
...
...
public/app/plugins/datasource/cloudwatch/datasource.test.ts
View file @
b904e0c6
import
{
of
}
from
'rxjs'
;
import
{
of
}
from
'rxjs'
;
import
{
setBackendSrv
}
from
'@grafana/runtime'
;
import
{
setBackendSrv
}
from
'@grafana/runtime'
;
import
{
dateTime
,
DefaultTimeRange
,
observableTester
}
from
'@grafana/data'
;
import
{
dateTime
,
DefaultTimeRange
}
from
'@grafana/data'
;
import
{
TemplateSrv
}
from
'../../../features/templating/template_srv'
;
import
{
TemplateSrv
}
from
'../../../features/templating/template_srv'
;
import
{
CloudWatchDatasource
}
from
'./datasource'
;
import
{
CloudWatchDatasource
}
from
'./datasource'
;
describe
(
'datasource'
,
()
=>
{
describe
(
'datasource'
,
()
=>
{
describe
(
'query'
,
()
=>
{
describe
(
'query'
,
()
=>
{
it
(
'should return error if log query and log groups is not specified'
,
done
=>
{
it
(
'should return error if log query and log groups is not specified'
,
async
()
=>
{
const
{
datasource
}
=
setup
();
const
{
datasource
}
=
setup
();
const
observable
=
datasource
.
query
({
observableTester
().
subscribeAndExpectOnNext
({
observable
:
datasource
.
query
({
targets
:
[
targets
:
[
{
{
queryMode
:
'Logs'
as
'Logs'
,
queryMode
:
'Logs'
as
'Logs'
,
},
},
],
],
}
as
any
),
}
as
any
);
expect
:
response
=>
{
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
const
response
=
received
[
0
];
expect
(
response
.
error
?.
message
).
toBe
(
'Log group is required'
);
expect
(
response
.
error
?.
message
).
toBe
(
'Log group is required'
);
},
done
,
});
});
});
});
it
(
'should return empty response if queries are hidden'
,
done
=>
{
it
(
'should return empty response if queries are hidden'
,
async
()
=>
{
const
{
datasource
}
=
setup
();
const
{
datasource
}
=
setup
();
const
observable
=
datasource
.
query
({
observableTester
().
subscribeAndExpectOnNext
({
observable
:
datasource
.
query
({
targets
:
[
targets
:
[
{
{
queryMode
:
'Logs'
as
'Logs'
,
queryMode
:
'Logs'
as
'Logs'
,
hide
:
true
,
hide
:
true
,
},
},
],
],
}
as
any
),
}
as
any
);
expect
:
response
=>
{
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
const
response
=
received
[
0
];
expect
(
response
.
data
).
toEqual
([]);
expect
(
response
.
data
).
toEqual
([]);
},
done
,
});
});
});
});
});
});
describe
(
'performTimeSeriesQuery'
,
()
=>
{
describe
(
'performTimeSeriesQuery'
,
()
=>
{
it
(
'should return the same length of data as result'
,
done
=>
{
it
(
'should return the same length of data as result'
,
async
()
=>
{
const
{
datasource
}
=
setup
({
const
{
datasource
}
=
setup
({
data
:
{
data
:
{
results
:
{
results
:
{
...
@@ -58,8 +54,7 @@ describe('datasource', () => {
...
@@ -58,8 +54,7 @@ describe('datasource', () => {
const
buildCloudwatchConsoleUrlMock
=
jest
.
spyOn
(
datasource
,
'buildCloudwatchConsoleUrl'
);
const
buildCloudwatchConsoleUrlMock
=
jest
.
spyOn
(
datasource
,
'buildCloudwatchConsoleUrl'
);
buildCloudwatchConsoleUrlMock
.
mockImplementation
(()
=>
''
);
buildCloudwatchConsoleUrlMock
.
mockImplementation
(()
=>
''
);
observableTester
().
subscribeAndExpectOnNext
({
const
observable
=
datasource
.
performTimeSeriesQuery
(
observable
:
datasource
.
performTimeSeriesQuery
(
{
{
queries
:
[
queries
:
[
{
datasourceId
:
1
,
refId
:
'a'
},
{
datasourceId
:
1
,
refId
:
'a'
},
...
@@ -67,11 +62,11 @@ describe('datasource', () => {
...
@@ -67,11 +62,11 @@ describe('datasource', () => {
],
],
}
as
any
,
}
as
any
,
{
from
:
dateTime
(),
to
:
dateTime
()
}
as
any
{
from
:
dateTime
(),
to
:
dateTime
()
}
as
any
),
);
expect
:
response
=>
{
await
expect
(
observable
).
toEmitValuesWith
(
received
=>
{
const
response
=
received
[
0
];
expect
(
response
.
data
.
length
).
toEqual
(
2
);
expect
(
response
.
data
.
length
).
toEqual
(
2
);
},
done
,
});
});
});
});
});
});
...
...
public/app/plugins/datasource/cloudwatch/specs/datasource.test.ts
View file @
b904e0c6
This diff is collapsed.
Click to expand it.
public/app/plugins/datasource/loki/datasource.test.ts
View file @
b904e0c6
...
@@ -11,6 +11,7 @@ import { backendSrv } from 'app/core/services/backend_srv';
...
@@ -11,6 +11,7 @@ import { backendSrv } from 'app/core/services/backend_srv';
import
{
CustomVariableModel
}
from
'../../../features/variables/types'
;
import
{
CustomVariableModel
}
from
'../../../features/variables/types'
;
import
{
initialCustomVariableModelState
}
from
'../../../features/variables/custom/reducer'
;
import
{
initialCustomVariableModelState
}
from
'../../../features/variables/custom/reducer'
;
import
{
makeMockLokiDatasource
}
from
'./mocks'
;
import
{
makeMockLokiDatasource
}
from
'./mocks'
;
import
{
createFetchResponse
}
from
'test/helpers/createFetchResponse'
;
jest
.
mock
(
'@grafana/runtime'
,
()
=>
({
jest
.
mock
(
'@grafana/runtime'
,
()
=>
({
// @ts-ignore
// @ts-ignore
...
@@ -593,17 +594,3 @@ function makeMetadataAndVersionsMocks() {
...
@@ -593,17 +594,3 @@ function makeMetadataAndVersionsMocks() {
}
}
return
mocks
;
return
mocks
;
}
}
function
createFetchResponse
<
T
>
(
data
:
T
):
FetchResponse
<
T
>
{
return
{
data
,
status
:
200
,
url
:
'http://localhost:3000/api/query'
,
config
:
{
url
:
'http://localhost:3000/api/query'
},
type
:
'basic'
,
statusText
:
'Ok'
,
redirected
:
false
,
headers
:
({}
as
unknown
)
as
Headers
,
ok
:
true
,
};
}
public/app/plugins/datasource/mssql/specs/datasource.test.ts
View file @
b904e0c6
...
@@ -6,7 +6,7 @@ import { TimeSrvStub } from 'test/specs/helpers';
...
@@ -6,7 +6,7 @@ import { TimeSrvStub } from 'test/specs/helpers';
import
{
TemplateSrv
}
from
'app/features/templating/template_srv'
;
import
{
TemplateSrv
}
from
'app/features/templating/template_srv'
;
import
{
backendSrv
}
from
'app/core/services/backend_srv'
;
import
{
backendSrv
}
from
'app/core/services/backend_srv'
;
import
{
initialCustomVariableModelState
}
from
'../../../../features/variables/custom/reducer'
;
import
{
initialCustomVariableModelState
}
from
'../../../../features/variables/custom/reducer'
;
import
{
FetchResponse
}
from
'@grafana/runtime'
;
// will use the version in __mocks__
import
{
createFetchResponse
}
from
'test/helpers/createFetchResponse'
;
jest
.
mock
(
'@grafana/runtime'
,
()
=>
({
jest
.
mock
(
'@grafana/runtime'
,
()
=>
({
...((
jest
.
requireActual
(
'@grafana/runtime'
)
as
unknown
)
as
object
),
...((
jest
.
requireActual
(
'@grafana/runtime'
)
as
unknown
)
as
object
),
...
@@ -334,17 +334,3 @@ describe('MSSQLDatasource', () => {
...
@@ -334,17 +334,3 @@ describe('MSSQLDatasource', () => {
});
});
});
});
});
});
function
createFetchResponse
<
T
>
(
data
:
T
):
FetchResponse
<
T
>
{
return
{
data
,
status
:
200
,
url
:
'http://localhost:3000/api/query'
,
config
:
{
url
:
'http://localhost:3000/api/query'
},
type
:
'basic'
,
statusText
:
'Ok'
,
redirected
:
false
,
headers
:
({}
as
unknown
)
as
Headers
,
ok
:
true
,
};
}
public/test/helpers/createFetchResponse.ts
View file @
b904e0c6
...
@@ -4,8 +4,8 @@ export function createFetchResponse<T>(data: T): FetchResponse<T> {
...
@@ -4,8 +4,8 @@ export function createFetchResponse<T>(data: T): FetchResponse<T> {
return
{
return
{
data
,
data
,
status
:
200
,
status
:
200
,
url
:
'http://localhost:3000/api/query'
,
url
:
'http://localhost:3000/api/
tsdb/
query'
,
config
:
{
url
:
'http://localhost:3000/api/query'
},
config
:
{
url
:
'http://localhost:3000/api/
tsdb/
query'
},
type
:
'basic'
,
type
:
'basic'
,
statusText
:
'Ok'
,
statusText
:
'Ok'
,
redirected
:
false
,
redirected
:
false
,
...
...
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