Skip to content

Commit

Permalink
start adding / updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Sep 30, 2024
1 parent 27c0276 commit 69be8a0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
11 changes: 11 additions & 0 deletions x-pack/plugins/fleet/server/services/epm/archive/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ describe('getPathParts', () => {
type: 'fields',
},
},
{
path: 'knowledgebase-1.0.1/kibana/knowledge_base_entry/foo/manifest.yml',
assetParts: {
dataset: 'foo',
file: 'manifest.yml',
path: 'knowledgebase-1.0.1/kibana/knowledge_base_entry/foo/manifest.yml',
pkgkey: 'knowledgebase-1.0.1',
service: 'kibana',
type: 'knowledge_base_entry',
},
},
];
test('testPathParts', () => {
for (const value of testPaths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,31 @@ describe('EPM template', () => {
expect(mappings).toEqual(runtimeFieldMapping);
});

it('tests processing semantic_text fields', () => {
const textWithRuntimeFieldsLiteralYml = `
- name: sem_without_inference_id
type: semantic_text
- name: sem_with_inference_id
type: semantic_text
inference_id: .model_id
`;
const semanticFieldMapping = {
properties: {
sem_without_inference_id: {
type: 'semantic_text',
},
sem_with_inference_id: {
inference_id: '.model_id',
type: 'semantic_text',
},
},
};
const fields: Field[] = load(textWithRuntimeFieldsLiteralYml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields, true);
expect(mappings).toEqual(semanticFieldMapping);
});

it('tests unexpected type for field as dynamic template fails', () => {
const textWithRuntimeFieldsLiteralYml = `
- name: labels.*
Expand Down
31 changes: 30 additions & 1 deletion x-pack/plugins/fleet/server/services/epm/fields/field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import path from 'path';
import globby from 'globby';
import { load } from 'js-yaml';

import { getField, processFields, processFieldsWithWildcard } from './field';
import {
getField,
processFields,
processFieldsWithWildcard,
filterForKnowledgeBaseEntryAssets,
} from './field';
import type { Field, Fields } from './field';

// Add our own serialiser to just do JSON.stringify
Expand Down Expand Up @@ -813,3 +818,27 @@ describe('processFields', () => {
});
});
});

describe('filterForKnowledgeBaseEntryAssets', () => {
it('returns true for assets within the given knowledge base entry folder', () => {
expect(
filterForKnowledgeBaseEntryAssets('foo')(
'/kb-1.0/kibana/knowledge_base_entry/foo/manifest.yml'
)
).toBe(true);
});
it('returns false for assets within another knowledge base entry folder', () => {
expect(
filterForKnowledgeBaseEntryAssets('bar')(
'/kb-1.0/kibana/knowledge_base_entry/foo/manifest.yml'
)
).toBe(false);
});
it('returns false for assets outside of a knowledge base entry folder', () => {
expect(
filterForKnowledgeBaseEntryAssets('foo')(
'/kb-1.0/kibana/dashboard/some_dashboard.json'
)
).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { saveArchiveEntriesFromAssetsMap } from '../../archive/storage';
jest.mock('../../elasticsearch/template/template');
jest.mock('../../kibana/assets/install');
jest.mock('../../kibana/index_pattern/install');
jest.mock('../../kibana/knowledge_base/install');
jest.mock('../get');
jest.mock('../install_index_template_pipeline');

Expand Down

0 comments on commit 69be8a0

Please sign in to comment.