From ed7f53ec4e81c4d02e982b00bae147cb4b503e15 Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Mon, 9 Dec 2024 09:35:57 -0800 Subject: [PATCH] Use util for getting latest version in test specs --- .../manager/cypress/support/constants/lke.ts | 8 ++++++-- packages/manager/cypress/support/util/lke.ts | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 packages/manager/cypress/support/util/lke.ts diff --git a/packages/manager/cypress/support/constants/lke.ts b/packages/manager/cypress/support/constants/lke.ts index 7696794071f..721985f92d1 100644 --- a/packages/manager/cypress/support/constants/lke.ts +++ b/packages/manager/cypress/support/constants/lke.ts @@ -1,3 +1,5 @@ +import { getLatestKubernetesVersion } from 'support/util/lke'; + import type { KubernetesTieredVersion } from '@linode/api-v4'; import type { LkePlanDescription } from 'support/api/lke'; @@ -23,7 +25,9 @@ export const enterpriseKubernetesVersions = ['v1.31.1+lke1']; /** * The latest Kubernetes version available for cluster creation via Cloud Manager. */ -export const latestKubernetesVersion = kubernetesVersions[0]; +export const latestKubernetesVersion = getLatestKubernetesVersion( + kubernetesVersions +); /** * The latest standard tier Kubernetes version available for cluster creation via Cloud Manager. @@ -37,6 +41,6 @@ export const latestStandardTierKubernetesVersion: KubernetesTieredVersion = { * The latest enterprise tier Kubernetes version available for cluster creation via Cloud Manager. */ export const latestEnterpriseTierKubernetesVersion: KubernetesTieredVersion = { - id: enterpriseKubernetesVersions[0], + id: getLatestKubernetesVersion(enterpriseKubernetesVersions), tier: 'enterprise', }; diff --git a/packages/manager/cypress/support/util/lke.ts b/packages/manager/cypress/support/util/lke.ts new file mode 100644 index 00000000000..e1e65848532 --- /dev/null +++ b/packages/manager/cypress/support/util/lke.ts @@ -0,0 +1,18 @@ +import { sortByVersion } from 'src/utilities/sort-by'; + +/** + * Returns the string of the highest semantic version. + */ +export const getLatestKubernetesVersion = (versions: string[]) => { + const sortedVersions = versions.sort((a, b) => { + return sortByVersion(a, b, 'asc'); + }); + + const latestVersion = sortedVersions.pop(); + + if (!latestVersion) { + // Return an empty string if sorting does not yield latest version + return ''; + } + return latestVersion; +};