-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/files-server-integration-tests
- Loading branch information
Showing
75 changed files
with
6,069 additions
and
1 deletion.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
...est_serverless/api_integration/test_suites/common/data_view_field_editor/field_preview.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
|
||
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; | ||
import { getErrorCodeFromErrorReason } from '@kbn/data-view-field-editor-plugin/public/lib/runtime_field_validation'; | ||
import { | ||
FIELD_PREVIEW_PATH, | ||
INITIAL_REST_VERSION, | ||
} from '@kbn/data-view-field-editor-plugin/common/constants'; | ||
import type { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
const INDEX_NAME = 'api-integration-test-field-preview'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
const svlCommonApi = getService('svlCommonApi'); | ||
|
||
const document = { foo: 1, bar: 'hello' }; | ||
|
||
const createIndex = async () => { | ||
await es.indices.create({ | ||
index: INDEX_NAME, | ||
body: { | ||
mappings: { | ||
properties: { | ||
foo: { | ||
type: 'integer', | ||
}, | ||
bar: { | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}; | ||
|
||
const deleteIndex = async () => { | ||
await es.indices.delete({ | ||
index: INDEX_NAME, | ||
}); | ||
}; | ||
|
||
describe('Field preview', function () { | ||
before(async () => await createIndex()); | ||
after(async () => await deleteIndex()); | ||
|
||
describe('should return the script value', () => { | ||
const tests = [ | ||
{ | ||
context: 'keyword_field', | ||
script: { | ||
source: 'emit("test")', | ||
}, | ||
expected: 'test', | ||
}, | ||
{ | ||
context: 'long_field', | ||
script: { | ||
source: 'emit(doc["foo"].value + 1)', | ||
}, | ||
expected: 2, | ||
}, | ||
{ | ||
context: 'keyword_field', | ||
script: { | ||
source: 'emit(doc["bar"].value + " world")', | ||
}, | ||
expected: 'hello world', | ||
}, | ||
]; | ||
|
||
tests.forEach((test) => { | ||
it(`> ${test.context}`, async () => { | ||
const payload = { | ||
script: test.script, | ||
document, | ||
context: test.context, | ||
index: INDEX_NAME, | ||
}; | ||
|
||
const { body: response } = await supertest | ||
.post(FIELD_PREVIEW_PATH) | ||
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION) | ||
// TODO: API requests in Serverless require internal request headers | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.send(payload) | ||
.set('kbn-xsrf', 'xxx') | ||
.expect(200); | ||
|
||
expect(response.values).eql([test.expected]); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('payload validation', () => { | ||
it('should require a script', async () => { | ||
await supertest | ||
.post(FIELD_PREVIEW_PATH) | ||
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION) | ||
// TODO: API requests in Serverless require internal request headers | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.send({ | ||
context: 'keyword_field', | ||
index: INDEX_NAME, | ||
}) | ||
.set('kbn-xsrf', 'xxx') | ||
.expect(400); | ||
}); | ||
|
||
it('should require a context', async () => { | ||
await supertest | ||
.post(FIELD_PREVIEW_PATH) | ||
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION) | ||
// TODO: API requests in Serverless require internal request headers | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.send({ | ||
script: { source: 'emit("hello")' }, | ||
index: INDEX_NAME, | ||
}) | ||
.set('kbn-xsrf', 'xxx') | ||
.expect(400); | ||
}); | ||
|
||
it('should require an index', async () => { | ||
await supertest | ||
.post(FIELD_PREVIEW_PATH) | ||
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION) | ||
// TODO: API requests in Serverless require internal request headers | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.send({ | ||
script: { source: 'emit("hello")' }, | ||
context: 'keyword_field', | ||
}) | ||
.set('kbn-xsrf', 'xxx') | ||
.expect(400); | ||
}); | ||
}); | ||
|
||
describe('Error messages', () => { | ||
// As ES does not return error codes we will add a test to make sure its error message string | ||
// does not change overtime as we rely on it to extract our own error code. | ||
// If this test fail we'll need to update the "getErrorCodeFromErrorReason()" handler | ||
// TODO: `response.error?.caused_by?.reason` returns | ||
// `class_cast_exception: Cannot cast from [int] to [java.lang.String].` | ||
// in Serverless, which causes `getErrorCodeFromErrorReason` to fail | ||
it.skip('should detect a script casting error', async () => { | ||
const { body: response } = await supertest | ||
.post(FIELD_PREVIEW_PATH) | ||
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION) | ||
// TODO: API requests in Serverless require internal request headers | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.send({ | ||
script: { source: 'emit(123)' }, // We send a long but the type is "keyword" | ||
context: 'keyword_field', | ||
index: INDEX_NAME, | ||
}) | ||
.set('kbn-xsrf', 'xxx'); | ||
|
||
const errorCode = getErrorCodeFromErrorReason(response.error?.caused_by?.reason); | ||
|
||
expect(errorCode).be('CAST_ERROR'); | ||
}); | ||
}); | ||
}); | ||
} |
14 changes: 14 additions & 0 deletions
14
x-pack/test_serverless/api_integration/test_suites/common/data_view_field_editor/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export default function ({ loadTestFile }: FtrProviderContext) { | ||
describe('index pattern field editor', () => { | ||
loadTestFile(require.resolve('./field_preview')); | ||
}); | ||
} |
31 changes: 31 additions & 0 deletions
31
x-pack/test_serverless/api_integration/test_suites/common/data_views/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
DATA_VIEW_PATH_LEGACY, | ||
SERVICE_KEY_LEGACY, | ||
DATA_VIEW_PATH, | ||
SERVICE_KEY, | ||
SERVICE_PATH, | ||
SERVICE_PATH_LEGACY, | ||
} from '@kbn/data-views-plugin/server'; | ||
|
||
const legacyConfig = { | ||
name: 'legacy index pattern api', | ||
path: DATA_VIEW_PATH_LEGACY, | ||
basePath: SERVICE_PATH_LEGACY, | ||
serviceKey: SERVICE_KEY_LEGACY, | ||
}; | ||
|
||
export const dataViewConfig = { | ||
name: 'data view api', | ||
path: DATA_VIEW_PATH, | ||
basePath: SERVICE_PATH, | ||
serviceKey: SERVICE_KEY, | ||
}; | ||
|
||
export const configArray = [legacyConfig, dataViewConfig]; |
15 changes: 15 additions & 0 deletions
15
...s/api_integration/test_suites/common/data_views/data_views_crud/create_data_view/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { FtrProviderContext } from '../../../../../ftr_provider_context'; | ||
|
||
export default function ({ loadTestFile }: FtrProviderContext) { | ||
describe('create_index_pattern', () => { | ||
loadTestFile(require.resolve('./validation')); | ||
loadTestFile(require.resolve('./main')); | ||
}); | ||
} |
Oops, something went wrong.