|
|
|
@ -18,7 +18,7 @@ import { |
|
|
|
|
TimeRange, |
|
|
|
|
toUtc, |
|
|
|
|
} from '@grafana/data'; |
|
|
|
|
import { BackendSrvRequest, FetchResponse, reportInteraction } from '@grafana/runtime'; |
|
|
|
|
import { BackendSrvRequest, FetchResponse, reportInteraction, config } from '@grafana/runtime'; |
|
|
|
|
import { backendSrv } from 'app/core/services/backend_srv'; // will use the version in __mocks__
|
|
|
|
|
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv'; |
|
|
|
|
import { TemplateSrv } from 'app/features/templating/template_srv'; |
|
|
|
@ -31,6 +31,8 @@ import { Filters, ElasticsearchOptions, ElasticsearchQuery } from './types'; |
|
|
|
|
|
|
|
|
|
const ELASTICSEARCH_MOCK_URL = 'http://elasticsearch.local'; |
|
|
|
|
|
|
|
|
|
const originalConsoleError = console.error; |
|
|
|
|
|
|
|
|
|
jest.mock('@grafana/runtime', () => ({ |
|
|
|
|
...jest.requireActual('@grafana/runtime'), |
|
|
|
|
getBackendSrv: () => backendSrv, |
|
|
|
@ -1291,3 +1293,37 @@ const logsResponse = { |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
describe('ElasticDatasource using backend', () => { |
|
|
|
|
beforeEach(() => { |
|
|
|
|
console.error = jest.fn(); |
|
|
|
|
config.featureToggles.enableElasticsearchBackendQuerying = true; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
afterEach(() => { |
|
|
|
|
console.error = originalConsoleError; |
|
|
|
|
config.featureToggles.enableElasticsearchBackendQuerying = false; |
|
|
|
|
}); |
|
|
|
|
describe('getDatabaseVersion', () => { |
|
|
|
|
it('should correctly get db version', async () => { |
|
|
|
|
const { ds } = getTestContext(); |
|
|
|
|
ds.getResource = jest.fn().mockResolvedValue({ version: { number: '8.0.0' } }); |
|
|
|
|
const version = await ds.getDatabaseVersion(); |
|
|
|
|
expect(version?.raw).toBe('8.0.0'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should correctly return null if invalid numeric version', async () => { |
|
|
|
|
const { ds } = getTestContext(); |
|
|
|
|
ds.getResource = jest.fn().mockResolvedValue({ version: { number: 8 } }); |
|
|
|
|
const version = await ds.getDatabaseVersion(); |
|
|
|
|
expect(version).toBe(null); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should correctly return null if rejected request', async () => { |
|
|
|
|
const { ds } = getTestContext(); |
|
|
|
|
ds.getResource = jest.fn().mockRejectedValue({}); |
|
|
|
|
const version = await ds.getDatabaseVersion(); |
|
|
|
|
expect(version).toBe(null); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|