-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Automatic Import] add fields mapping to readme #193717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
haetamoudi
merged 12 commits into
elastic:main
from
haetamoudi:automatic-import-readme-with-fields-mapping
Sep 30, 2024
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7d781d5
add mapping to readme
haetamoudi 184e334
rename readme module
haetamoudi 9a14b60
fix merge conflicts
haetamoudi ec0197c
use field interface to specify param type
haetamoudi 282853f
remove desc
haetamoudi bb0bef8
add fields to readme
haetamoudi c648dd0
add datastream fields to readme
haetamoudi 9b11ece
merge main
haetamoudi 6b70c9b
handle empty lines in descr
haetamoudi fce0935
eslint
haetamoudi 499fad6
Merge branch 'main' into automatic-import-readme-with-fields-mapping
haetamoudi c58a58f
fix typo
haetamoudi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
149 changes: 149 additions & 0 deletions
149
x-pack/plugins/integration_assistant/server/integration_builder/readme_files.test.ts
This file contains hidden or 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,149 @@ | ||
| /* | ||
| * 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 { testIntegration } from '../../__jest__/fixtures/build_integration'; | ||
| import { ensureDirSync, createSync } from '../util'; | ||
| import { configure } from 'nunjucks'; | ||
| import { join as joinPath } from 'path'; | ||
| import { createReadme } from './readme_files'; | ||
|
|
||
| jest.mock('../util', () => ({ | ||
| ...jest.requireActual('../util'), | ||
| createSync: jest.fn(), | ||
| ensureDirSync: jest.fn(), | ||
| })); | ||
|
|
||
| describe('createReadme', () => { | ||
| const integrationPath = 'path'; | ||
|
|
||
| const templateDir = joinPath(__dirname, '../templates'); | ||
| configure([templateDir], { | ||
| autoescape: false, | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('Should create expected files', async () => { | ||
| const fields = [ | ||
| { | ||
| datastream: 'data_stream_1', | ||
| fields: [ | ||
| { | ||
| name: 'data_stream.type', | ||
| type: 'constant_keyword', | ||
| description: 'Data stream type.', | ||
| }, | ||
| { | ||
| name: 'data_stream.dataset', | ||
| type: 'constant_keyword', | ||
| description: 'Data stream dataset name.', | ||
| }, | ||
| { | ||
| name: 'event.dataset', | ||
| type: 'constant_keyword', | ||
| description: 'Event dataset', | ||
| value: 'package.datastream', | ||
| }, | ||
| { name: '@timestamp', type: 'date', description: 'Event timestamp.' }, | ||
| ], | ||
| }, | ||
| { | ||
| datastream: 'data_stream_2', | ||
| fields: [{ name: '@timestamp', type: 'date', description: 'Event timestamp.' }], | ||
| }, | ||
| ]; | ||
|
|
||
| createReadme(integrationPath, testIntegration.name, fields); | ||
|
|
||
| expect(createSync).toHaveBeenCalledWith( | ||
| `${integrationPath}/_dev/build/docs/README.md`, | ||
| expect.any(String) | ||
| ); | ||
|
|
||
| // Docs files | ||
| expect(ensureDirSync).toHaveBeenCalledWith(`${integrationPath}/docs/`); | ||
| expect(createSync).toHaveBeenCalledWith( | ||
| `${integrationPath}/docs/README.md`, | ||
| expect.any(String) | ||
| ); | ||
| }); | ||
|
|
||
| it('Should render a table per datastream with fields mapping in package readme', async () => { | ||
| const fields = [ | ||
| { | ||
| datastream: 'data_stream_1', | ||
| fields: [ | ||
| { | ||
| name: 'data_stream.type', | ||
| type: 'constant_keyword', | ||
| description: 'Data stream type.', | ||
| }, | ||
| { | ||
| name: 'data_stream.dataset', | ||
| type: 'constant_keyword', | ||
| }, | ||
| { | ||
| name: 'event.dataset', | ||
| type: 'constant_keyword', | ||
| description: 'Event dataset', | ||
| value: 'package.datastream', | ||
| }, | ||
| { name: '@timestamp', type: 'date', description: 'Event timestamp.' }, | ||
| ], | ||
| }, | ||
| { | ||
| datastream: 'data_stream_2', | ||
| fields: [{ name: '@timestamp', type: 'date', description: 'Event timestamp.' }], | ||
| }, | ||
| ]; | ||
|
|
||
| createReadme(integrationPath, testIntegration.name, fields); | ||
|
|
||
| const firstDatastreamFieldsDisplayed = ` | ||
| | Field | Description | Type | | ||
| |---|---|---| | ||
| | data_stream.type | Data stream type. | constant_keyword | | ||
| | data_stream.dataset | Insert a description | constant_keyword | | ||
| | event.dataset | Event dataset | constant_keyword | | ||
| | @timestamp | Event timestamp. | date | | ||
| `; | ||
|
|
||
| const secondDatastreamFieldsDisplayed = ` | ||
| | Field | Description | Type | | ||
| |---|---|---| | ||
| | @timestamp | Event timestamp. | date | | ||
| `; | ||
|
|
||
| expect(createSync).toHaveBeenCalledWith( | ||
| `${integrationPath}/docs/README.md`, | ||
| expect.stringContaining(firstDatastreamFieldsDisplayed) | ||
| ); | ||
|
|
||
| expect(createSync).toHaveBeenCalledWith( | ||
| `${integrationPath}/docs/README.md`, | ||
| expect.stringContaining(secondDatastreamFieldsDisplayed) | ||
| ); | ||
| }); | ||
|
|
||
| it('Should not render a fields mapping table in build readme', async () => { | ||
| const fields = [ | ||
| { | ||
| datastream: 'data_stream_1', | ||
| fields: [{ name: '@timestamp', type: 'date', description: 'Event timestamp.' }], | ||
| }, | ||
| ]; | ||
|
|
||
| createReadme(integrationPath, testIntegration.name, fields); | ||
|
|
||
| expect(createSync).toHaveBeenCalledWith( | ||
| `${integrationPath}/_dev/build/docs/README.md`, | ||
| expect.stringContaining('{{fields "data_stream_1"}}') | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.