@@ -38,6 +38,7 @@ import type {
3838 PostPackagePolicyPostCreateCallback ,
3939 PostPackagePolicyDeleteCallback ,
4040 UpdatePackagePolicy ,
41+ AssetsMap ,
4142} from '../types' ;
4243import { createPackagePolicyMock } from '../../common/mocks' ;
4344
@@ -58,6 +59,7 @@ import type {
5859 DeletePackagePoliciesResponse ,
5960 PackagePolicyAssetsMap ,
6061 PreconfiguredInputs ,
62+ ArchiveEntry ,
6163} from '../../common/types' ;
6264import { packageToPackagePolicy , packageToPackagePolicyInputs } from '../../common/services' ;
6365
@@ -73,6 +75,7 @@ import {
7375 _compilePackagePolicyInputs ,
7476 _validateRestrictedFieldsNotModifiedOrThrow ,
7577 _normalizePackagePolicyKuery ,
78+ _getAssetForTemplatePath ,
7679} from './package_policy' ;
7780import { appContextService } from '.' ;
7881
@@ -8808,3 +8811,54 @@ describe('_normalizePackagePolicyKuery', () => {
88088811 expect ( res ) . toEqual ( 'ingest-package-policies.attributes.name:test' ) ;
88098812 } ) ;
88108813} ) ;
8814+
8815+ describe ( '_getAssetForTemplatePath()' , ( ) => {
8816+ it ( 'should return the asset for the given template path' , ( ) => {
8817+ const pkgInfo : PackageInfo = {
8818+ name : 'test_package' ,
8819+ version : '1.0.0' ,
8820+ type : 'integration' ,
8821+ } as any ;
8822+ const datasetPath = 'test_data_stream' ;
8823+ const templatePath = 'log.yml.hbs' ;
8824+ const assetsMap : AssetsMap = new Map ( ) ;
8825+ assetsMap . set (
8826+ `test_package-1.0.0/data_stream/${ datasetPath } /agent/stream/syslog.yml.hbs` ,
8827+ Buffer . from ( 'wrong match asset' )
8828+ ) ;
8829+ assetsMap . set (
8830+ `test_package-1.0.0/data_stream/${ datasetPath } /agent/stream/log.yml.hbs` ,
8831+ Buffer . from ( 'exact match asset' )
8832+ ) ;
8833+
8834+ const expectedAsset : ArchiveEntry = {
8835+ path : 'test_package-1.0.0/data_stream/test_data_stream/agent/stream/log.yml.hbs' ,
8836+ buffer : Buffer . from ( 'exact match asset' ) ,
8837+ } ;
8838+ const asset = _getAssetForTemplatePath ( pkgInfo , assetsMap , datasetPath , templatePath ) ;
8839+ expect ( asset ) . toEqual ( expectedAsset ) ;
8840+ } ) ;
8841+ it ( 'should return fallback asset it exact match is not found' , ( ) => {
8842+ // representing the scenario where the templatePath has the default value 'stream.yml.hbs'
8843+ // but the actual asset uses a prefixed name like 'filestream.yml.hbs'
8844+ const pkgInfo : PackageInfo = {
8845+ name : 'test_package' ,
8846+ version : '1.0.0' ,
8847+ type : 'integration' ,
8848+ } as any ;
8849+ const datasetPath = 'test_data_stream' ;
8850+ const templatePath = 'stream.yml.hbs' ;
8851+ const assetsMap : AssetsMap = new Map ( ) ;
8852+ assetsMap . set (
8853+ `test_package-1.0.0/data_stream/${ datasetPath } /agent/stream/filestream.yml.hbs` ,
8854+ Buffer . from ( 'ends with match asset' )
8855+ ) ;
8856+
8857+ const expectedFallbackAsset : ArchiveEntry = {
8858+ path : 'test_package-1.0.0/data_stream/test_data_stream/agent/stream/filestream.yml.hbs' ,
8859+ buffer : Buffer . from ( 'ends with match asset' ) ,
8860+ } ;
8861+ const asset = _getAssetForTemplatePath ( pkgInfo , assetsMap , datasetPath , templatePath ) ;
8862+ expect ( asset ) . toEqual ( expectedFallbackAsset ) ;
8863+ } ) ;
8864+ } ) ;
0 commit comments