Skip to content

Commit

Permalink
feat(datasource): add aws-eks datasource lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: ivan katliarchuk <[email protected]>
  • Loading branch information
ivankatliarchuk committed Dec 27, 2024
1 parent 53f21e2 commit 558515f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
43 changes: 27 additions & 16 deletions lib/modules/datasource/aws-eks/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ describe('modules/datasource/aws-eks/index', () => {
it('should return releases when the response is valid', async () => {
const mockResponse: DescribeClusterVersionsCommandOutput = {
$metadata: {},
clusterVersions : [
clusterVersions: [
{
clusterVersion: '1.21',
releaseDate: new Date(new Date().setMonth(new Date().getMonth() - 24)),
endOfStandardSupportDate: new Date(new Date().setMonth(new Date().getMonth() + 10)),
releaseDate: new Date(
new Date().setMonth(new Date().getMonth() - 24),
),
endOfStandardSupportDate: new Date(
new Date().setMonth(new Date().getMonth() + 10),
),
},
],
};
Expand All @@ -33,7 +37,7 @@ describe('modules/datasource/aws-eks/index', () => {

const result = await getPkgReleases({ datasource, packageName: '{}' });

expect(result?.releases).toHaveLength(1)
expect(result?.releases).toHaveLength(1);
expect(result).toEqual({
releases: [
{
Expand All @@ -48,7 +52,10 @@ describe('modules/datasource/aws-eks/index', () => {

it('should return null and log an error when the filter is invalid', async () => {
const invalidFilter = '{ invalid json }';
const actual = await getPkgReleases({ datasource, packageName: invalidFilter });
const actual = await getPkgReleases({
datasource,
packageName: invalidFilter,
});
expect(actual).toBeNull();
expect(logger.logger.error).toHaveBeenCalledTimes(1);
});
Expand All @@ -66,12 +73,13 @@ describe('modules/datasource/aws-eks/index', () => {
};
eksMock.on(DescribeClusterVersionsCommand).resolves(mockResponse);

const actual = await getPkgReleases(
{ datasource, packageName: '{"default":"true", "region":"eu-west-1"}' }
);
const actual = await getPkgReleases({
datasource,
packageName: '{"default":"true", "region":"eu-west-1"}',
});

expect(eksMock.calls()).toHaveLength(1);
expect(eksMock.call(0).args[0].input).toEqual({"defaultOnly": true});
expect(eksMock.call(0).args[0].input).toEqual({ defaultOnly: true });

expect(actual).toEqual({
releases: [
Expand Down Expand Up @@ -102,12 +110,14 @@ describe('modules/datasource/aws-eks/index', () => {
};
eksMock.on(DescribeClusterVersionsCommand).resolves(mockResponse);

const actual = await getPkgReleases(
{ datasource, packageName: '{"default":"false", "region":"eu-west-1", "profile":"admin"}' }
);
const actual = await getPkgReleases({
datasource,
packageName:
'{"default":"false", "region":"eu-west-1", "profile":"admin"}',
});

expect(eksMock.calls()).toHaveLength(1);
expect(eksMock.call(0).args[0].input).toEqual({"defaultOnly": false});
expect(eksMock.call(0).args[0].input).toEqual({ defaultOnly: false });

expect(actual).toEqual({
releases: [
Expand All @@ -125,9 +135,10 @@ describe('modules/datasource/aws-eks/index', () => {
};
eksMock.on(DescribeClusterVersionsCommand).resolves(mockResponse);

const actual = await getPkgReleases(
{ datasource, packageName: '{"profile":"not-exist-profile"}' }
);
const actual = await getPkgReleases({
datasource,
packageName: '{"profile":"not-exist-profile"}',
});

expect(eksMock.calls()).toHaveLength(1);
expect(eksMock.call(0).args[0].input).toEqual({});
Expand Down
13 changes: 9 additions & 4 deletions lib/modules/datasource/aws-eks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type DescribeClusterVersionsCommandInput,
type DescribeClusterVersionsCommandOutput,
EKSClient,
} from "@aws-sdk/client-eks";
} from '@aws-sdk/client-eks';

import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
import { logger } from '../../../logger';
Expand Down Expand Up @@ -51,12 +51,17 @@ export class AwsEKSDataSource extends Datasource {
const input: DescribeClusterVersionsCommandInput = {
defaultOnly: res.data.default ?? undefined,
};
const cmd = new DescribeClusterVersionsCommand(input)
const response: DescribeClusterVersionsCommandOutput = await this.getClient(res.data).send(cmd)
const cmd = new DescribeClusterVersionsCommand(input);
const response: DescribeClusterVersionsCommandOutput = await this.getClient(
res.data,
).send(cmd);
const results: ClusterVersionInformation[] = response.clusterVersions ?? [];
return {
releases: results
.filter((el): el is ClusterVersionInformation & { clusterVersion: string } => Boolean(el.clusterVersion))
.filter(
(el): el is ClusterVersionInformation & { clusterVersion: string } =>
Boolean(el.clusterVersion),
)
.map((el) => ({
version: el.clusterVersion,
})),
Expand Down
10 changes: 2 additions & 8 deletions lib/modules/datasource/aws-eks/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,10 @@ renovate: eksFilter={"region":"us-east-1","profile":"renovate-east"}
"packageRules": [
{
"matchDatasources": ["aws-eks"],
"prBodyColumns": [
"Package",
"Update",
"Change",
"Sources",
"Changelog"
],
"prBodyColumns": ["Package", "Update", "Change", "Sources", "Changelog"],
"prBodyDefinitions": {
"Sources": "[▶️](https://github.com/aws/eks-distro/)",
"Changelog": "[▶️](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-{{{newVersion}}}.md)",
"Changelog": "[▶️](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-{{{newVersion}}}.md)"
}
}
],
Expand Down

0 comments on commit 558515f

Please sign in to comment.