Merge pull request #13690 from taras/tm/placeholder-object-values
[Catalog] Allow placeholder value to be any type
This commit is contained in:
@@ -387,6 +387,39 @@ describe('PlaceholderProcessor', () => {
|
||||
key: 'url:http://example.com/path-to-file.json',
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts arbitrary object as value', async () => {
|
||||
const processor = new PlaceholderProcessor({
|
||||
resolvers: {
|
||||
merge: async ({ value }) => {
|
||||
if (value instanceof Object) {
|
||||
return { merged: 'value', ...value };
|
||||
}
|
||||
return value;
|
||||
},
|
||||
},
|
||||
reader,
|
||||
integrations,
|
||||
});
|
||||
|
||||
const result = await processor.preProcessEntity(
|
||||
{
|
||||
apiVersion: 'a',
|
||||
kind: 'k',
|
||||
metadata: { name: 'n' },
|
||||
spec: { a: { $merge: { passed: 'value' } } },
|
||||
},
|
||||
{ type: 'fake', target: 'http://example.com' },
|
||||
() => {},
|
||||
);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
apiVersion: 'a',
|
||||
kind: 'k',
|
||||
metadata: { name: 'n' },
|
||||
spec: { a: { passed: 'value', merged: 'value' } },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('yamlPlaceholderResolver', () => {
|
||||
|
||||
@@ -111,12 +111,11 @@ export class PlaceholderProcessor implements CatalogProcessor {
|
||||
const resolverValue = data[keys[0]];
|
||||
|
||||
const resolver = this.options.resolvers[resolverKey];
|
||||
if (!resolver || typeof resolverValue !== 'string') {
|
||||
// If there was no such placeholder resolver or if the value was not a
|
||||
// string, we err on the side of safety and assume that this is
|
||||
// something that's best left alone. For example, if the input contains
|
||||
// JSONSchema, there may be "$ref": "#/definitions/node" nodes in the
|
||||
// document.
|
||||
if (!resolver) {
|
||||
// If there was no such placeholder resolver, we err on the side of safety
|
||||
// and assume that this is something that's best left alone. For example, if
|
||||
// the input contains JSONSchema, there may be "$ref": "#/definitions/node"
|
||||
// nodes in the document.
|
||||
return [data, false];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user