Skip to content

Commit

Permalink
ip acl e2e tests for updating an lke cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
coliu-akamai committed Oct 21, 2024
1 parent b0d9a8a commit f22cabf
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 3 deletions.
Empty file.
101 changes: 101 additions & 0 deletions packages/manager/cypress/support/intercepts/lke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
kubernetesDashboardUrlFactory,
} from '@src/factories';
import { kubernetesVersions } from 'support/constants/lke';
import { makeErrorResponse } from 'support/util/errors';
import { apiMatcher } from 'support/util/intercepts';
import { paginateResponse } from 'support/util/paginate';
import { randomDomainName } from 'support/util/random';
Expand All @@ -16,6 +17,7 @@ import type {
KubeConfigResponse,
KubeNodePoolResponse,
KubernetesCluster,
KubernetesControlPlaneACLPayload,
KubernetesVersion,
} from '@linode/api-v4';

Expand Down Expand Up @@ -157,6 +159,25 @@ export const mockCreateCluster = (
);
};

/**
* Intercepts POST request to create an LKE cluster and mocks an error response.
*
* @param errorMessage - Optional error message with which to mock response.
* @param statusCode - HTTP status code with which to mock response.
*
* @returns Cypress chainable.
*/
export const mockCreateClusterError = (
errorMessage: string = 'An unknown error occurred.',
statusCode: number = 500
): Cypress.Chainable<null> => {
return cy.intercept(
'POST',
apiMatcher('lke/clusters'),
makeErrorResponse(errorMessage, statusCode)
);
};

/**
* Intercepts DELETE request to delete an LKE cluster and mocks the response.
*
Expand Down Expand Up @@ -354,3 +375,83 @@ export const mockResetKubeconfig = (
makeResponse({})
);
};

/**
* Intercepts GET request for a cluster's Control Plane ACL and mocks the response
*
* @param clusterId - Numberic ID of LKE cluster for which to mock response.
* @param controlPlaneACL - control plane ACL data for which to mock response
*
* @returns Cypress chainable
*/
export const mockGetControlPlaneACL = (
clusterId: number,
controlPlaneACL: KubernetesControlPlaneACLPayload
): Cypress.Chainable<null> => {
return cy.intercept(
'GET',
apiMatcher(`/lke/clusters/${clusterId}/control_plane_acl`),
makeResponse(controlPlaneACL)
);
};

/**
* Intercepts GET request for a cluster's Control Plane ACL and mocks an error response
*
* @param clusterId - Numberic ID of LKE cluster for which to mock response.
* @param errorMessage - Optional error message with which to mock response.
* @param statusCode - HTTP status code with which to mock response.
*
* @returns Cypress chainable
*/
export const mockGetControlPlaneACLError = (
clusterId: number,
errorMessage: string = 'An unknown error occurred.',
statusCode: number = 500
): Cypress.Chainable<null> => {
return cy.intercept(
'GET',
apiMatcher(`/lke/clusters/${clusterId}/control_plane_acl`),
makeErrorResponse(errorMessage, statusCode)
);
};

/**
* Intercepts PUT request for a cluster's Control Plane ACL and mocks the response
*
* @param clusterId - Numberic ID of LKE cluster for which to mock response.
* @param controlPlaneACL - control plane ACL data for which to mock response
*
* @returns Cypress chainable
*/
export const mockUpdateControlPlaneACL = (
clusterId: number,
controlPlaneACL: KubernetesControlPlaneACLPayload
): Cypress.Chainable<null> => {
return cy.intercept(
'PUT',
apiMatcher(`/lke/clusters/${clusterId}/control_plane_acl`),
makeResponse(controlPlaneACL)
);
};

/**
* Intercepts PUT request for a cluster's Control Plane ACL and mocks the response
*
* @param clusterId - Numberic ID of LKE cluster for which to mock response.
* @param errorMessage - Optional error message with which to mock response.
* @param statusCode - HTTP status code with which to mock response.
*
* @returns Cypress chainable.
*/
export const mockUpdateControlPlaneACLError = (
clusterId: number,
errorMessage: string = 'An unknown error occurred.',
statusCode: number = 500
): Cypress.Chainable<null> => {
return cy.intercept(
'PUT',
apiMatcher(`/lke/clusters/${clusterId}/control_plane_acl`),
makeErrorResponse(errorMessage, statusCode)
);
};
28 changes: 25 additions & 3 deletions packages/manager/src/factories/kubernetesCluster.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {
import { v4 } from 'uuid';

import Factory from 'src/factories/factoryProxy';

import type {
ControlPlaneACLOptions,
KubeNodePoolResponse,
KubernetesCluster,
KubernetesControlPlaneACLPayload,
KubernetesDashboardResponse,
KubernetesEndpointResponse,
KubernetesVersion,
PoolNodeResponse,
} from '@linode/api-v4/lib/kubernetes/types';
import Factory from 'src/factories/factoryProxy';
import { v4 } from 'uuid';

export const kubeLinodeFactory = Factory.Sync.makeFactory<PoolNodeResponse>({
id: Factory.each((id) => `id-${id}`),
Expand Down Expand Up @@ -73,3 +77,21 @@ export const kubernetesVersionFactory = Factory.Sync.makeFactory<KubernetesVersi
id: '1.24',
}
);

export const kubernetesControlPlaneACLOptionsFactory = Factory.Sync.makeFactory<ControlPlaneACLOptions>(
{
addresses: {
ipv4: ['10.0.0.0/24', '10.0.1.0/24'],
ipv6: ['8e61:f9e9:8d40:6e0a:cbff:c97a:2692:827e'],
},
enabled: true,
'revision-id': '67497a9c5fc8491889a7ef8107493e92',
}
);
export const kubernetesControlPlaneACLFactory = Factory.Sync.makeFactory<KubernetesControlPlaneACLPayload>(
{
acl: {
...kubernetesControlPlaneACLOptionsFactory.build(),
},
}
);

0 comments on commit f22cabf

Please sign in to comment.