Skip to content

Commit

Permalink
test(builtins): update test corespondingly
Browse files Browse the repository at this point in the history
  • Loading branch information
manushak committed Jul 26, 2024
1 parent 954c5c0 commit 6904da5
Show file tree
Hide file tree
Showing 15 changed files with 1,096 additions and 818 deletions.
28 changes: 24 additions & 4 deletions src/__tests__/if-run/builtins/coefficient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ describe('builtins/coefficient: ', () => {
inputs: {},
outputs: {},
};
const coefficient = Coefficient(globalConfig, parametersMetadata);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': parametersMetadata,
mapping: {},
};
const coefficient = Coefficient(pluginSettings);

describe('init: ', () => {
it('successfully initalized.', () => {
Expand Down Expand Up @@ -55,7 +60,12 @@ describe('builtins/coefficient: ', () => {

it('throws an error when global config is not provided.', () => {
const config = undefined;
const coefficient = Coefficient(config!, parametersMetadata);
const pluginSettings = {
'global-config': config!,
'parameter-metadata': parametersMetadata,
mapping: {},
};
const coefficient = Coefficient(pluginSettings);

expect.assertions(1);

Expand All @@ -80,7 +90,12 @@ describe('builtins/coefficient: ', () => {
coefficient: 3,
'output-parameter': 'carbon-product',
};
const coefficient = Coefficient(invalidConfig, parametersMetadata);
const pluginSettings = {
'global-config': invalidConfig,
'parameter-metadata': parametersMetadata,
mapping: {},
};
const coefficient = Coefficient(pluginSettings);
const expectedMessage =
'"input-parameter" parameter is string must contain at least 1 character(s). Error code: too_small.';

Expand All @@ -107,7 +122,12 @@ describe('builtins/coefficient: ', () => {
coefficient: 10,
'output-parameter': '',
};
const coefficient = Coefficient(invalidConfig, parametersMetadata);
const pluginSettings = {
'global-config': invalidConfig,
'parameter-metadata': parametersMetadata,
mapping: {},
};
const coefficient = Coefficient(pluginSettings);
const expectedMessage =
'"output-parameter" parameter is string must contain at least 1 character(s). Error code: too_small.';

Expand Down
28 changes: 24 additions & 4 deletions src/__tests__/if-run/builtins/copy-param.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ describe('builtins/copy: ', () => {
inputs: {},
outputs: {},
};
const copy = Copy(globalConfig, parametersMetadata);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': parametersMetadata,
mapping: {},
};
const copy = Copy(pluginSettings);

describe('init: ', () => {
it('successfully initalized.', () => {
Expand Down Expand Up @@ -53,7 +58,12 @@ describe('builtins/copy: ', () => {

it('throws an error when global config is not provided.', () => {
const config = undefined;
const copy = Copy(config!, parametersMetadata);
const pluginSettings = {
'global-config': config!,
'parameter-metadata': parametersMetadata,
mapping: {},
};
const copy = Copy(pluginSettings);

expect.assertions(1);

Expand All @@ -78,7 +88,12 @@ describe('builtins/copy: ', () => {
from: 'original',
to: 'copy',
};
const copy = Copy(globalConfig, parametersMetadata);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': parametersMetadata,
mapping: {},
};
const copy = Copy(pluginSettings);
expect.assertions(1);

try {
Expand All @@ -103,7 +118,12 @@ describe('builtins/copy: ', () => {
from: 'original',
to: 'copy',
};
const copy = Copy(globalConfig, parametersMetadata);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': parametersMetadata,
mapping: {},
};
const copy = Copy(pluginSettings);

const expectedResult = [
{
Expand Down
101 changes: 85 additions & 16 deletions src/__tests__/if-run/builtins/csv-lookup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: ['cpu-tdp', 'tdp'],
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);
expect(csvLookup).toHaveProperty('metadata');
expect(csvLookup).toHaveProperty('execute');
});
Expand All @@ -54,7 +59,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: ['cpu-tdp', 'tdp'],
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);

const responseData = `cpu-cores-available,cpu-cores-utilized,cpu-manufacturer,cpu-model-name,cpu-tdp,gpu-count,gpu-model-name,Hardware Information on AWS Documentation & Comments,instance-class,instance-storage,memory-available,platform-memory,release-date,storage-drives
16,8,AWS,AWS Graviton,150.00,N/A,N/A,AWS Graviton (ARM),a1.2xlarge,EBS-Only,16,32,November 2018,0
Expand Down Expand Up @@ -93,7 +103,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: ['cpu-tdp', 'tdp'],
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);

const result = await csvLookup.execute([
{
Expand Down Expand Up @@ -126,7 +141,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: ['cpu-tdp', 'tdp'],
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);
const input = [
{
timestamp: '2024-03-01',
Expand Down Expand Up @@ -155,7 +175,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: ['cpu-tdp', 'tdp'],
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);
const input = [
{
timestamp: '2024-03-01',
Expand Down Expand Up @@ -187,7 +212,12 @@ describe('builtins/CSVLookup: ', () => {
};
mock.onGet(globalConfig.filepath).reply(404);

const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);
const input = [
{
timestamp: '2024-03-01',
Expand Down Expand Up @@ -217,7 +247,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: '*',
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);

const result = await csvLookup.execute([
{
Expand Down Expand Up @@ -265,7 +300,12 @@ describe('builtins/CSVLookup: ', () => {
['gpu-model-name', 'gpumodel'],
],
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);

const result = await csvLookup.execute([
{
Expand Down Expand Up @@ -300,7 +340,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: 'gpu-count',
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);

const result = await csvLookup.execute([
{
Expand Down Expand Up @@ -334,8 +379,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: ['cpu-tdp', 'tdp'],
};

const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);
const input = [
{
timestamp: '2024-03-01',
Expand All @@ -360,7 +409,7 @@ describe('builtins/CSVLookup: ', () => {

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const csvLookup = CSVLookup();
const csvLookup = CSVLookup({});
const input = [
{
timestamp: '2024-03-01',
Expand Down Expand Up @@ -392,7 +441,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: 'mock',
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);
const input = [
{
timestamp: '2024-03-01',
Expand Down Expand Up @@ -425,7 +479,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: ['gpu-count'],
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);

const result = await csvLookup.execute([
{
Expand Down Expand Up @@ -459,7 +518,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: [['gpu-count']],
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);

const result = await csvLookup.execute([
{
Expand Down Expand Up @@ -495,7 +559,12 @@ describe('builtins/CSVLookup: ', () => {
},
output: [['gpu-count']],
};
const csvLookup = CSVLookup(globalConfig);
const pluginSettings = {
'global-config': globalConfig,
'parameter-metadata': {},
mapping: {},
};
const csvLookup = CSVLookup(pluginSettings);

try {
await csvLookup.execute([
Expand Down
Loading

0 comments on commit 6904da5

Please sign in to comment.