Skip to content

Commit a69c687

Browse files
authored
upcoming: [UIE-9669] - Implement mocks and factories for Network LoadBalancer (#13104)
* upcoming: [UIE-9669] - implement mocks and factories for Network LoadBalancer * Added changeset: Implement mocks and factories for Network LoadBalancer * PR feedback
1 parent b2a852e commit a69c687

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Upcoming Features
3+
---
4+
5+
Implement mocks and factories for Network LoadBalancer ([#13104](https://github.com/linode/manager/pull/13104))

packages/manager/src/factories/account.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const accountFactory = Factory.Sync.makeFactory<Account>({
4848
'Managed Databases',
4949
'Managed Databases Beta',
5050
'NETINT Quadra T1U',
51+
'Network LoadBalancer',
5152
'NodeBalancers',
5253
'Object Storage Access Key Regions',
5354
'Object Storage Endpoint Types',

packages/manager/src/factories/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export * from './longviewSubscription';
3333
export * from './longviewTopProcesses';
3434
export * from './managed';
3535
export * from './networking';
36+
export * from './networkLoadBalancer';
3637
export * from './notification';
3738
export * from './oauth';
3839
export * from './objectStorage';
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Factory } from '@linode/utilities';
2+
3+
import type {
4+
NetworkLoadBalancer,
5+
NetworkLoadBalancerListener,
6+
NetworkLoadBalancerNode,
7+
} from '@linode/api-v4';
8+
9+
export const networkLoadBalancerFactory =
10+
Factory.Sync.makeFactory<NetworkLoadBalancer>({
11+
id: Factory.each((id) => id),
12+
label: Factory.each((id) => `nlb-${id}`),
13+
region: 'us-east',
14+
address_v4: '192.168.1.1',
15+
address_v6: '2001:db8:85a3::8a2e:370:7334',
16+
created: '2023-01-01T00:00:00Z',
17+
updated: '2023-01-02T00:00:00Z',
18+
status: 'active',
19+
last_composite_updated: '',
20+
listeners: [],
21+
});
22+
23+
export const networkLoadBalancerListenerFactory =
24+
Factory.Sync.makeFactory<NetworkLoadBalancerListener>({
25+
created: '2023-01-01T00:00:00Z',
26+
id: Factory.each((id) => id),
27+
label: Factory.each((id) => `nlb-listener-${id}`),
28+
updated: '2023-01-01T00:00:00Z',
29+
port: 80,
30+
protocol: 'tcp',
31+
});
32+
33+
export const networkLoadBalancerNodeFactory =
34+
Factory.Sync.makeFactory<NetworkLoadBalancerNode>({
35+
address_v6: '2001:db8:85a3::8a2e:370:7334',
36+
created: '2023-01-01T00:00:00Z',
37+
id: Factory.each((id) => id),
38+
label: Factory.each((id) => `nlb-node-${id}`),
39+
updated: '2023-01-01T00:00:00Z',
40+
linode_id: Factory.each((id) => id),
41+
weight: 0,
42+
weight_updated: '',
43+
});

packages/manager/src/mocks/serverHandlers.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ import {
9090
managedStatsFactory,
9191
monitorFactory,
9292
mysqlConfigResponse,
93+
networkLoadBalancerFactory,
94+
networkLoadBalancerListenerFactory,
95+
networkLoadBalancerNodeFactory,
9396
nodeBalancerTypeFactory,
9497
nodePoolFactory,
9598
notificationChannelFactory,
@@ -536,6 +539,64 @@ const entities = [
536539
}),
537540
];
538541

542+
const netLoadBalancers = [
543+
http.get('*/v4beta/netloadbalancers', () => {
544+
const nlbWithListener1 = networkLoadBalancerFactory.buildList(5, {
545+
listeners: networkLoadBalancerListenerFactory.buildList(
546+
Math.floor(Math.random() * 10) + 1
547+
),
548+
});
549+
const nlbWithListener2 = networkLoadBalancerFactory.buildList(5, {
550+
region: 'eu-west',
551+
lke_cluster: {
552+
id: 1,
553+
label: 'lke-e-123',
554+
type: 'lkecluster',
555+
url: 'v4/lke/clusters/1',
556+
},
557+
listeners: networkLoadBalancerListenerFactory.buildList(
558+
Math.floor(Math.random() * 20) + 1
559+
),
560+
});
561+
const nlbWithoutListener = networkLoadBalancerFactory.buildList(20);
562+
return HttpResponse.json(
563+
makeResourcePage([
564+
...nlbWithListener1,
565+
...nlbWithListener2,
566+
...nlbWithoutListener,
567+
])
568+
);
569+
}),
570+
http.get('*/v4beta/netloadbalancers/:id', () => {
571+
return HttpResponse.json(
572+
networkLoadBalancerFactory.build({
573+
lke_cluster: {
574+
id: 1,
575+
label: 'lke-e-123',
576+
type: 'lkecluster',
577+
url: 'v4/lke/clusters/1',
578+
},
579+
listeners: networkLoadBalancerListenerFactory.buildList(
580+
Math.floor(Math.random() * 10) + 1
581+
),
582+
})
583+
);
584+
}),
585+
http.get('*/v4beta/netloadbalancers/:id/listeners', () => {
586+
return HttpResponse.json(
587+
makeResourcePage(networkLoadBalancerListenerFactory.buildList(30))
588+
);
589+
}),
590+
http.get('*/v4beta/netloadbalancers/:id/listeners/:listenerId', () => {
591+
return HttpResponse.json(networkLoadBalancerListenerFactory.build());
592+
}),
593+
http.get('*/v4beta/netloadbalancers/:id/listeners/:listenerId/nodes', () => {
594+
return HttpResponse.json(
595+
makeResourcePage(networkLoadBalancerNodeFactory.buildList(30))
596+
);
597+
}),
598+
];
599+
539600
const nanodeType = linodeTypeFactory.build({ id: 'g6-nanode-1' });
540601
const standardTypes = linodeTypeFactory.buildList(7);
541602
const dedicatedTypes = dedicatedTypeFactory.buildList(7);
@@ -3999,6 +4060,7 @@ export const handlers = [
39994060
...databases,
40004061
...vpc,
40014062
...entities,
4063+
...netLoadBalancers,
40024064
http.get('*/v4beta/maintenance/policies', () => {
40034065
return HttpResponse.json(
40044066
makeResourcePage(maintenancePolicyFactory.buildList(2))

0 commit comments

Comments
 (0)