Skip to content

Commit

Permalink
Merge pull request #74 from Green-Software-Foundation/main
Browse files Browse the repository at this point in the history
Release v0.3.1
  • Loading branch information
narekhovhannisyan authored Apr 9, 2024
2 parents 92df22b + f89b1c6 commit b31b9d2
Show file tree
Hide file tree
Showing 41 changed files with 951 additions and 197 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
> [!IMPORTANT]
> If you are participating in Carbon Hack 24, please **don't submit your plugin to the if-plugins repository**. This is the standard library of plugins for Impact Framework which are being maintained by the IF team. Please commit your plugin to your **own repository** and submit a link to your repo in your final submission for the hackaton. More info about building and publishing plugins [here](https://if.greensoftware.foundation/developers/how-to-build-plugins#step-5-publishing-your-plugin).

# Impact Framework - Plugins

`if-plugins` are set of plugins maintained as a part of Impact Framework.
Expand Down
44 changes: 31 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@grnsft/if-plugins",
"description": "Impact Framework Standard Plugins",
"version": "v0.3.0",
"version": "v0.3.1",
"author": {
"name": "Green Software Foundation",
"email": "[email protected]"
Expand All @@ -16,7 +16,6 @@
"axios": "^1.6.0",
"copyfiles": "^2.4.1",
"csv-parse": "^5.5.5",
"dayjs": "^1.11.10",
"dotenv": "^16.3.1",
"js-yaml": "^4.1.0",
"typescript": "^5.1.6",
Expand All @@ -30,12 +29,14 @@
"@jest/globals": "^29.6.1",
"@types/jest": "^29.5.7",
"@types/js-yaml": "^4.0.8",
"@types/luxon": "^3.4.2",
"@types/node": "^20.4.5",
"fixpack": "4.0.0",
"gts": "^5.0.0",
"husky": "^8.0.0",
"jest": "^29.6.1",
"jest-mock-axios": "^4.7.2",
"luxon": "^3.4.4",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.1"
},
Expand Down
128 changes: 128 additions & 0 deletions src/__tests__/unit/lib/cloud-metadata/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,134 @@ describe('lib/cloud-metadata:', () => {
]);
});

it('returns a result when azure instance type do not have size number.', async () => {
const inputs = [
{
timestamp: '',
duration: 5,
'cloud/instance-type': 'Standard_B1ms',
'cloud/vendor': 'azure',
},
];

const result = await cloudMetadata.execute(inputs);

expect.assertions(1);

expect(result).toStrictEqual([
{
timestamp: '',
duration: 5,
'cloud/instance-type': 'Standard_B1ms',
'cloud/vendor': 'azure',
'cpu/thermal-design-power': 270,
'physical-processor':
'Intel® Xeon® Platinum 8370C,Intel® Xeon® Platinum 8272CL,Intel® Xeon® 8171M 2.1 GHz,Intel® Xeon® E5-2673 v4 2.3 GHz,Intel® Xeon® E5-2673 v3 2.4 GHz',
'vcpus-allocated': 1,
'vcpus-total': 64,
'memory-available': 2,
},
]);
});

it('returns a result with configured outputs.', async () => {
const inputs = [
{
timestamp: '',
duration: 5,
'cloud/instance-type': 'Standard_A1_v2',
'cloud/vendor': 'azure',
'cloud/region': 'francesouth',
},
];
const config = {
fields: [
'cloud/vendor',
'cloud/region-wt-id',
'cloud/instance-type',
'physical-processor',
'cpu/thermal-design-power',
],
};
const result = await cloudMetadata.execute(inputs, config);

expect.assertions(1);

expect(result).toStrictEqual([
{
timestamp: '',
duration: 5,
'cloud/instance-type': 'Standard_A1_v2',
'cloud/region': 'francesouth',
'cloud/region-wt-id': 'FR',
'cloud/vendor': 'azure',
'cpu/thermal-design-power': 205,
'physical-processor':
'Intel® Xeon® Platinum 8272CL,Intel® Xeon® 8171M 2.1 GHz,Intel® Xeon® E5-2673 v4 2.3 GHz,Intel® Xeon® E5-2673 v3 2.4 GHz',
},
]);
});

it('returns a result when provided a `cloud/region` in the input.', async () => {
const inputs = [
{
timestamp: '',
duration: 5,
'cloud/instance-type': 'Standard_A1_v2',
'cloud/vendor': 'azure',
'cloud/region': 'francesouth',
},
];

const result = await cloudMetadata.execute(inputs);

expect.assertions(1);

expect(result).toStrictEqual([
{
timestamp: '',
duration: 5,
'cloud/instance-type': 'Standard_A1_v2',
'cloud/region': 'francesouth',
'cloud/region-cfe': 'France',
'cloud/region-em-zone-id': 'FR',
'cloud/region-geolocation': '48.8567,2.3522',
'cloud/region-location': 'Paris',
'cloud/region-wt-id': 'FR',
'cloud/vendor': 'azure',
'cpu/thermal-design-power': 205,
'memory-available': 2,
'physical-processor':
'Intel® Xeon® Platinum 8272CL,Intel® Xeon® 8171M 2.1 GHz,Intel® Xeon® E5-2673 v4 2.3 GHz,Intel® Xeon® E5-2673 v3 2.4 GHz',
'vcpus-allocated': 1,
'vcpus-total': 52,
},
]);
});

it('throws an error when provided a wrong `cloud/region` for vendor in the input.', async () => {
const errorMessage =
"CloudMetadata: 'uk-west' region is not supported in 'azure' cloud vendor.";
const inputs = [
{
timestamp: '',
duration: 5,
'cloud/instance-type': 'Standard_A1_v2',
'cloud/vendor': 'azure',
'cloud/region': 'uk-west',
},
];

expect.assertions(2);

try {
await cloudMetadata.execute(inputs);
} catch (error) {
expect(error).toStrictEqual(new UnsupportedValueError(errorMessage));
expect(error).toBeInstanceOf(UnsupportedValueError);
}
});

it('throws on `cloud/instance-type` when `cloud/vendor` is aws.', async () => {
const errorMessage =
"CloudMetadata(cloud/instance-type): 't2.micro2' instance type is not supported in 'aws' cloud vendor.";
Expand Down
32 changes: 31 additions & 1 deletion src/__tests__/unit/lib/csv-export/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {CsvExport} from '../../../../lib/csv-export';

import {ERRORS} from '../../../../util/errors';

const {MakeDirectoryError, WriteFileError} = ERRORS;
const {MakeDirectoryError, WriteFileError, InputValidationError} = ERRORS;

jest.mock('fs/promises', () => ({
mkdir: jest.fn<() => Promise<void>>().mockResolvedValue(),
Expand Down Expand Up @@ -126,6 +126,36 @@ describe('lib/csv-export: ', () => {
expect(result).toStrictEqual(input);
});

it('throws an error when node config is not provided.', async () => {
const csvExport = CsvExport();

const input = [
{
timestamp: '2023-12-12T00:00:00.000Z',
duration: 10,
energy: 10,
carbon: 2,
},
{
timestamp: '2023-12-12T00:00:10.000Z',
duration: 30,
energy: 20,
carbon: 5,
},
];

expect.assertions(2);

try {
await csvExport.execute(input);
} catch (error) {
expect(error).toBeInstanceOf(InputValidationError);
expect(error).toEqual(
new InputValidationError('CsvExport: Configuration data is missing.')
);
}
});

it('throws an error when a file writing fails.', async () => {
(fs.writeFile as jest.Mock).mockImplementation(() => {
throw new Error('Permission denied');
Expand Down
Loading

0 comments on commit b31b9d2

Please sign in to comment.