Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
busma13 committed Apr 10, 2024
1 parent 8648e9a commit 9abf7ca
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
9 changes: 3 additions & 6 deletions packages/terafoundation/src/validate-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function extractInitializers<S>(
return fn(sysconfig);
}
if (isPlainObject(fn)) {
return fn;
return { schema: fn };
}

return { schema: {} };
Expand Down Expand Up @@ -81,18 +81,16 @@ export default function validateConfigs<
const {
schema: sysconfigSchema,
validatorFn: sysconfigValidatorFn
} = extractInitializers(config.config_schema, sysconfig); // FixMe test this
console.log('@@@@ sysconfigSchema: ', sysconfigSchema);
} = extractInitializers(config.config_schema, sysconfig);

listOfValidations.push({ schema: sysconfigSchema, validatorFn: sysconfigValidatorFn });

const {
schema: foundationSchema,
validatorFn: foundationValidatorFn
} = getFoundationInitializers(); // FixMe test this
} = getFoundationInitializers();
listOfValidations.push({ schema: foundationSchema, validatorFn: foundationValidatorFn });
sysconfigSchema.terafoundation = foundationSchema;
console.log('@@@@ sysconfigSchema: ', sysconfigSchema);

const result: any = {};

Expand Down Expand Up @@ -147,7 +145,6 @@ export default function validateConfigs<
result._nodeName = hostname;
}

console.log('@@@@ listofValidations: ', listOfValidations);
const resultCopy = cloneDeep(result);
for (const {
schema, validatorFn, connector, connection
Expand Down
3 changes: 3 additions & 0 deletions packages/terafoundation/test/process-context-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ describe('Terafoundation (ProcessContext)', () => {
configfile: {
terafoundation: {
environment: process.env.NODE_ENV,
connectors: {
'elasticsearch-next': {}
}
}
}
} as any);
Expand Down
46 changes: 33 additions & 13 deletions packages/terafoundation/test/validate-configs-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'jest-extended';
import os from 'os';
import { Cluster } from '../src';
import validateConfigs from '../src/validate-configs';
import { getFoundationInitializers } from '../src/schema';
import { getConnectorInitializers } from '../src/connector-utils';

describe('Validate Configs', () => {
describe('when using mainly defaults', () => {
Expand All @@ -15,7 +17,9 @@ describe('Validate Configs', () => {

const configFile = {
terafoundation: {

connectors: {
'elasticsearch-next': {}
}
},
other: {
test: 'custom'
Expand Down Expand Up @@ -179,7 +183,7 @@ describe('Validate Configs', () => {
};
const config = {
config_schema() {
return {};
return { schema: {} };
}
};

Expand All @@ -200,7 +204,7 @@ describe('Validate Configs', () => {
};
const config = {
config_schema() {
return {};
return { schema: {} };
}
};

Expand All @@ -221,7 +225,7 @@ describe('Validate Configs', () => {
};
const config = {
config_schema() {
return {};
return { schema: {} };
}
};

Expand All @@ -242,7 +246,7 @@ describe('Validate Configs', () => {
};
const config = {
config_schema() {
return {};
return { schema: {} };
}
};

Expand All @@ -261,7 +265,10 @@ describe('Validate Configs', () => {
default: {}
},
s3: {
minio1: {},
minio1: {
accessKeyId: 'test',
secretAccessKey: 'test'
},
}
}
},
Expand All @@ -272,13 +279,13 @@ describe('Validate Configs', () => {
};
const config = {
config_schema() {
return {};
return { schema: {} };
}
};

it('should throw an error', () => {
expect(() => validateConfigs(cluster as any, config as any, configFile as any))
.toThrow('Error validating configuration, caused by Error: asset_storage_connection: minio2 not found in terafoundation.connectors.s3: value was "minio2"');
.toThrow('minio2 not found in terafoundation.connectors.s3');
});
});

Expand All @@ -294,7 +301,7 @@ describe('Validate Configs', () => {
};
const config = {
config_schema() {
return {};
return { schema: {} };
}
};

Expand All @@ -320,7 +327,7 @@ describe('Validate Configs', () => {
};
const config = {
config_schema() {
return {};
return { schema: {} };
}
};

Expand Down Expand Up @@ -349,13 +356,13 @@ describe('Validate Configs', () => {
};
const config = {
config_schema() {
return {};
return { schema: {} };
}
};

it('should throw an error', () => {
expect(() => validateConfigs(cluster as any, config as any, configFile as any))
.toThrow('Error validating configuration, caused by Error: asset_storage_connection_type: Invalid asset_storage_connection_type. Valid types: elasticsearch-next,s3: value was "kafka"');
.toThrow('Invalid asset_storage_connection_type. Valid types: elasticsearch-next,s3');
});
});

Expand All @@ -375,7 +382,7 @@ describe('Validate Configs', () => {
};
const config = {
config_schema() {
return {};
return { schema: {} };
}
};

Expand Down Expand Up @@ -405,3 +412,16 @@ describe('Validate Configs', () => {
});
});
});

describe('getFoundationInitializers', () => {
it('should return an initializer with schema and validatorFn keys', () => {
expect(getFoundationInitializers()).toContainKey('schema');
});
});

describe('getConnectorInitializers', () => {
it('should return an initializer with schema and validatorFn keys', () => {
const connector = 'elasticsearch-next';
expect(getConnectorInitializers(connector)).toContainKey('schema');
});
});

0 comments on commit 9abf7ca

Please sign in to comment.