Skip to content

Commit

Permalink
[Ingest Manager] Fix datasource validation for streams without vars (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Jun 3, 2020
1 parent e7cd996 commit f8957c4
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ describe('Ingest Manager - validateDatasource()', () => {
{ dataset: 'disabled2', input: 'disabled2', title: 'Disabled 2', enabled: false },
],
},
{
type: 'with-no-stream-vars',
enabled: true,
vars: [{ required: true, name: 'var-name', type: 'text' }],
streams: [
{
id: 'with-no-stream-vars-bar',
dataset: 'bar',
enabled: true,
},
],
},
],
},
],
Expand Down Expand Up @@ -172,12 +184,26 @@ describe('Ingest Manager - validateDatasource()', () => {
vars: { 'var-name': { value: undefined, type: 'text' } },
},
{
id: 'with-disabled-streams-disabled2',
id: 'with-disabled-streams-disabled-without-vars',
dataset: 'disabled2',
enabled: false,
},
],
},
{
type: 'with-no-stream-vars',
enabled: true,
vars: {
'var-name': { value: 'test', type: 'text' },
},
streams: [
{
id: 'with-no-stream-vars-bar',
dataset: 'bar',
enabled: true,
},
],
},
],
};

Expand Down Expand Up @@ -245,12 +271,26 @@ describe('Ingest Manager - validateDatasource()', () => {
},
},
{
id: 'with-disabled-streams-disabled2',
id: 'with-disabled-streams-disabled-without-vars',
dataset: 'disabled2',
enabled: false,
},
],
},
{
type: 'with-no-stream-vars',
enabled: true,
vars: {
'var-name': { value: undefined, type: 'text' },
},
streams: [
{
id: 'with-no-stream-vars-bar',
dataset: 'bar',
enabled: true,
},
],
},
],
};

Expand All @@ -274,7 +314,18 @@ describe('Ingest Manager - validateDatasource()', () => {
},
},
'with-disabled-streams': {
streams: { 'with-disabled-streams-disabled': { vars: { 'var-name': null } } },
streams: {
'with-disabled-streams-disabled': {
vars: { 'var-name': null },
},
'with-disabled-streams-disabled-without-vars': {},
},
},
'with-no-stream-vars': {
streams: {
'with-no-stream-vars-bar': {},
},
vars: { 'var-name': null },
},
},
};
Expand Down Expand Up @@ -307,7 +358,16 @@ describe('Ingest Manager - validateDatasource()', () => {
},
},
'with-disabled-streams': {
streams: { 'with-disabled-streams-disabled': { vars: { 'var-name': null } } },
streams: {
'with-disabled-streams-disabled': { vars: { 'var-name': null } },
'with-disabled-streams-disabled-without-vars': {},
},
},
'with-no-stream-vars': {
vars: {
'var-name': ['var-name is required'],
},
streams: { 'with-no-stream-vars-bar': {} },
},
},
});
Expand Down Expand Up @@ -354,7 +414,18 @@ describe('Ingest Manager - validateDatasource()', () => {
},
},
'with-disabled-streams': {
streams: { 'with-disabled-streams-disabled': { vars: { 'var-name': null } } },
streams: {
'with-disabled-streams-disabled': {
vars: { 'var-name': null },
},
'with-disabled-streams-disabled-without-vars': {},
},
},
'with-no-stream-vars': {
vars: {
'var-name': ['var-name is required'],
},
streams: { 'with-no-stream-vars-bar': {} },
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,36 +110,31 @@ export const validateDatasource = (
// Validate each input stream with config fields
if (input.streams.length) {
input.streams.forEach((stream) => {
if (!stream.vars) {
return;
}

const streamValidationResults: DatasourceConfigValidationResults = {
vars: undefined,
};

const streamVarsByName = (
(
registryInputsByType[input.type].streams.find(
(registryStream) => registryStream.dataset === stream.dataset
) || {}
).vars || []
).reduce((vars, registryVar) => {
vars[registryVar.name] = registryVar;
return vars;
}, {} as Record<string, RegistryVarsEntry>);
const streamValidationResults: DatasourceConfigValidationResults = {};

// Validate stream-level config fields
streamValidationResults.vars = Object.entries(stream.vars).reduce(
(results, [name, configEntry]) => {
results[name] =
input.enabled && stream.enabled
? validateDatasourceConfig(configEntry, streamVarsByName[name])
: null;
return results;
},
{} as ValidationEntry
);
if (stream.vars) {
const streamVarsByName = (
(
registryInputsByType[input.type].streams.find(
(registryStream) => registryStream.dataset === stream.dataset
) || {}
).vars || []
).reduce((vars, registryVar) => {
vars[registryVar.name] = registryVar;
return vars;
}, {} as Record<string, RegistryVarsEntry>);
streamValidationResults.vars = Object.entries(stream.vars).reduce(
(results, [name, configEntry]) => {
results[name] =
input.enabled && stream.enabled
? validateDatasourceConfig(configEntry, streamVarsByName[name])
: null;
return results;
},
{} as ValidationEntry
);
}

inputValidationResults.streams![stream.id] = streamValidationResults;
});
Expand Down Expand Up @@ -228,5 +223,6 @@ export const validationHasErrors = (
| DatasourceConfigValidationResults
) => {
const flattenedValidation = getFlattenedObject(validationResults);

return !!Object.entries(flattenedValidation).find(([, value]) => !!value);
};

0 comments on commit f8957c4

Please sign in to comment.