Skip to content

Commit

Permalink
fix eks sshkey dropdown and add unit test (#12880)
Browse files Browse the repository at this point in the history
  • Loading branch information
mantis-toboggan-md authored Dec 12, 2024
1 parent 5218335 commit d5b785b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
5 changes: 2 additions & 3 deletions pkg/eks/components/CruEKS.vue
Original file line number Diff line number Diff line change
Expand Up @@ -557,15 +557,14 @@ export default defineComponent({
const keyPairRes: {KeyPairs: {KeyName: string}[]} = await ec2Client.describeKeyPairs({ DryRun: false });
this['sshKeyPairs'] = (keyPairRes.KeyPairs || [].map((key) => {
this.sshKeyPairs = (keyPairRes.KeyPairs || []).map((key) => {
return key.KeyName;
}).sort());
}).sort();
} catch (err: any) {
const errors = this.errors as any[];
errors.push(err);
}
this.loadingSshKeyPairs = false;
},
}
Expand Down
31 changes: 31 additions & 0 deletions pkg/eks/components/__mocks__/describeKeyPairs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default {
KeyPairs: [
{
CreateTime: 'Date Mon Jul 24 2023 14:53:22 GMT-0700 (Pacific Daylight Time)',

KeyFingerprint: 'a1:b2:c3:12345678987654321',

KeyName: 'test-key1',

KeyPairId: 'key-123456789',

KeyType: 'rsa',

Tags: []
},

{
CreateTime: 'Date Mon Jul 24 2023 14:53:22 GMT-0700 (Pacific Daylight Time)',

KeyFingerprint: 'a1:b2:c3:12345678987654321',

KeyName: 'test-key2',

KeyPairId: 'key-123456789',

KeyType: 'rsa',

Tags: []
}
]
};
33 changes: 31 additions & 2 deletions pkg/eks/components/__tests__/CruEKS.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable jest/no-mocks-import */
import flushPromises from 'flush-promises';
import { mount, shallowMount, Wrapper } from '@vue/test-utils';
import { EKSConfig, EKSNodeGroup } from 'types';
import CruEKS, { DEFAULT_EKS_CONFIG } from '@pkg/eks/components/CruEKS.vue';
import describeKeyPairs from '../__mocks__/describeKeyPairs';
import describeLaunchTemplates from '../__mocks__/describeLaunchTemplates';

const mockedStore = (versionSetting: any) => {
return {
Expand All @@ -19,7 +22,19 @@ const mockedStore = (versionSetting: any) => {
return {};
}
},
dispatch: jest.fn()
dispatch: () => {
return {
describeKeyPairs: () => {
return describeKeyPairs;
},
describeLaunchTemplates: () => {
return describeLaunchTemplates;
},
listRoles: () => {
return { Roles: [] };
}
};
}
};
};

Expand All @@ -39,8 +54,9 @@ const requiredSetup = (versionSetting = { value: '<=1.27.x' }) => {
};

const setCredential = async(wrapper :Wrapper<any>, config = {} as EKSConfig) => {
config.amazonCredentialSecret = 'foo';
wrapper.setData({ config });
wrapper.vm.updateCredential('foo');
wrapper.vm.updateRegion('bar');
await flushPromises();
};

Expand Down Expand Up @@ -216,4 +232,17 @@ describe('eKS provisioning form', () => {

expect(wrapper.vm.fvUnreportedValidationErrors).toStrictEqual([]);
});

it('should fetch ssh keys from the aws api and save response as list of keypair KeyNames', async() => {
const setup = requiredSetup();

const wrapper = shallowMount(CruEKS, {
propsData: { value: {}, mode: 'create' },
...setup
});

await setCredential(wrapper);

expect(wrapper.vm.sshKeyPairs).toStrictEqual(['test-key1', 'test-key2']);
});
});

0 comments on commit d5b785b

Please sign in to comment.